18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * rt5651.c -- RT5651 ALSA SoC audio codec driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2014 Realtek Semiconductor Corp. 68c2ecf20Sopenharmony_ci * Author: Bard Liao <bardliao@realtek.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/module.h> 108c2ecf20Sopenharmony_ci#include <linux/init.h> 118c2ecf20Sopenharmony_ci#include <linux/delay.h> 128c2ecf20Sopenharmony_ci#include <linux/pm.h> 138c2ecf20Sopenharmony_ci#include <linux/gpio/consumer.h> 148c2ecf20Sopenharmony_ci#include <linux/i2c.h> 158c2ecf20Sopenharmony_ci#include <linux/regmap.h> 168c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 178c2ecf20Sopenharmony_ci#include <linux/spi/spi.h> 188c2ecf20Sopenharmony_ci#include <linux/acpi.h> 198c2ecf20Sopenharmony_ci#include <sound/core.h> 208c2ecf20Sopenharmony_ci#include <sound/pcm.h> 218c2ecf20Sopenharmony_ci#include <sound/pcm_params.h> 228c2ecf20Sopenharmony_ci#include <sound/soc.h> 238c2ecf20Sopenharmony_ci#include <sound/soc-dapm.h> 248c2ecf20Sopenharmony_ci#include <sound/initval.h> 258c2ecf20Sopenharmony_ci#include <sound/tlv.h> 268c2ecf20Sopenharmony_ci#include <sound/jack.h> 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#include "rl6231.h" 298c2ecf20Sopenharmony_ci#include "rt5651.h" 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#define RT5651_DEVICE_ID_VALUE 0x6281 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define RT5651_PR_RANGE_BASE (0xff + 1) 348c2ecf20Sopenharmony_ci#define RT5651_PR_SPACING 0x100 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define RT5651_PR_BASE (RT5651_PR_RANGE_BASE + (0 * RT5651_PR_SPACING)) 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cistatic const struct regmap_range_cfg rt5651_ranges[] = { 398c2ecf20Sopenharmony_ci { .name = "PR", .range_min = RT5651_PR_BASE, 408c2ecf20Sopenharmony_ci .range_max = RT5651_PR_BASE + 0xb4, 418c2ecf20Sopenharmony_ci .selector_reg = RT5651_PRIV_INDEX, 428c2ecf20Sopenharmony_ci .selector_mask = 0xff, 438c2ecf20Sopenharmony_ci .selector_shift = 0x0, 448c2ecf20Sopenharmony_ci .window_start = RT5651_PRIV_DATA, 458c2ecf20Sopenharmony_ci .window_len = 0x1, }, 468c2ecf20Sopenharmony_ci}; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_cistatic const struct reg_sequence init_list[] = { 498c2ecf20Sopenharmony_ci {RT5651_PR_BASE + 0x3d, 0x3e00}, 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic const struct reg_default rt5651_reg[] = { 538c2ecf20Sopenharmony_ci { 0x00, 0x0000 }, 548c2ecf20Sopenharmony_ci { 0x02, 0xc8c8 }, 558c2ecf20Sopenharmony_ci { 0x03, 0xc8c8 }, 568c2ecf20Sopenharmony_ci { 0x05, 0x0000 }, 578c2ecf20Sopenharmony_ci { 0x0d, 0x0000 }, 588c2ecf20Sopenharmony_ci { 0x0e, 0x0000 }, 598c2ecf20Sopenharmony_ci { 0x0f, 0x0808 }, 608c2ecf20Sopenharmony_ci { 0x10, 0x0808 }, 618c2ecf20Sopenharmony_ci { 0x19, 0xafaf }, 628c2ecf20Sopenharmony_ci { 0x1a, 0xafaf }, 638c2ecf20Sopenharmony_ci { 0x1b, 0x0c00 }, 648c2ecf20Sopenharmony_ci { 0x1c, 0x2f2f }, 658c2ecf20Sopenharmony_ci { 0x1d, 0x2f2f }, 668c2ecf20Sopenharmony_ci { 0x1e, 0x0000 }, 678c2ecf20Sopenharmony_ci { 0x27, 0x7860 }, 688c2ecf20Sopenharmony_ci { 0x28, 0x7070 }, 698c2ecf20Sopenharmony_ci { 0x29, 0x8080 }, 708c2ecf20Sopenharmony_ci { 0x2a, 0x5252 }, 718c2ecf20Sopenharmony_ci { 0x2b, 0x5454 }, 728c2ecf20Sopenharmony_ci { 0x2f, 0x0000 }, 738c2ecf20Sopenharmony_ci { 0x30, 0x5000 }, 748c2ecf20Sopenharmony_ci { 0x3b, 0x0000 }, 758c2ecf20Sopenharmony_ci { 0x3c, 0x006f }, 768c2ecf20Sopenharmony_ci { 0x3d, 0x0000 }, 778c2ecf20Sopenharmony_ci { 0x3e, 0x006f }, 788c2ecf20Sopenharmony_ci { 0x45, 0x6000 }, 798c2ecf20Sopenharmony_ci { 0x4d, 0x0000 }, 808c2ecf20Sopenharmony_ci { 0x4e, 0x0000 }, 818c2ecf20Sopenharmony_ci { 0x4f, 0x0279 }, 828c2ecf20Sopenharmony_ci { 0x50, 0x0000 }, 838c2ecf20Sopenharmony_ci { 0x51, 0x0000 }, 848c2ecf20Sopenharmony_ci { 0x52, 0x0279 }, 858c2ecf20Sopenharmony_ci { 0x53, 0xf000 }, 868c2ecf20Sopenharmony_ci { 0x61, 0x0000 }, 878c2ecf20Sopenharmony_ci { 0x62, 0x0000 }, 888c2ecf20Sopenharmony_ci { 0x63, 0x00c0 }, 898c2ecf20Sopenharmony_ci { 0x64, 0x0000 }, 908c2ecf20Sopenharmony_ci { 0x65, 0x0000 }, 918c2ecf20Sopenharmony_ci { 0x66, 0x0000 }, 928c2ecf20Sopenharmony_ci { 0x70, 0x8000 }, 938c2ecf20Sopenharmony_ci { 0x71, 0x8000 }, 948c2ecf20Sopenharmony_ci { 0x73, 0x1104 }, 958c2ecf20Sopenharmony_ci { 0x74, 0x0c00 }, 968c2ecf20Sopenharmony_ci { 0x75, 0x1400 }, 978c2ecf20Sopenharmony_ci { 0x77, 0x0c00 }, 988c2ecf20Sopenharmony_ci { 0x78, 0x4000 }, 998c2ecf20Sopenharmony_ci { 0x79, 0x0123 }, 1008c2ecf20Sopenharmony_ci { 0x80, 0x0000 }, 1018c2ecf20Sopenharmony_ci { 0x81, 0x0000 }, 1028c2ecf20Sopenharmony_ci { 0x82, 0x0000 }, 1038c2ecf20Sopenharmony_ci { 0x83, 0x0800 }, 1048c2ecf20Sopenharmony_ci { 0x84, 0x0000 }, 1058c2ecf20Sopenharmony_ci { 0x85, 0x0008 }, 1068c2ecf20Sopenharmony_ci { 0x89, 0x0000 }, 1078c2ecf20Sopenharmony_ci { 0x8e, 0x0004 }, 1088c2ecf20Sopenharmony_ci { 0x8f, 0x1100 }, 1098c2ecf20Sopenharmony_ci { 0x90, 0x0000 }, 1108c2ecf20Sopenharmony_ci { 0x93, 0x2000 }, 1118c2ecf20Sopenharmony_ci { 0x94, 0x0200 }, 1128c2ecf20Sopenharmony_ci { 0xb0, 0x2080 }, 1138c2ecf20Sopenharmony_ci { 0xb1, 0x0000 }, 1148c2ecf20Sopenharmony_ci { 0xb4, 0x2206 }, 1158c2ecf20Sopenharmony_ci { 0xb5, 0x1f00 }, 1168c2ecf20Sopenharmony_ci { 0xb6, 0x0000 }, 1178c2ecf20Sopenharmony_ci { 0xbb, 0x0000 }, 1188c2ecf20Sopenharmony_ci { 0xbc, 0x0000 }, 1198c2ecf20Sopenharmony_ci { 0xbd, 0x0000 }, 1208c2ecf20Sopenharmony_ci { 0xbe, 0x0000 }, 1218c2ecf20Sopenharmony_ci { 0xbf, 0x0000 }, 1228c2ecf20Sopenharmony_ci { 0xc0, 0x0400 }, 1238c2ecf20Sopenharmony_ci { 0xc1, 0x0000 }, 1248c2ecf20Sopenharmony_ci { 0xc2, 0x0000 }, 1258c2ecf20Sopenharmony_ci { 0xcf, 0x0013 }, 1268c2ecf20Sopenharmony_ci { 0xd0, 0x0680 }, 1278c2ecf20Sopenharmony_ci { 0xd1, 0x1c17 }, 1288c2ecf20Sopenharmony_ci { 0xd3, 0xb320 }, 1298c2ecf20Sopenharmony_ci { 0xd9, 0x0809 }, 1308c2ecf20Sopenharmony_ci { 0xfa, 0x0010 }, 1318c2ecf20Sopenharmony_ci { 0xfe, 0x10ec }, 1328c2ecf20Sopenharmony_ci { 0xff, 0x6281 }, 1338c2ecf20Sopenharmony_ci}; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_cistatic bool rt5651_volatile_register(struct device *dev, unsigned int reg) 1368c2ecf20Sopenharmony_ci{ 1378c2ecf20Sopenharmony_ci int i; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(rt5651_ranges); i++) { 1408c2ecf20Sopenharmony_ci if ((reg >= rt5651_ranges[i].window_start && 1418c2ecf20Sopenharmony_ci reg <= rt5651_ranges[i].window_start + 1428c2ecf20Sopenharmony_ci rt5651_ranges[i].window_len) || 1438c2ecf20Sopenharmony_ci (reg >= rt5651_ranges[i].range_min && 1448c2ecf20Sopenharmony_ci reg <= rt5651_ranges[i].range_max)) { 1458c2ecf20Sopenharmony_ci return true; 1468c2ecf20Sopenharmony_ci } 1478c2ecf20Sopenharmony_ci } 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci switch (reg) { 1508c2ecf20Sopenharmony_ci case RT5651_RESET: 1518c2ecf20Sopenharmony_ci case RT5651_PRIV_DATA: 1528c2ecf20Sopenharmony_ci case RT5651_EQ_CTRL1: 1538c2ecf20Sopenharmony_ci case RT5651_ALC_1: 1548c2ecf20Sopenharmony_ci case RT5651_IRQ_CTRL2: 1558c2ecf20Sopenharmony_ci case RT5651_INT_IRQ_ST: 1568c2ecf20Sopenharmony_ci case RT5651_PGM_REG_ARR1: 1578c2ecf20Sopenharmony_ci case RT5651_PGM_REG_ARR3: 1588c2ecf20Sopenharmony_ci case RT5651_VENDOR_ID: 1598c2ecf20Sopenharmony_ci case RT5651_DEVICE_ID: 1608c2ecf20Sopenharmony_ci return true; 1618c2ecf20Sopenharmony_ci default: 1628c2ecf20Sopenharmony_ci return false; 1638c2ecf20Sopenharmony_ci } 1648c2ecf20Sopenharmony_ci} 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_cistatic bool rt5651_readable_register(struct device *dev, unsigned int reg) 1678c2ecf20Sopenharmony_ci{ 1688c2ecf20Sopenharmony_ci int i; 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(rt5651_ranges); i++) { 1718c2ecf20Sopenharmony_ci if ((reg >= rt5651_ranges[i].window_start && 1728c2ecf20Sopenharmony_ci reg <= rt5651_ranges[i].window_start + 1738c2ecf20Sopenharmony_ci rt5651_ranges[i].window_len) || 1748c2ecf20Sopenharmony_ci (reg >= rt5651_ranges[i].range_min && 1758c2ecf20Sopenharmony_ci reg <= rt5651_ranges[i].range_max)) { 1768c2ecf20Sopenharmony_ci return true; 1778c2ecf20Sopenharmony_ci } 1788c2ecf20Sopenharmony_ci } 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci switch (reg) { 1818c2ecf20Sopenharmony_ci case RT5651_RESET: 1828c2ecf20Sopenharmony_ci case RT5651_VERSION_ID: 1838c2ecf20Sopenharmony_ci case RT5651_VENDOR_ID: 1848c2ecf20Sopenharmony_ci case RT5651_DEVICE_ID: 1858c2ecf20Sopenharmony_ci case RT5651_HP_VOL: 1868c2ecf20Sopenharmony_ci case RT5651_LOUT_CTRL1: 1878c2ecf20Sopenharmony_ci case RT5651_LOUT_CTRL2: 1888c2ecf20Sopenharmony_ci case RT5651_IN1_IN2: 1898c2ecf20Sopenharmony_ci case RT5651_IN3: 1908c2ecf20Sopenharmony_ci case RT5651_INL1_INR1_VOL: 1918c2ecf20Sopenharmony_ci case RT5651_INL2_INR2_VOL: 1928c2ecf20Sopenharmony_ci case RT5651_DAC1_DIG_VOL: 1938c2ecf20Sopenharmony_ci case RT5651_DAC2_DIG_VOL: 1948c2ecf20Sopenharmony_ci case RT5651_DAC2_CTRL: 1958c2ecf20Sopenharmony_ci case RT5651_ADC_DIG_VOL: 1968c2ecf20Sopenharmony_ci case RT5651_ADC_DATA: 1978c2ecf20Sopenharmony_ci case RT5651_ADC_BST_VOL: 1988c2ecf20Sopenharmony_ci case RT5651_STO1_ADC_MIXER: 1998c2ecf20Sopenharmony_ci case RT5651_STO2_ADC_MIXER: 2008c2ecf20Sopenharmony_ci case RT5651_AD_DA_MIXER: 2018c2ecf20Sopenharmony_ci case RT5651_STO_DAC_MIXER: 2028c2ecf20Sopenharmony_ci case RT5651_DD_MIXER: 2038c2ecf20Sopenharmony_ci case RT5651_DIG_INF_DATA: 2048c2ecf20Sopenharmony_ci case RT5651_PDM_CTL: 2058c2ecf20Sopenharmony_ci case RT5651_REC_L1_MIXER: 2068c2ecf20Sopenharmony_ci case RT5651_REC_L2_MIXER: 2078c2ecf20Sopenharmony_ci case RT5651_REC_R1_MIXER: 2088c2ecf20Sopenharmony_ci case RT5651_REC_R2_MIXER: 2098c2ecf20Sopenharmony_ci case RT5651_HPO_MIXER: 2108c2ecf20Sopenharmony_ci case RT5651_OUT_L1_MIXER: 2118c2ecf20Sopenharmony_ci case RT5651_OUT_L2_MIXER: 2128c2ecf20Sopenharmony_ci case RT5651_OUT_L3_MIXER: 2138c2ecf20Sopenharmony_ci case RT5651_OUT_R1_MIXER: 2148c2ecf20Sopenharmony_ci case RT5651_OUT_R2_MIXER: 2158c2ecf20Sopenharmony_ci case RT5651_OUT_R3_MIXER: 2168c2ecf20Sopenharmony_ci case RT5651_LOUT_MIXER: 2178c2ecf20Sopenharmony_ci case RT5651_PWR_DIG1: 2188c2ecf20Sopenharmony_ci case RT5651_PWR_DIG2: 2198c2ecf20Sopenharmony_ci case RT5651_PWR_ANLG1: 2208c2ecf20Sopenharmony_ci case RT5651_PWR_ANLG2: 2218c2ecf20Sopenharmony_ci case RT5651_PWR_MIXER: 2228c2ecf20Sopenharmony_ci case RT5651_PWR_VOL: 2238c2ecf20Sopenharmony_ci case RT5651_PRIV_INDEX: 2248c2ecf20Sopenharmony_ci case RT5651_PRIV_DATA: 2258c2ecf20Sopenharmony_ci case RT5651_I2S1_SDP: 2268c2ecf20Sopenharmony_ci case RT5651_I2S2_SDP: 2278c2ecf20Sopenharmony_ci case RT5651_ADDA_CLK1: 2288c2ecf20Sopenharmony_ci case RT5651_ADDA_CLK2: 2298c2ecf20Sopenharmony_ci case RT5651_DMIC: 2308c2ecf20Sopenharmony_ci case RT5651_TDM_CTL_1: 2318c2ecf20Sopenharmony_ci case RT5651_TDM_CTL_2: 2328c2ecf20Sopenharmony_ci case RT5651_TDM_CTL_3: 2338c2ecf20Sopenharmony_ci case RT5651_GLB_CLK: 2348c2ecf20Sopenharmony_ci case RT5651_PLL_CTRL1: 2358c2ecf20Sopenharmony_ci case RT5651_PLL_CTRL2: 2368c2ecf20Sopenharmony_ci case RT5651_PLL_MODE_1: 2378c2ecf20Sopenharmony_ci case RT5651_PLL_MODE_2: 2388c2ecf20Sopenharmony_ci case RT5651_PLL_MODE_3: 2398c2ecf20Sopenharmony_ci case RT5651_PLL_MODE_4: 2408c2ecf20Sopenharmony_ci case RT5651_PLL_MODE_5: 2418c2ecf20Sopenharmony_ci case RT5651_PLL_MODE_6: 2428c2ecf20Sopenharmony_ci case RT5651_PLL_MODE_7: 2438c2ecf20Sopenharmony_ci case RT5651_DEPOP_M1: 2448c2ecf20Sopenharmony_ci case RT5651_DEPOP_M2: 2458c2ecf20Sopenharmony_ci case RT5651_DEPOP_M3: 2468c2ecf20Sopenharmony_ci case RT5651_CHARGE_PUMP: 2478c2ecf20Sopenharmony_ci case RT5651_MICBIAS: 2488c2ecf20Sopenharmony_ci case RT5651_A_JD_CTL1: 2498c2ecf20Sopenharmony_ci case RT5651_EQ_CTRL1: 2508c2ecf20Sopenharmony_ci case RT5651_EQ_CTRL2: 2518c2ecf20Sopenharmony_ci case RT5651_ALC_1: 2528c2ecf20Sopenharmony_ci case RT5651_ALC_2: 2538c2ecf20Sopenharmony_ci case RT5651_ALC_3: 2548c2ecf20Sopenharmony_ci case RT5651_JD_CTRL1: 2558c2ecf20Sopenharmony_ci case RT5651_JD_CTRL2: 2568c2ecf20Sopenharmony_ci case RT5651_IRQ_CTRL1: 2578c2ecf20Sopenharmony_ci case RT5651_IRQ_CTRL2: 2588c2ecf20Sopenharmony_ci case RT5651_INT_IRQ_ST: 2598c2ecf20Sopenharmony_ci case RT5651_GPIO_CTRL1: 2608c2ecf20Sopenharmony_ci case RT5651_GPIO_CTRL2: 2618c2ecf20Sopenharmony_ci case RT5651_GPIO_CTRL3: 2628c2ecf20Sopenharmony_ci case RT5651_PGM_REG_ARR1: 2638c2ecf20Sopenharmony_ci case RT5651_PGM_REG_ARR2: 2648c2ecf20Sopenharmony_ci case RT5651_PGM_REG_ARR3: 2658c2ecf20Sopenharmony_ci case RT5651_PGM_REG_ARR4: 2668c2ecf20Sopenharmony_ci case RT5651_PGM_REG_ARR5: 2678c2ecf20Sopenharmony_ci case RT5651_SCB_FUNC: 2688c2ecf20Sopenharmony_ci case RT5651_SCB_CTRL: 2698c2ecf20Sopenharmony_ci case RT5651_BASE_BACK: 2708c2ecf20Sopenharmony_ci case RT5651_MP3_PLUS1: 2718c2ecf20Sopenharmony_ci case RT5651_MP3_PLUS2: 2728c2ecf20Sopenharmony_ci case RT5651_ADJ_HPF_CTRL1: 2738c2ecf20Sopenharmony_ci case RT5651_ADJ_HPF_CTRL2: 2748c2ecf20Sopenharmony_ci case RT5651_HP_CALIB_AMP_DET: 2758c2ecf20Sopenharmony_ci case RT5651_HP_CALIB2: 2768c2ecf20Sopenharmony_ci case RT5651_SV_ZCD1: 2778c2ecf20Sopenharmony_ci case RT5651_SV_ZCD2: 2788c2ecf20Sopenharmony_ci case RT5651_D_MISC: 2798c2ecf20Sopenharmony_ci case RT5651_DUMMY2: 2808c2ecf20Sopenharmony_ci case RT5651_DUMMY3: 2818c2ecf20Sopenharmony_ci return true; 2828c2ecf20Sopenharmony_ci default: 2838c2ecf20Sopenharmony_ci return false; 2848c2ecf20Sopenharmony_ci } 2858c2ecf20Sopenharmony_ci} 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0); 2888c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_MINMAX(dac_vol_tlv, -6562, 0); 2898c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0); 2908c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_MINMAX(adc_vol_tlv, -1762, 3000); 2918c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(adc_bst_tlv, 0, 1200, 0); 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ci/* {0, +20, +24, +30, +35, +40, +44, +50, +52} dB */ 2948c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_RANGE(bst_tlv, 2958c2ecf20Sopenharmony_ci 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0), 2968c2ecf20Sopenharmony_ci 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0), 2978c2ecf20Sopenharmony_ci 2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0), 2988c2ecf20Sopenharmony_ci 3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0), 2998c2ecf20Sopenharmony_ci 6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0), 3008c2ecf20Sopenharmony_ci 7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0), 3018c2ecf20Sopenharmony_ci 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0) 3028c2ecf20Sopenharmony_ci); 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci/* Interface data select */ 3058c2ecf20Sopenharmony_cistatic const char * const rt5651_data_select[] = { 3068c2ecf20Sopenharmony_ci "Normal", "Swap", "left copy to right", "right copy to left"}; 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5651_if2_dac_enum, RT5651_DIG_INF_DATA, 3098c2ecf20Sopenharmony_ci RT5651_IF2_DAC_SEL_SFT, rt5651_data_select); 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5651_if2_adc_enum, RT5651_DIG_INF_DATA, 3128c2ecf20Sopenharmony_ci RT5651_IF2_ADC_SEL_SFT, rt5651_data_select); 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_snd_controls[] = { 3158c2ecf20Sopenharmony_ci /* Headphone Output Volume */ 3168c2ecf20Sopenharmony_ci SOC_DOUBLE_TLV("HP Playback Volume", RT5651_HP_VOL, 3178c2ecf20Sopenharmony_ci RT5651_L_VOL_SFT, RT5651_R_VOL_SFT, 39, 1, out_vol_tlv), 3188c2ecf20Sopenharmony_ci /* OUTPUT Control */ 3198c2ecf20Sopenharmony_ci SOC_DOUBLE_TLV("OUT Playback Volume", RT5651_LOUT_CTRL1, 3208c2ecf20Sopenharmony_ci RT5651_L_VOL_SFT, RT5651_R_VOL_SFT, 39, 1, out_vol_tlv), 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci /* DAC Digital Volume */ 3238c2ecf20Sopenharmony_ci SOC_DOUBLE("DAC2 Playback Switch", RT5651_DAC2_CTRL, 3248c2ecf20Sopenharmony_ci RT5651_M_DAC_L2_VOL_SFT, RT5651_M_DAC_R2_VOL_SFT, 1, 1), 3258c2ecf20Sopenharmony_ci SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5651_DAC1_DIG_VOL, 3268c2ecf20Sopenharmony_ci RT5651_L_VOL_SFT, RT5651_R_VOL_SFT, 3278c2ecf20Sopenharmony_ci 175, 0, dac_vol_tlv), 3288c2ecf20Sopenharmony_ci SOC_DOUBLE_TLV("Mono DAC Playback Volume", RT5651_DAC2_DIG_VOL, 3298c2ecf20Sopenharmony_ci RT5651_L_VOL_SFT, RT5651_R_VOL_SFT, 3308c2ecf20Sopenharmony_ci 175, 0, dac_vol_tlv), 3318c2ecf20Sopenharmony_ci /* IN1/IN2/IN3 Control */ 3328c2ecf20Sopenharmony_ci SOC_SINGLE_TLV("IN1 Boost", RT5651_IN1_IN2, 3338c2ecf20Sopenharmony_ci RT5651_BST_SFT1, 8, 0, bst_tlv), 3348c2ecf20Sopenharmony_ci SOC_SINGLE_TLV("IN2 Boost", RT5651_IN1_IN2, 3358c2ecf20Sopenharmony_ci RT5651_BST_SFT2, 8, 0, bst_tlv), 3368c2ecf20Sopenharmony_ci SOC_SINGLE_TLV("IN3 Boost", RT5651_IN3, 3378c2ecf20Sopenharmony_ci RT5651_BST_SFT1, 8, 0, bst_tlv), 3388c2ecf20Sopenharmony_ci /* INL/INR Volume Control */ 3398c2ecf20Sopenharmony_ci SOC_DOUBLE_TLV("IN Capture Volume", RT5651_INL1_INR1_VOL, 3408c2ecf20Sopenharmony_ci RT5651_INL_VOL_SFT, RT5651_INR_VOL_SFT, 3418c2ecf20Sopenharmony_ci 31, 1, in_vol_tlv), 3428c2ecf20Sopenharmony_ci /* ADC Digital Volume Control */ 3438c2ecf20Sopenharmony_ci SOC_DOUBLE("ADC Capture Switch", RT5651_ADC_DIG_VOL, 3448c2ecf20Sopenharmony_ci RT5651_L_MUTE_SFT, RT5651_R_MUTE_SFT, 1, 1), 3458c2ecf20Sopenharmony_ci SOC_DOUBLE_TLV("ADC Capture Volume", RT5651_ADC_DIG_VOL, 3468c2ecf20Sopenharmony_ci RT5651_L_VOL_SFT, RT5651_R_VOL_SFT, 3478c2ecf20Sopenharmony_ci 127, 0, adc_vol_tlv), 3488c2ecf20Sopenharmony_ci SOC_DOUBLE_TLV("Mono ADC Capture Volume", RT5651_ADC_DATA, 3498c2ecf20Sopenharmony_ci RT5651_L_VOL_SFT, RT5651_R_VOL_SFT, 3508c2ecf20Sopenharmony_ci 127, 0, adc_vol_tlv), 3518c2ecf20Sopenharmony_ci /* ADC Boost Volume Control */ 3528c2ecf20Sopenharmony_ci SOC_DOUBLE_TLV("ADC Boost Gain", RT5651_ADC_BST_VOL, 3538c2ecf20Sopenharmony_ci RT5651_ADC_L_BST_SFT, RT5651_ADC_R_BST_SFT, 3548c2ecf20Sopenharmony_ci 3, 0, adc_bst_tlv), 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci /* ASRC */ 3578c2ecf20Sopenharmony_ci SOC_SINGLE("IF1 ASRC Switch", RT5651_PLL_MODE_1, 3588c2ecf20Sopenharmony_ci RT5651_STO1_T_SFT, 1, 0), 3598c2ecf20Sopenharmony_ci SOC_SINGLE("IF2 ASRC Switch", RT5651_PLL_MODE_1, 3608c2ecf20Sopenharmony_ci RT5651_STO2_T_SFT, 1, 0), 3618c2ecf20Sopenharmony_ci SOC_SINGLE("DMIC ASRC Switch", RT5651_PLL_MODE_1, 3628c2ecf20Sopenharmony_ci RT5651_DMIC_1_M_SFT, 1, 0), 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci SOC_ENUM("ADC IF2 Data Switch", rt5651_if2_adc_enum), 3658c2ecf20Sopenharmony_ci SOC_ENUM("DAC IF2 Data Switch", rt5651_if2_dac_enum), 3668c2ecf20Sopenharmony_ci}; 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci/** 3698c2ecf20Sopenharmony_ci * set_dmic_clk - Set parameter of dmic. 3708c2ecf20Sopenharmony_ci * 3718c2ecf20Sopenharmony_ci * @w: DAPM widget. 3728c2ecf20Sopenharmony_ci * @kcontrol: The kcontrol of this widget. 3738c2ecf20Sopenharmony_ci * @event: Event id. 3748c2ecf20Sopenharmony_ci * 3758c2ecf20Sopenharmony_ci */ 3768c2ecf20Sopenharmony_cistatic int set_dmic_clk(struct snd_soc_dapm_widget *w, 3778c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 3788c2ecf20Sopenharmony_ci{ 3798c2ecf20Sopenharmony_ci struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 3808c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 3818c2ecf20Sopenharmony_ci int idx, rate; 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci rate = rt5651->sysclk / rl6231_get_pre_div(rt5651->regmap, 3848c2ecf20Sopenharmony_ci RT5651_ADDA_CLK1, RT5651_I2S_PD1_SFT); 3858c2ecf20Sopenharmony_ci idx = rl6231_calc_dmic_clk(rate); 3868c2ecf20Sopenharmony_ci if (idx < 0) 3878c2ecf20Sopenharmony_ci dev_err(component->dev, "Failed to set DMIC clock\n"); 3888c2ecf20Sopenharmony_ci else 3898c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_DMIC, RT5651_DMIC_CLK_MASK, 3908c2ecf20Sopenharmony_ci idx << RT5651_DMIC_CLK_SFT); 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci return idx; 3938c2ecf20Sopenharmony_ci} 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci/* Digital Mixer */ 3968c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_sto1_adc_l_mix[] = { 3978c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("ADC1 Switch", RT5651_STO1_ADC_MIXER, 3988c2ecf20Sopenharmony_ci RT5651_M_STO1_ADC_L1_SFT, 1, 1), 3998c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("ADC2 Switch", RT5651_STO1_ADC_MIXER, 4008c2ecf20Sopenharmony_ci RT5651_M_STO1_ADC_L2_SFT, 1, 1), 4018c2ecf20Sopenharmony_ci}; 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_sto1_adc_r_mix[] = { 4048c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("ADC1 Switch", RT5651_STO1_ADC_MIXER, 4058c2ecf20Sopenharmony_ci RT5651_M_STO1_ADC_R1_SFT, 1, 1), 4068c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("ADC2 Switch", RT5651_STO1_ADC_MIXER, 4078c2ecf20Sopenharmony_ci RT5651_M_STO1_ADC_R2_SFT, 1, 1), 4088c2ecf20Sopenharmony_ci}; 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_sto2_adc_l_mix[] = { 4118c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("ADC1 Switch", RT5651_STO2_ADC_MIXER, 4128c2ecf20Sopenharmony_ci RT5651_M_STO2_ADC_L1_SFT, 1, 1), 4138c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("ADC2 Switch", RT5651_STO2_ADC_MIXER, 4148c2ecf20Sopenharmony_ci RT5651_M_STO2_ADC_L2_SFT, 1, 1), 4158c2ecf20Sopenharmony_ci}; 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_sto2_adc_r_mix[] = { 4188c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("ADC1 Switch", RT5651_STO2_ADC_MIXER, 4198c2ecf20Sopenharmony_ci RT5651_M_STO2_ADC_R1_SFT, 1, 1), 4208c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("ADC2 Switch", RT5651_STO2_ADC_MIXER, 4218c2ecf20Sopenharmony_ci RT5651_M_STO2_ADC_R2_SFT, 1, 1), 4228c2ecf20Sopenharmony_ci}; 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_dac_l_mix[] = { 4258c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("Stereo ADC Switch", RT5651_AD_DA_MIXER, 4268c2ecf20Sopenharmony_ci RT5651_M_ADCMIX_L_SFT, 1, 1), 4278c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("INF1 Switch", RT5651_AD_DA_MIXER, 4288c2ecf20Sopenharmony_ci RT5651_M_IF1_DAC_L_SFT, 1, 1), 4298c2ecf20Sopenharmony_ci}; 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_dac_r_mix[] = { 4328c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("Stereo ADC Switch", RT5651_AD_DA_MIXER, 4338c2ecf20Sopenharmony_ci RT5651_M_ADCMIX_R_SFT, 1, 1), 4348c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("INF1 Switch", RT5651_AD_DA_MIXER, 4358c2ecf20Sopenharmony_ci RT5651_M_IF1_DAC_R_SFT, 1, 1), 4368c2ecf20Sopenharmony_ci}; 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_sto_dac_l_mix[] = { 4398c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC L1 Switch", RT5651_STO_DAC_MIXER, 4408c2ecf20Sopenharmony_ci RT5651_M_DAC_L1_MIXL_SFT, 1, 1), 4418c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC L2 Switch", RT5651_STO_DAC_MIXER, 4428c2ecf20Sopenharmony_ci RT5651_M_DAC_L2_MIXL_SFT, 1, 1), 4438c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC R1 Switch", RT5651_STO_DAC_MIXER, 4448c2ecf20Sopenharmony_ci RT5651_M_DAC_R1_MIXL_SFT, 1, 1), 4458c2ecf20Sopenharmony_ci}; 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_sto_dac_r_mix[] = { 4488c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC R1 Switch", RT5651_STO_DAC_MIXER, 4498c2ecf20Sopenharmony_ci RT5651_M_DAC_R1_MIXR_SFT, 1, 1), 4508c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC R2 Switch", RT5651_STO_DAC_MIXER, 4518c2ecf20Sopenharmony_ci RT5651_M_DAC_R2_MIXR_SFT, 1, 1), 4528c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC L1 Switch", RT5651_STO_DAC_MIXER, 4538c2ecf20Sopenharmony_ci RT5651_M_DAC_L1_MIXR_SFT, 1, 1), 4548c2ecf20Sopenharmony_ci}; 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_dd_dac_l_mix[] = { 4578c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC L1 Switch", RT5651_DD_MIXER, 4588c2ecf20Sopenharmony_ci RT5651_M_STO_DD_L1_SFT, 1, 1), 4598c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC L2 Switch", RT5651_DD_MIXER, 4608c2ecf20Sopenharmony_ci RT5651_M_STO_DD_L2_SFT, 1, 1), 4618c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC R2 Switch", RT5651_DD_MIXER, 4628c2ecf20Sopenharmony_ci RT5651_M_STO_DD_R2_L_SFT, 1, 1), 4638c2ecf20Sopenharmony_ci}; 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_dd_dac_r_mix[] = { 4668c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC R1 Switch", RT5651_DD_MIXER, 4678c2ecf20Sopenharmony_ci RT5651_M_STO_DD_R1_SFT, 1, 1), 4688c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC R2 Switch", RT5651_DD_MIXER, 4698c2ecf20Sopenharmony_ci RT5651_M_STO_DD_R2_SFT, 1, 1), 4708c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC L2 Switch", RT5651_DD_MIXER, 4718c2ecf20Sopenharmony_ci RT5651_M_STO_DD_L2_R_SFT, 1, 1), 4728c2ecf20Sopenharmony_ci}; 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci/* Analog Input Mixer */ 4758c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_rec_l_mix[] = { 4768c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("INL1 Switch", RT5651_REC_L2_MIXER, 4778c2ecf20Sopenharmony_ci RT5651_M_IN1_L_RM_L_SFT, 1, 1), 4788c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST3 Switch", RT5651_REC_L2_MIXER, 4798c2ecf20Sopenharmony_ci RT5651_M_BST3_RM_L_SFT, 1, 1), 4808c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST2 Switch", RT5651_REC_L2_MIXER, 4818c2ecf20Sopenharmony_ci RT5651_M_BST2_RM_L_SFT, 1, 1), 4828c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST1 Switch", RT5651_REC_L2_MIXER, 4838c2ecf20Sopenharmony_ci RT5651_M_BST1_RM_L_SFT, 1, 1), 4848c2ecf20Sopenharmony_ci}; 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_rec_r_mix[] = { 4878c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("INR1 Switch", RT5651_REC_R2_MIXER, 4888c2ecf20Sopenharmony_ci RT5651_M_IN1_R_RM_R_SFT, 1, 1), 4898c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST3 Switch", RT5651_REC_R2_MIXER, 4908c2ecf20Sopenharmony_ci RT5651_M_BST3_RM_R_SFT, 1, 1), 4918c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST2 Switch", RT5651_REC_R2_MIXER, 4928c2ecf20Sopenharmony_ci RT5651_M_BST2_RM_R_SFT, 1, 1), 4938c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST1 Switch", RT5651_REC_R2_MIXER, 4948c2ecf20Sopenharmony_ci RT5651_M_BST1_RM_R_SFT, 1, 1), 4958c2ecf20Sopenharmony_ci}; 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci/* Analog Output Mixer */ 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_out_l_mix[] = { 5008c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST1 Switch", RT5651_OUT_L3_MIXER, 5018c2ecf20Sopenharmony_ci RT5651_M_BST1_OM_L_SFT, 1, 1), 5028c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST2 Switch", RT5651_OUT_L3_MIXER, 5038c2ecf20Sopenharmony_ci RT5651_M_BST2_OM_L_SFT, 1, 1), 5048c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("INL1 Switch", RT5651_OUT_L3_MIXER, 5058c2ecf20Sopenharmony_ci RT5651_M_IN1_L_OM_L_SFT, 1, 1), 5068c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("REC MIXL Switch", RT5651_OUT_L3_MIXER, 5078c2ecf20Sopenharmony_ci RT5651_M_RM_L_OM_L_SFT, 1, 1), 5088c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC L1 Switch", RT5651_OUT_L3_MIXER, 5098c2ecf20Sopenharmony_ci RT5651_M_DAC_L1_OM_L_SFT, 1, 1), 5108c2ecf20Sopenharmony_ci}; 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_out_r_mix[] = { 5138c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST2 Switch", RT5651_OUT_R3_MIXER, 5148c2ecf20Sopenharmony_ci RT5651_M_BST2_OM_R_SFT, 1, 1), 5158c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST1 Switch", RT5651_OUT_R3_MIXER, 5168c2ecf20Sopenharmony_ci RT5651_M_BST1_OM_R_SFT, 1, 1), 5178c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("INR1 Switch", RT5651_OUT_R3_MIXER, 5188c2ecf20Sopenharmony_ci RT5651_M_IN1_R_OM_R_SFT, 1, 1), 5198c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("REC MIXR Switch", RT5651_OUT_R3_MIXER, 5208c2ecf20Sopenharmony_ci RT5651_M_RM_R_OM_R_SFT, 1, 1), 5218c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC R1 Switch", RT5651_OUT_R3_MIXER, 5228c2ecf20Sopenharmony_ci RT5651_M_DAC_R1_OM_R_SFT, 1, 1), 5238c2ecf20Sopenharmony_ci}; 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_hpo_mix[] = { 5268c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("HPO MIX DAC1 Switch", RT5651_HPO_MIXER, 5278c2ecf20Sopenharmony_ci RT5651_M_DAC1_HM_SFT, 1, 1), 5288c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("HPO MIX HPVOL Switch", RT5651_HPO_MIXER, 5298c2ecf20Sopenharmony_ci RT5651_M_HPVOL_HM_SFT, 1, 1), 5308c2ecf20Sopenharmony_ci}; 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_lout_mix[] = { 5338c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC L1 Switch", RT5651_LOUT_MIXER, 5348c2ecf20Sopenharmony_ci RT5651_M_DAC_L1_LM_SFT, 1, 1), 5358c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC R1 Switch", RT5651_LOUT_MIXER, 5368c2ecf20Sopenharmony_ci RT5651_M_DAC_R1_LM_SFT, 1, 1), 5378c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("OUTVOL L Switch", RT5651_LOUT_MIXER, 5388c2ecf20Sopenharmony_ci RT5651_M_OV_L_LM_SFT, 1, 1), 5398c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("OUTVOL R Switch", RT5651_LOUT_MIXER, 5408c2ecf20Sopenharmony_ci RT5651_M_OV_R_LM_SFT, 1, 1), 5418c2ecf20Sopenharmony_ci}; 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new outvol_l_control = 5448c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("Switch", RT5651_LOUT_CTRL1, 5458c2ecf20Sopenharmony_ci RT5651_VOL_L_SFT, 1, 1); 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new outvol_r_control = 5488c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("Switch", RT5651_LOUT_CTRL1, 5498c2ecf20Sopenharmony_ci RT5651_VOL_R_SFT, 1, 1); 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new lout_l_mute_control = 5528c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5651_LOUT_CTRL1, 5538c2ecf20Sopenharmony_ci RT5651_L_MUTE_SFT, 1, 1); 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new lout_r_mute_control = 5568c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5651_LOUT_CTRL1, 5578c2ecf20Sopenharmony_ci RT5651_R_MUTE_SFT, 1, 1); 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new hpovol_l_control = 5608c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("Switch", RT5651_HP_VOL, 5618c2ecf20Sopenharmony_ci RT5651_VOL_L_SFT, 1, 1); 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new hpovol_r_control = 5648c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("Switch", RT5651_HP_VOL, 5658c2ecf20Sopenharmony_ci RT5651_VOL_R_SFT, 1, 1); 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new hpo_l_mute_control = 5688c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5651_HP_VOL, 5698c2ecf20Sopenharmony_ci RT5651_L_MUTE_SFT, 1, 1); 5708c2ecf20Sopenharmony_ci 5718c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new hpo_r_mute_control = 5728c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5651_HP_VOL, 5738c2ecf20Sopenharmony_ci RT5651_R_MUTE_SFT, 1, 1); 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci/* Stereo ADC source */ 5768c2ecf20Sopenharmony_cistatic const char * const rt5651_stereo1_adc1_src[] = {"DD MIX", "ADC"}; 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL( 5798c2ecf20Sopenharmony_ci rt5651_stereo1_adc1_enum, RT5651_STO1_ADC_MIXER, 5808c2ecf20Sopenharmony_ci RT5651_STO1_ADC_1_SRC_SFT, rt5651_stereo1_adc1_src); 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_sto1_adc_l1_mux = 5838c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Stereo1 ADC L1 source", rt5651_stereo1_adc1_enum); 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_sto1_adc_r1_mux = 5868c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Stereo1 ADC R1 source", rt5651_stereo1_adc1_enum); 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_cistatic const char * const rt5651_stereo1_adc2_src[] = {"DMIC", "DD MIX"}; 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL( 5918c2ecf20Sopenharmony_ci rt5651_stereo1_adc2_enum, RT5651_STO1_ADC_MIXER, 5928c2ecf20Sopenharmony_ci RT5651_STO1_ADC_2_SRC_SFT, rt5651_stereo1_adc2_src); 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_sto1_adc_l2_mux = 5958c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Stereo1 ADC L2 source", rt5651_stereo1_adc2_enum); 5968c2ecf20Sopenharmony_ci 5978c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_sto1_adc_r2_mux = 5988c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Stereo1 ADC R2 source", rt5651_stereo1_adc2_enum); 5998c2ecf20Sopenharmony_ci 6008c2ecf20Sopenharmony_ci/* Mono ADC source */ 6018c2ecf20Sopenharmony_cistatic const char * const rt5651_sto2_adc_l1_src[] = {"DD MIXL", "ADCL"}; 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL( 6048c2ecf20Sopenharmony_ci rt5651_sto2_adc_l1_enum, RT5651_STO1_ADC_MIXER, 6058c2ecf20Sopenharmony_ci RT5651_STO2_ADC_L1_SRC_SFT, rt5651_sto2_adc_l1_src); 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_sto2_adc_l1_mux = 6088c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Stereo2 ADC1 left source", rt5651_sto2_adc_l1_enum); 6098c2ecf20Sopenharmony_ci 6108c2ecf20Sopenharmony_cistatic const char * const rt5651_sto2_adc_l2_src[] = {"DMIC L", "DD MIXL"}; 6118c2ecf20Sopenharmony_ci 6128c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL( 6138c2ecf20Sopenharmony_ci rt5651_sto2_adc_l2_enum, RT5651_STO1_ADC_MIXER, 6148c2ecf20Sopenharmony_ci RT5651_STO2_ADC_L2_SRC_SFT, rt5651_sto2_adc_l2_src); 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_sto2_adc_l2_mux = 6178c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Stereo2 ADC2 left source", rt5651_sto2_adc_l2_enum); 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_cistatic const char * const rt5651_sto2_adc_r1_src[] = {"DD MIXR", "ADCR"}; 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL( 6228c2ecf20Sopenharmony_ci rt5651_sto2_adc_r1_enum, RT5651_STO1_ADC_MIXER, 6238c2ecf20Sopenharmony_ci RT5651_STO2_ADC_R1_SRC_SFT, rt5651_sto2_adc_r1_src); 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_sto2_adc_r1_mux = 6268c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Stereo2 ADC1 right source", rt5651_sto2_adc_r1_enum); 6278c2ecf20Sopenharmony_ci 6288c2ecf20Sopenharmony_cistatic const char * const rt5651_sto2_adc_r2_src[] = {"DMIC R", "DD MIXR"}; 6298c2ecf20Sopenharmony_ci 6308c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL( 6318c2ecf20Sopenharmony_ci rt5651_sto2_adc_r2_enum, RT5651_STO1_ADC_MIXER, 6328c2ecf20Sopenharmony_ci RT5651_STO2_ADC_R2_SRC_SFT, rt5651_sto2_adc_r2_src); 6338c2ecf20Sopenharmony_ci 6348c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_sto2_adc_r2_mux = 6358c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Stereo2 ADC2 right source", rt5651_sto2_adc_r2_enum); 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci/* DAC2 channel source */ 6388c2ecf20Sopenharmony_ci 6398c2ecf20Sopenharmony_cistatic const char * const rt5651_dac_src[] = {"IF1", "IF2"}; 6408c2ecf20Sopenharmony_ci 6418c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5651_dac_l2_enum, RT5651_DAC2_CTRL, 6428c2ecf20Sopenharmony_ci RT5651_SEL_DAC_L2_SFT, rt5651_dac_src); 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_dac_l2_mux = 6458c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("DAC2 left channel source", rt5651_dac_l2_enum); 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL( 6488c2ecf20Sopenharmony_ci rt5651_dac_r2_enum, RT5651_DAC2_CTRL, 6498c2ecf20Sopenharmony_ci RT5651_SEL_DAC_R2_SFT, rt5651_dac_src); 6508c2ecf20Sopenharmony_ci 6518c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_dac_r2_mux = 6528c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("DAC2 right channel source", rt5651_dac_r2_enum); 6538c2ecf20Sopenharmony_ci 6548c2ecf20Sopenharmony_ci/* IF2_ADC channel source */ 6558c2ecf20Sopenharmony_ci 6568c2ecf20Sopenharmony_cistatic const char * const rt5651_adc_src[] = {"IF1 ADC1", "IF1 ADC2"}; 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5651_if2_adc_src_enum, RT5651_DIG_INF_DATA, 6598c2ecf20Sopenharmony_ci RT5651_IF2_ADC_SRC_SFT, rt5651_adc_src); 6608c2ecf20Sopenharmony_ci 6618c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_if2_adc_src_mux = 6628c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("IF2 ADC channel source", rt5651_if2_adc_src_enum); 6638c2ecf20Sopenharmony_ci 6648c2ecf20Sopenharmony_ci/* PDM select */ 6658c2ecf20Sopenharmony_cistatic const char * const rt5651_pdm_sel[] = {"DD MIX", "Stereo DAC MIX"}; 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL( 6688c2ecf20Sopenharmony_ci rt5651_pdm_l_sel_enum, RT5651_PDM_CTL, 6698c2ecf20Sopenharmony_ci RT5651_PDM_L_SEL_SFT, rt5651_pdm_sel); 6708c2ecf20Sopenharmony_ci 6718c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL( 6728c2ecf20Sopenharmony_ci rt5651_pdm_r_sel_enum, RT5651_PDM_CTL, 6738c2ecf20Sopenharmony_ci RT5651_PDM_R_SEL_SFT, rt5651_pdm_sel); 6748c2ecf20Sopenharmony_ci 6758c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_pdm_l_mux = 6768c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("PDM L select", rt5651_pdm_l_sel_enum); 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5651_pdm_r_mux = 6798c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("PDM R select", rt5651_pdm_r_sel_enum); 6808c2ecf20Sopenharmony_ci 6818c2ecf20Sopenharmony_cistatic int rt5651_amp_power_event(struct snd_soc_dapm_widget *w, 6828c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 6838c2ecf20Sopenharmony_ci{ 6848c2ecf20Sopenharmony_ci struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 6858c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 6868c2ecf20Sopenharmony_ci 6878c2ecf20Sopenharmony_ci switch (event) { 6888c2ecf20Sopenharmony_ci case SND_SOC_DAPM_POST_PMU: 6898c2ecf20Sopenharmony_ci /* depop parameters */ 6908c2ecf20Sopenharmony_ci regmap_update_bits(rt5651->regmap, RT5651_PR_BASE + 6918c2ecf20Sopenharmony_ci RT5651_CHPUMP_INT_REG1, 0x0700, 0x0200); 6928c2ecf20Sopenharmony_ci regmap_update_bits(rt5651->regmap, RT5651_DEPOP_M2, 6938c2ecf20Sopenharmony_ci RT5651_DEPOP_MASK, RT5651_DEPOP_MAN); 6948c2ecf20Sopenharmony_ci regmap_update_bits(rt5651->regmap, RT5651_DEPOP_M1, 6958c2ecf20Sopenharmony_ci RT5651_HP_CP_MASK | RT5651_HP_SG_MASK | 6968c2ecf20Sopenharmony_ci RT5651_HP_CB_MASK, RT5651_HP_CP_PU | 6978c2ecf20Sopenharmony_ci RT5651_HP_SG_DIS | RT5651_HP_CB_PU); 6988c2ecf20Sopenharmony_ci regmap_write(rt5651->regmap, RT5651_PR_BASE + 6998c2ecf20Sopenharmony_ci RT5651_HP_DCC_INT1, 0x9f00); 7008c2ecf20Sopenharmony_ci /* headphone amp power on */ 7018c2ecf20Sopenharmony_ci regmap_update_bits(rt5651->regmap, RT5651_PWR_ANLG1, 7028c2ecf20Sopenharmony_ci RT5651_PWR_FV1 | RT5651_PWR_FV2, 0); 7038c2ecf20Sopenharmony_ci regmap_update_bits(rt5651->regmap, RT5651_PWR_ANLG1, 7048c2ecf20Sopenharmony_ci RT5651_PWR_HA, 7058c2ecf20Sopenharmony_ci RT5651_PWR_HA); 7068c2ecf20Sopenharmony_ci usleep_range(10000, 15000); 7078c2ecf20Sopenharmony_ci regmap_update_bits(rt5651->regmap, RT5651_PWR_ANLG1, 7088c2ecf20Sopenharmony_ci RT5651_PWR_FV1 | RT5651_PWR_FV2 , 7098c2ecf20Sopenharmony_ci RT5651_PWR_FV1 | RT5651_PWR_FV2); 7108c2ecf20Sopenharmony_ci break; 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_ci default: 7138c2ecf20Sopenharmony_ci return 0; 7148c2ecf20Sopenharmony_ci } 7158c2ecf20Sopenharmony_ci 7168c2ecf20Sopenharmony_ci return 0; 7178c2ecf20Sopenharmony_ci} 7188c2ecf20Sopenharmony_ci 7198c2ecf20Sopenharmony_cistatic int rt5651_hp_event(struct snd_soc_dapm_widget *w, 7208c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 7218c2ecf20Sopenharmony_ci{ 7228c2ecf20Sopenharmony_ci struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 7238c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 7248c2ecf20Sopenharmony_ci 7258c2ecf20Sopenharmony_ci switch (event) { 7268c2ecf20Sopenharmony_ci case SND_SOC_DAPM_POST_PMU: 7278c2ecf20Sopenharmony_ci /* headphone unmute sequence */ 7288c2ecf20Sopenharmony_ci regmap_update_bits(rt5651->regmap, RT5651_DEPOP_M2, 7298c2ecf20Sopenharmony_ci RT5651_DEPOP_MASK | RT5651_DIG_DP_MASK, 7308c2ecf20Sopenharmony_ci RT5651_DEPOP_AUTO | RT5651_DIG_DP_EN); 7318c2ecf20Sopenharmony_ci regmap_update_bits(rt5651->regmap, RT5651_CHARGE_PUMP, 7328c2ecf20Sopenharmony_ci RT5651_PM_HP_MASK, RT5651_PM_HP_HV); 7338c2ecf20Sopenharmony_ci 7348c2ecf20Sopenharmony_ci regmap_update_bits(rt5651->regmap, RT5651_DEPOP_M3, 7358c2ecf20Sopenharmony_ci RT5651_CP_FQ1_MASK | RT5651_CP_FQ2_MASK | 7368c2ecf20Sopenharmony_ci RT5651_CP_FQ3_MASK, 7378c2ecf20Sopenharmony_ci (RT5651_CP_FQ_192_KHZ << RT5651_CP_FQ1_SFT) | 7388c2ecf20Sopenharmony_ci (RT5651_CP_FQ_12_KHZ << RT5651_CP_FQ2_SFT) | 7398c2ecf20Sopenharmony_ci (RT5651_CP_FQ_192_KHZ << RT5651_CP_FQ3_SFT)); 7408c2ecf20Sopenharmony_ci 7418c2ecf20Sopenharmony_ci regmap_write(rt5651->regmap, RT5651_PR_BASE + 7428c2ecf20Sopenharmony_ci RT5651_MAMP_INT_REG2, 0x1c00); 7438c2ecf20Sopenharmony_ci regmap_update_bits(rt5651->regmap, RT5651_DEPOP_M1, 7448c2ecf20Sopenharmony_ci RT5651_HP_CP_MASK | RT5651_HP_SG_MASK, 7458c2ecf20Sopenharmony_ci RT5651_HP_CP_PD | RT5651_HP_SG_EN); 7468c2ecf20Sopenharmony_ci regmap_update_bits(rt5651->regmap, RT5651_PR_BASE + 7478c2ecf20Sopenharmony_ci RT5651_CHPUMP_INT_REG1, 0x0700, 0x0400); 7488c2ecf20Sopenharmony_ci rt5651->hp_mute = false; 7498c2ecf20Sopenharmony_ci break; 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci case SND_SOC_DAPM_PRE_PMD: 7528c2ecf20Sopenharmony_ci rt5651->hp_mute = true; 7538c2ecf20Sopenharmony_ci usleep_range(70000, 75000); 7548c2ecf20Sopenharmony_ci break; 7558c2ecf20Sopenharmony_ci 7568c2ecf20Sopenharmony_ci default: 7578c2ecf20Sopenharmony_ci return 0; 7588c2ecf20Sopenharmony_ci } 7598c2ecf20Sopenharmony_ci 7608c2ecf20Sopenharmony_ci return 0; 7618c2ecf20Sopenharmony_ci} 7628c2ecf20Sopenharmony_ci 7638c2ecf20Sopenharmony_cistatic int rt5651_hp_post_event(struct snd_soc_dapm_widget *w, 7648c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 7658c2ecf20Sopenharmony_ci{ 7668c2ecf20Sopenharmony_ci 7678c2ecf20Sopenharmony_ci struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 7688c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 7698c2ecf20Sopenharmony_ci 7708c2ecf20Sopenharmony_ci switch (event) { 7718c2ecf20Sopenharmony_ci case SND_SOC_DAPM_POST_PMU: 7728c2ecf20Sopenharmony_ci if (!rt5651->hp_mute) 7738c2ecf20Sopenharmony_ci usleep_range(80000, 85000); 7748c2ecf20Sopenharmony_ci 7758c2ecf20Sopenharmony_ci break; 7768c2ecf20Sopenharmony_ci 7778c2ecf20Sopenharmony_ci default: 7788c2ecf20Sopenharmony_ci return 0; 7798c2ecf20Sopenharmony_ci } 7808c2ecf20Sopenharmony_ci 7818c2ecf20Sopenharmony_ci return 0; 7828c2ecf20Sopenharmony_ci} 7838c2ecf20Sopenharmony_ci 7848c2ecf20Sopenharmony_cistatic int rt5651_bst1_event(struct snd_soc_dapm_widget *w, 7858c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 7868c2ecf20Sopenharmony_ci{ 7878c2ecf20Sopenharmony_ci struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_ci switch (event) { 7908c2ecf20Sopenharmony_ci case SND_SOC_DAPM_POST_PMU: 7918c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, 7928c2ecf20Sopenharmony_ci RT5651_PWR_BST1_OP2, RT5651_PWR_BST1_OP2); 7938c2ecf20Sopenharmony_ci break; 7948c2ecf20Sopenharmony_ci 7958c2ecf20Sopenharmony_ci case SND_SOC_DAPM_PRE_PMD: 7968c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, 7978c2ecf20Sopenharmony_ci RT5651_PWR_BST1_OP2, 0); 7988c2ecf20Sopenharmony_ci break; 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_ci default: 8018c2ecf20Sopenharmony_ci return 0; 8028c2ecf20Sopenharmony_ci } 8038c2ecf20Sopenharmony_ci 8048c2ecf20Sopenharmony_ci return 0; 8058c2ecf20Sopenharmony_ci} 8068c2ecf20Sopenharmony_ci 8078c2ecf20Sopenharmony_cistatic int rt5651_bst2_event(struct snd_soc_dapm_widget *w, 8088c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 8098c2ecf20Sopenharmony_ci{ 8108c2ecf20Sopenharmony_ci struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 8118c2ecf20Sopenharmony_ci 8128c2ecf20Sopenharmony_ci switch (event) { 8138c2ecf20Sopenharmony_ci case SND_SOC_DAPM_POST_PMU: 8148c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, 8158c2ecf20Sopenharmony_ci RT5651_PWR_BST2_OP2, RT5651_PWR_BST2_OP2); 8168c2ecf20Sopenharmony_ci break; 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_ci case SND_SOC_DAPM_PRE_PMD: 8198c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, 8208c2ecf20Sopenharmony_ci RT5651_PWR_BST2_OP2, 0); 8218c2ecf20Sopenharmony_ci break; 8228c2ecf20Sopenharmony_ci 8238c2ecf20Sopenharmony_ci default: 8248c2ecf20Sopenharmony_ci return 0; 8258c2ecf20Sopenharmony_ci } 8268c2ecf20Sopenharmony_ci 8278c2ecf20Sopenharmony_ci return 0; 8288c2ecf20Sopenharmony_ci} 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_cistatic int rt5651_bst3_event(struct snd_soc_dapm_widget *w, 8318c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 8328c2ecf20Sopenharmony_ci{ 8338c2ecf20Sopenharmony_ci struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_ci switch (event) { 8368c2ecf20Sopenharmony_ci case SND_SOC_DAPM_POST_PMU: 8378c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, 8388c2ecf20Sopenharmony_ci RT5651_PWR_BST3_OP2, RT5651_PWR_BST3_OP2); 8398c2ecf20Sopenharmony_ci break; 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ci case SND_SOC_DAPM_PRE_PMD: 8428c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, 8438c2ecf20Sopenharmony_ci RT5651_PWR_BST3_OP2, 0); 8448c2ecf20Sopenharmony_ci break; 8458c2ecf20Sopenharmony_ci 8468c2ecf20Sopenharmony_ci default: 8478c2ecf20Sopenharmony_ci return 0; 8488c2ecf20Sopenharmony_ci } 8498c2ecf20Sopenharmony_ci 8508c2ecf20Sopenharmony_ci return 0; 8518c2ecf20Sopenharmony_ci} 8528c2ecf20Sopenharmony_ci 8538c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget rt5651_dapm_widgets[] = { 8548c2ecf20Sopenharmony_ci /* ASRC */ 8558c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY_S("I2S1 ASRC", 1, RT5651_PLL_MODE_2, 8568c2ecf20Sopenharmony_ci 15, 0, NULL, 0), 8578c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY_S("I2S2 ASRC", 1, RT5651_PLL_MODE_2, 8588c2ecf20Sopenharmony_ci 14, 0, NULL, 0), 8598c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY_S("STO1 DAC ASRC", 1, RT5651_PLL_MODE_2, 8608c2ecf20Sopenharmony_ci 13, 0, NULL, 0), 8618c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY_S("STO2 DAC ASRC", 1, RT5651_PLL_MODE_2, 8628c2ecf20Sopenharmony_ci 12, 0, NULL, 0), 8638c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY_S("ADC ASRC", 1, RT5651_PLL_MODE_2, 8648c2ecf20Sopenharmony_ci 11, 0, NULL, 0), 8658c2ecf20Sopenharmony_ci 8668c2ecf20Sopenharmony_ci /* micbias */ 8678c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("LDO", RT5651_PWR_ANLG1, 8688c2ecf20Sopenharmony_ci RT5651_PWR_LDO_BIT, 0, NULL, 0), 8698c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("micbias1", RT5651_PWR_ANLG2, 8708c2ecf20Sopenharmony_ci RT5651_PWR_MB1_BIT, 0, NULL, 0), 8718c2ecf20Sopenharmony_ci /* Input Lines */ 8728c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("MIC1"), 8738c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("MIC2"), 8748c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("MIC3"), 8758c2ecf20Sopenharmony_ci 8768c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("IN1P"), 8778c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("IN2P"), 8788c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("IN2N"), 8798c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("IN3P"), 8808c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("DMIC L1"), 8818c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("DMIC R1"), 8828c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("DMIC CLK", RT5651_DMIC, RT5651_DMIC_1_EN_SFT, 8838c2ecf20Sopenharmony_ci 0, set_dmic_clk, SND_SOC_DAPM_PRE_PMU), 8848c2ecf20Sopenharmony_ci /* Boost */ 8858c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA_E("BST1", RT5651_PWR_ANLG2, 8868c2ecf20Sopenharmony_ci RT5651_PWR_BST1_BIT, 0, NULL, 0, rt5651_bst1_event, 8878c2ecf20Sopenharmony_ci SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 8888c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA_E("BST2", RT5651_PWR_ANLG2, 8898c2ecf20Sopenharmony_ci RT5651_PWR_BST2_BIT, 0, NULL, 0, rt5651_bst2_event, 8908c2ecf20Sopenharmony_ci SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 8918c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA_E("BST3", RT5651_PWR_ANLG2, 8928c2ecf20Sopenharmony_ci RT5651_PWR_BST3_BIT, 0, NULL, 0, rt5651_bst3_event, 8938c2ecf20Sopenharmony_ci SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 8948c2ecf20Sopenharmony_ci /* Input Volume */ 8958c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("INL1 VOL", RT5651_PWR_VOL, 8968c2ecf20Sopenharmony_ci RT5651_PWR_IN1_L_BIT, 0, NULL, 0), 8978c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("INR1 VOL", RT5651_PWR_VOL, 8988c2ecf20Sopenharmony_ci RT5651_PWR_IN1_R_BIT, 0, NULL, 0), 8998c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("INL2 VOL", RT5651_PWR_VOL, 9008c2ecf20Sopenharmony_ci RT5651_PWR_IN2_L_BIT, 0, NULL, 0), 9018c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("INR2 VOL", RT5651_PWR_VOL, 9028c2ecf20Sopenharmony_ci RT5651_PWR_IN2_R_BIT, 0, NULL, 0), 9038c2ecf20Sopenharmony_ci 9048c2ecf20Sopenharmony_ci /* REC Mixer */ 9058c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("RECMIXL", RT5651_PWR_MIXER, RT5651_PWR_RM_L_BIT, 0, 9068c2ecf20Sopenharmony_ci rt5651_rec_l_mix, ARRAY_SIZE(rt5651_rec_l_mix)), 9078c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("RECMIXR", RT5651_PWR_MIXER, RT5651_PWR_RM_R_BIT, 0, 9088c2ecf20Sopenharmony_ci rt5651_rec_r_mix, ARRAY_SIZE(rt5651_rec_r_mix)), 9098c2ecf20Sopenharmony_ci /* ADCs */ 9108c2ecf20Sopenharmony_ci SND_SOC_DAPM_ADC("ADC L", NULL, SND_SOC_NOPM, 0, 0), 9118c2ecf20Sopenharmony_ci SND_SOC_DAPM_ADC("ADC R", NULL, SND_SOC_NOPM, 0, 0), 9128c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("ADC L Power", RT5651_PWR_DIG1, 9138c2ecf20Sopenharmony_ci RT5651_PWR_ADC_L_BIT, 0, NULL, 0), 9148c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("ADC R Power", RT5651_PWR_DIG1, 9158c2ecf20Sopenharmony_ci RT5651_PWR_ADC_R_BIT, 0, NULL, 0), 9168c2ecf20Sopenharmony_ci /* ADC Mux */ 9178c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("Stereo1 ADC L2 Mux", SND_SOC_NOPM, 0, 0, 9188c2ecf20Sopenharmony_ci &rt5651_sto1_adc_l2_mux), 9198c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("Stereo1 ADC R2 Mux", SND_SOC_NOPM, 0, 0, 9208c2ecf20Sopenharmony_ci &rt5651_sto1_adc_r2_mux), 9218c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("Stereo1 ADC L1 Mux", SND_SOC_NOPM, 0, 0, 9228c2ecf20Sopenharmony_ci &rt5651_sto1_adc_l1_mux), 9238c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("Stereo1 ADC R1 Mux", SND_SOC_NOPM, 0, 0, 9248c2ecf20Sopenharmony_ci &rt5651_sto1_adc_r1_mux), 9258c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("Stereo2 ADC L2 Mux", SND_SOC_NOPM, 0, 0, 9268c2ecf20Sopenharmony_ci &rt5651_sto2_adc_l2_mux), 9278c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("Stereo2 ADC L1 Mux", SND_SOC_NOPM, 0, 0, 9288c2ecf20Sopenharmony_ci &rt5651_sto2_adc_l1_mux), 9298c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("Stereo2 ADC R1 Mux", SND_SOC_NOPM, 0, 0, 9308c2ecf20Sopenharmony_ci &rt5651_sto2_adc_r1_mux), 9318c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("Stereo2 ADC R2 Mux", SND_SOC_NOPM, 0, 0, 9328c2ecf20Sopenharmony_ci &rt5651_sto2_adc_r2_mux), 9338c2ecf20Sopenharmony_ci /* ADC Mixer */ 9348c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("Stereo1 Filter", RT5651_PWR_DIG2, 9358c2ecf20Sopenharmony_ci RT5651_PWR_ADC_STO1_F_BIT, 0, NULL, 0), 9368c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("Stereo2 Filter", RT5651_PWR_DIG2, 9378c2ecf20Sopenharmony_ci RT5651_PWR_ADC_STO2_F_BIT, 0, NULL, 0), 9388c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("Stereo1 ADC MIXL", SND_SOC_NOPM, 0, 0, 9398c2ecf20Sopenharmony_ci rt5651_sto1_adc_l_mix, 9408c2ecf20Sopenharmony_ci ARRAY_SIZE(rt5651_sto1_adc_l_mix)), 9418c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("Stereo1 ADC MIXR", SND_SOC_NOPM, 0, 0, 9428c2ecf20Sopenharmony_ci rt5651_sto1_adc_r_mix, 9438c2ecf20Sopenharmony_ci ARRAY_SIZE(rt5651_sto1_adc_r_mix)), 9448c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("Stereo2 ADC MIXL", SND_SOC_NOPM, 0, 0, 9458c2ecf20Sopenharmony_ci rt5651_sto2_adc_l_mix, 9468c2ecf20Sopenharmony_ci ARRAY_SIZE(rt5651_sto2_adc_l_mix)), 9478c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("Stereo2 ADC MIXR", SND_SOC_NOPM, 0, 0, 9488c2ecf20Sopenharmony_ci rt5651_sto2_adc_r_mix, 9498c2ecf20Sopenharmony_ci ARRAY_SIZE(rt5651_sto2_adc_r_mix)), 9508c2ecf20Sopenharmony_ci 9518c2ecf20Sopenharmony_ci /* Digital Interface */ 9528c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("I2S1", RT5651_PWR_DIG1, 9538c2ecf20Sopenharmony_ci RT5651_PWR_I2S1_BIT, 0, NULL, 0), 9548c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("IF1 DAC", SND_SOC_NOPM, 0, 0, NULL, 0), 9558c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("IF1 DAC1 L", SND_SOC_NOPM, 0, 0, NULL, 0), 9568c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("IF1 DAC1 R", SND_SOC_NOPM, 0, 0, NULL, 0), 9578c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("IF1 ADC1", SND_SOC_NOPM, 0, 0, NULL, 0), 9588c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("IF1 DAC2 L", SND_SOC_NOPM, 0, 0, NULL, 0), 9598c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("IF1 DAC2 R", SND_SOC_NOPM, 0, 0, NULL, 0), 9608c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("IF1 ADC2", SND_SOC_NOPM, 0, 0, NULL, 0), 9618c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("I2S2", RT5651_PWR_DIG1, 9628c2ecf20Sopenharmony_ci RT5651_PWR_I2S2_BIT, 0, NULL, 0), 9638c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("IF2 DAC", SND_SOC_NOPM, 0, 0, NULL, 0), 9648c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("IF2 DAC L", SND_SOC_NOPM, 0, 0, NULL, 0), 9658c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("IF2 DAC R", SND_SOC_NOPM, 0, 0, NULL, 0), 9668c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("IF2 ADC", SND_SOC_NOPM, 0, 0, 9678c2ecf20Sopenharmony_ci &rt5651_if2_adc_src_mux), 9688c2ecf20Sopenharmony_ci 9698c2ecf20Sopenharmony_ci /* Digital Interface Select */ 9708c2ecf20Sopenharmony_ci 9718c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("PDM L Mux", RT5651_PDM_CTL, 9728c2ecf20Sopenharmony_ci RT5651_M_PDM_L_SFT, 1, &rt5651_pdm_l_mux), 9738c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("PDM R Mux", RT5651_PDM_CTL, 9748c2ecf20Sopenharmony_ci RT5651_M_PDM_R_SFT, 1, &rt5651_pdm_r_mux), 9758c2ecf20Sopenharmony_ci /* Audio Interface */ 9768c2ecf20Sopenharmony_ci SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), 9778c2ecf20Sopenharmony_ci SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0), 9788c2ecf20Sopenharmony_ci SND_SOC_DAPM_AIF_IN("AIF2RX", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0), 9798c2ecf20Sopenharmony_ci SND_SOC_DAPM_AIF_OUT("AIF2TX", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0), 9808c2ecf20Sopenharmony_ci 9818c2ecf20Sopenharmony_ci /* Audio DSP */ 9828c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("Audio DSP", SND_SOC_NOPM, 0, 0, NULL, 0), 9838c2ecf20Sopenharmony_ci 9848c2ecf20Sopenharmony_ci /* Output Side */ 9858c2ecf20Sopenharmony_ci /* DAC mixer before sound effect */ 9868c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("DAC MIXL", SND_SOC_NOPM, 0, 0, 9878c2ecf20Sopenharmony_ci rt5651_dac_l_mix, ARRAY_SIZE(rt5651_dac_l_mix)), 9888c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("DAC MIXR", SND_SOC_NOPM, 0, 0, 9898c2ecf20Sopenharmony_ci rt5651_dac_r_mix, ARRAY_SIZE(rt5651_dac_r_mix)), 9908c2ecf20Sopenharmony_ci 9918c2ecf20Sopenharmony_ci /* DAC2 channel Mux */ 9928c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("DAC L2 Mux", SND_SOC_NOPM, 0, 0, &rt5651_dac_l2_mux), 9938c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("DAC R2 Mux", SND_SOC_NOPM, 0, 0, &rt5651_dac_r2_mux), 9948c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("DAC L2 Volume", SND_SOC_NOPM, 0, 0, NULL, 0), 9958c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("DAC R2 Volume", SND_SOC_NOPM, 0, 0, NULL, 0), 9968c2ecf20Sopenharmony_ci 9978c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("Stero1 DAC Power", RT5651_PWR_DIG2, 9988c2ecf20Sopenharmony_ci RT5651_PWR_DAC_STO1_F_BIT, 0, NULL, 0), 9998c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("Stero2 DAC Power", RT5651_PWR_DIG2, 10008c2ecf20Sopenharmony_ci RT5651_PWR_DAC_STO2_F_BIT, 0, NULL, 0), 10018c2ecf20Sopenharmony_ci /* DAC Mixer */ 10028c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("Stereo DAC MIXL", SND_SOC_NOPM, 0, 0, 10038c2ecf20Sopenharmony_ci rt5651_sto_dac_l_mix, 10048c2ecf20Sopenharmony_ci ARRAY_SIZE(rt5651_sto_dac_l_mix)), 10058c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("Stereo DAC MIXR", SND_SOC_NOPM, 0, 0, 10068c2ecf20Sopenharmony_ci rt5651_sto_dac_r_mix, 10078c2ecf20Sopenharmony_ci ARRAY_SIZE(rt5651_sto_dac_r_mix)), 10088c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("DD MIXL", SND_SOC_NOPM, 0, 0, 10098c2ecf20Sopenharmony_ci rt5651_dd_dac_l_mix, 10108c2ecf20Sopenharmony_ci ARRAY_SIZE(rt5651_dd_dac_l_mix)), 10118c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("DD MIXR", SND_SOC_NOPM, 0, 0, 10128c2ecf20Sopenharmony_ci rt5651_dd_dac_r_mix, 10138c2ecf20Sopenharmony_ci ARRAY_SIZE(rt5651_dd_dac_r_mix)), 10148c2ecf20Sopenharmony_ci 10158c2ecf20Sopenharmony_ci /* DACs */ 10168c2ecf20Sopenharmony_ci SND_SOC_DAPM_DAC("DAC L1", NULL, SND_SOC_NOPM, 0, 0), 10178c2ecf20Sopenharmony_ci SND_SOC_DAPM_DAC("DAC R1", NULL, SND_SOC_NOPM, 0, 0), 10188c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("DAC L1 Power", RT5651_PWR_DIG1, 10198c2ecf20Sopenharmony_ci RT5651_PWR_DAC_L1_BIT, 0, NULL, 0), 10208c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("DAC R1 Power", RT5651_PWR_DIG1, 10218c2ecf20Sopenharmony_ci RT5651_PWR_DAC_R1_BIT, 0, NULL, 0), 10228c2ecf20Sopenharmony_ci /* OUT Mixer */ 10238c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("OUT MIXL", RT5651_PWR_MIXER, RT5651_PWR_OM_L_BIT, 10248c2ecf20Sopenharmony_ci 0, rt5651_out_l_mix, ARRAY_SIZE(rt5651_out_l_mix)), 10258c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("OUT MIXR", RT5651_PWR_MIXER, RT5651_PWR_OM_R_BIT, 10268c2ecf20Sopenharmony_ci 0, rt5651_out_r_mix, ARRAY_SIZE(rt5651_out_r_mix)), 10278c2ecf20Sopenharmony_ci /* Ouput Volume */ 10288c2ecf20Sopenharmony_ci SND_SOC_DAPM_SWITCH("OUTVOL L", RT5651_PWR_VOL, 10298c2ecf20Sopenharmony_ci RT5651_PWR_OV_L_BIT, 0, &outvol_l_control), 10308c2ecf20Sopenharmony_ci SND_SOC_DAPM_SWITCH("OUTVOL R", RT5651_PWR_VOL, 10318c2ecf20Sopenharmony_ci RT5651_PWR_OV_R_BIT, 0, &outvol_r_control), 10328c2ecf20Sopenharmony_ci SND_SOC_DAPM_SWITCH("HPOVOL L", RT5651_PWR_VOL, 10338c2ecf20Sopenharmony_ci RT5651_PWR_HV_L_BIT, 0, &hpovol_l_control), 10348c2ecf20Sopenharmony_ci SND_SOC_DAPM_SWITCH("HPOVOL R", RT5651_PWR_VOL, 10358c2ecf20Sopenharmony_ci RT5651_PWR_HV_R_BIT, 0, &hpovol_r_control), 10368c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("INL1", RT5651_PWR_VOL, 10378c2ecf20Sopenharmony_ci RT5651_PWR_IN1_L_BIT, 0, NULL, 0), 10388c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("INR1", RT5651_PWR_VOL, 10398c2ecf20Sopenharmony_ci RT5651_PWR_IN1_R_BIT, 0, NULL, 0), 10408c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("INL2", RT5651_PWR_VOL, 10418c2ecf20Sopenharmony_ci RT5651_PWR_IN2_L_BIT, 0, NULL, 0), 10428c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("INR2", RT5651_PWR_VOL, 10438c2ecf20Sopenharmony_ci RT5651_PWR_IN2_R_BIT, 0, NULL, 0), 10448c2ecf20Sopenharmony_ci /* HPO/LOUT/Mono Mixer */ 10458c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("HPOL MIX", SND_SOC_NOPM, 0, 0, 10468c2ecf20Sopenharmony_ci rt5651_hpo_mix, ARRAY_SIZE(rt5651_hpo_mix)), 10478c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("HPOR MIX", SND_SOC_NOPM, 0, 0, 10488c2ecf20Sopenharmony_ci rt5651_hpo_mix, ARRAY_SIZE(rt5651_hpo_mix)), 10498c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("HP L Amp", RT5651_PWR_ANLG1, 10508c2ecf20Sopenharmony_ci RT5651_PWR_HP_L_BIT, 0, NULL, 0), 10518c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("HP R Amp", RT5651_PWR_ANLG1, 10528c2ecf20Sopenharmony_ci RT5651_PWR_HP_R_BIT, 0, NULL, 0), 10538c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("LOUT MIX", RT5651_PWR_ANLG1, RT5651_PWR_LM_BIT, 0, 10548c2ecf20Sopenharmony_ci rt5651_lout_mix, ARRAY_SIZE(rt5651_lout_mix)), 10558c2ecf20Sopenharmony_ci 10568c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("Amp Power", RT5651_PWR_ANLG1, 10578c2ecf20Sopenharmony_ci RT5651_PWR_HA_BIT, 0, rt5651_amp_power_event, 10588c2ecf20Sopenharmony_ci SND_SOC_DAPM_POST_PMU), 10598c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA_S("HP Amp", 1, SND_SOC_NOPM, 0, 0, rt5651_hp_event, 10608c2ecf20Sopenharmony_ci SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 10618c2ecf20Sopenharmony_ci SND_SOC_DAPM_SWITCH("HPO L Playback", SND_SOC_NOPM, 0, 0, 10628c2ecf20Sopenharmony_ci &hpo_l_mute_control), 10638c2ecf20Sopenharmony_ci SND_SOC_DAPM_SWITCH("HPO R Playback", SND_SOC_NOPM, 0, 0, 10648c2ecf20Sopenharmony_ci &hpo_r_mute_control), 10658c2ecf20Sopenharmony_ci SND_SOC_DAPM_SWITCH("LOUT L Playback", SND_SOC_NOPM, 0, 0, 10668c2ecf20Sopenharmony_ci &lout_l_mute_control), 10678c2ecf20Sopenharmony_ci SND_SOC_DAPM_SWITCH("LOUT R Playback", SND_SOC_NOPM, 0, 0, 10688c2ecf20Sopenharmony_ci &lout_r_mute_control), 10698c2ecf20Sopenharmony_ci SND_SOC_DAPM_POST("HP Post", rt5651_hp_post_event), 10708c2ecf20Sopenharmony_ci 10718c2ecf20Sopenharmony_ci /* Output Lines */ 10728c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("HPOL"), 10738c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("HPOR"), 10748c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("LOUTL"), 10758c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("LOUTR"), 10768c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("PDML"), 10778c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("PDMR"), 10788c2ecf20Sopenharmony_ci}; 10798c2ecf20Sopenharmony_ci 10808c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route rt5651_dapm_routes[] = { 10818c2ecf20Sopenharmony_ci {"Stero1 DAC Power", NULL, "STO1 DAC ASRC"}, 10828c2ecf20Sopenharmony_ci {"Stero2 DAC Power", NULL, "STO2 DAC ASRC"}, 10838c2ecf20Sopenharmony_ci {"I2S1", NULL, "I2S1 ASRC"}, 10848c2ecf20Sopenharmony_ci {"I2S2", NULL, "I2S2 ASRC"}, 10858c2ecf20Sopenharmony_ci 10868c2ecf20Sopenharmony_ci {"IN1P", NULL, "LDO"}, 10878c2ecf20Sopenharmony_ci {"IN2P", NULL, "LDO"}, 10888c2ecf20Sopenharmony_ci {"IN3P", NULL, "LDO"}, 10898c2ecf20Sopenharmony_ci 10908c2ecf20Sopenharmony_ci {"IN1P", NULL, "MIC1"}, 10918c2ecf20Sopenharmony_ci {"IN2P", NULL, "MIC2"}, 10928c2ecf20Sopenharmony_ci {"IN2N", NULL, "MIC2"}, 10938c2ecf20Sopenharmony_ci {"IN3P", NULL, "MIC3"}, 10948c2ecf20Sopenharmony_ci 10958c2ecf20Sopenharmony_ci {"BST1", NULL, "IN1P"}, 10968c2ecf20Sopenharmony_ci {"BST2", NULL, "IN2P"}, 10978c2ecf20Sopenharmony_ci {"BST2", NULL, "IN2N"}, 10988c2ecf20Sopenharmony_ci {"BST3", NULL, "IN3P"}, 10998c2ecf20Sopenharmony_ci 11008c2ecf20Sopenharmony_ci {"INL1 VOL", NULL, "IN2P"}, 11018c2ecf20Sopenharmony_ci {"INR1 VOL", NULL, "IN2N"}, 11028c2ecf20Sopenharmony_ci 11038c2ecf20Sopenharmony_ci {"RECMIXL", "INL1 Switch", "INL1 VOL"}, 11048c2ecf20Sopenharmony_ci {"RECMIXL", "BST3 Switch", "BST3"}, 11058c2ecf20Sopenharmony_ci {"RECMIXL", "BST2 Switch", "BST2"}, 11068c2ecf20Sopenharmony_ci {"RECMIXL", "BST1 Switch", "BST1"}, 11078c2ecf20Sopenharmony_ci 11088c2ecf20Sopenharmony_ci {"RECMIXR", "INR1 Switch", "INR1 VOL"}, 11098c2ecf20Sopenharmony_ci {"RECMIXR", "BST3 Switch", "BST3"}, 11108c2ecf20Sopenharmony_ci {"RECMIXR", "BST2 Switch", "BST2"}, 11118c2ecf20Sopenharmony_ci {"RECMIXR", "BST1 Switch", "BST1"}, 11128c2ecf20Sopenharmony_ci 11138c2ecf20Sopenharmony_ci {"ADC L", NULL, "RECMIXL"}, 11148c2ecf20Sopenharmony_ci {"ADC L", NULL, "ADC L Power"}, 11158c2ecf20Sopenharmony_ci {"ADC R", NULL, "RECMIXR"}, 11168c2ecf20Sopenharmony_ci {"ADC R", NULL, "ADC R Power"}, 11178c2ecf20Sopenharmony_ci 11188c2ecf20Sopenharmony_ci {"DMIC L1", NULL, "DMIC CLK"}, 11198c2ecf20Sopenharmony_ci {"DMIC R1", NULL, "DMIC CLK"}, 11208c2ecf20Sopenharmony_ci 11218c2ecf20Sopenharmony_ci {"Stereo1 ADC L2 Mux", "DMIC", "DMIC L1"}, 11228c2ecf20Sopenharmony_ci {"Stereo1 ADC L2 Mux", "DD MIX", "DD MIXL"}, 11238c2ecf20Sopenharmony_ci {"Stereo1 ADC L1 Mux", "ADC", "ADC L"}, 11248c2ecf20Sopenharmony_ci {"Stereo1 ADC L1 Mux", "DD MIX", "DD MIXL"}, 11258c2ecf20Sopenharmony_ci 11268c2ecf20Sopenharmony_ci {"Stereo1 ADC R1 Mux", "ADC", "ADC R"}, 11278c2ecf20Sopenharmony_ci {"Stereo1 ADC R1 Mux", "DD MIX", "DD MIXR"}, 11288c2ecf20Sopenharmony_ci {"Stereo1 ADC R2 Mux", "DMIC", "DMIC R1"}, 11298c2ecf20Sopenharmony_ci {"Stereo1 ADC R2 Mux", "DD MIX", "DD MIXR"}, 11308c2ecf20Sopenharmony_ci 11318c2ecf20Sopenharmony_ci {"Stereo2 ADC L2 Mux", "DMIC L", "DMIC L1"}, 11328c2ecf20Sopenharmony_ci {"Stereo2 ADC L2 Mux", "DD MIXL", "DD MIXL"}, 11338c2ecf20Sopenharmony_ci {"Stereo2 ADC L1 Mux", "DD MIXL", "DD MIXL"}, 11348c2ecf20Sopenharmony_ci {"Stereo2 ADC L1 Mux", "ADCL", "ADC L"}, 11358c2ecf20Sopenharmony_ci 11368c2ecf20Sopenharmony_ci {"Stereo2 ADC R1 Mux", "DD MIXR", "DD MIXR"}, 11378c2ecf20Sopenharmony_ci {"Stereo2 ADC R1 Mux", "ADCR", "ADC R"}, 11388c2ecf20Sopenharmony_ci {"Stereo2 ADC R2 Mux", "DMIC R", "DMIC R1"}, 11398c2ecf20Sopenharmony_ci {"Stereo2 ADC R2 Mux", "DD MIXR", "DD MIXR"}, 11408c2ecf20Sopenharmony_ci 11418c2ecf20Sopenharmony_ci {"Stereo1 ADC MIXL", "ADC1 Switch", "Stereo1 ADC L1 Mux"}, 11428c2ecf20Sopenharmony_ci {"Stereo1 ADC MIXL", "ADC2 Switch", "Stereo1 ADC L2 Mux"}, 11438c2ecf20Sopenharmony_ci {"Stereo1 ADC MIXL", NULL, "Stereo1 Filter"}, 11448c2ecf20Sopenharmony_ci {"Stereo1 Filter", NULL, "ADC ASRC"}, 11458c2ecf20Sopenharmony_ci 11468c2ecf20Sopenharmony_ci {"Stereo1 ADC MIXR", "ADC1 Switch", "Stereo1 ADC R1 Mux"}, 11478c2ecf20Sopenharmony_ci {"Stereo1 ADC MIXR", "ADC2 Switch", "Stereo1 ADC R2 Mux"}, 11488c2ecf20Sopenharmony_ci {"Stereo1 ADC MIXR", NULL, "Stereo1 Filter"}, 11498c2ecf20Sopenharmony_ci 11508c2ecf20Sopenharmony_ci {"Stereo2 ADC MIXL", "ADC1 Switch", "Stereo2 ADC L1 Mux"}, 11518c2ecf20Sopenharmony_ci {"Stereo2 ADC MIXL", "ADC2 Switch", "Stereo2 ADC L2 Mux"}, 11528c2ecf20Sopenharmony_ci {"Stereo2 ADC MIXL", NULL, "Stereo2 Filter"}, 11538c2ecf20Sopenharmony_ci {"Stereo2 Filter", NULL, "ADC ASRC"}, 11548c2ecf20Sopenharmony_ci 11558c2ecf20Sopenharmony_ci {"Stereo2 ADC MIXR", "ADC1 Switch", "Stereo2 ADC R1 Mux"}, 11568c2ecf20Sopenharmony_ci {"Stereo2 ADC MIXR", "ADC2 Switch", "Stereo2 ADC R2 Mux"}, 11578c2ecf20Sopenharmony_ci {"Stereo2 ADC MIXR", NULL, "Stereo2 Filter"}, 11588c2ecf20Sopenharmony_ci 11598c2ecf20Sopenharmony_ci {"IF1 ADC2", NULL, "Stereo2 ADC MIXL"}, 11608c2ecf20Sopenharmony_ci {"IF1 ADC2", NULL, "Stereo2 ADC MIXR"}, 11618c2ecf20Sopenharmony_ci {"IF1 ADC1", NULL, "Stereo1 ADC MIXL"}, 11628c2ecf20Sopenharmony_ci {"IF1 ADC1", NULL, "Stereo1 ADC MIXR"}, 11638c2ecf20Sopenharmony_ci 11648c2ecf20Sopenharmony_ci {"IF1 ADC1", NULL, "I2S1"}, 11658c2ecf20Sopenharmony_ci 11668c2ecf20Sopenharmony_ci {"IF2 ADC", "IF1 ADC1", "IF1 ADC1"}, 11678c2ecf20Sopenharmony_ci {"IF2 ADC", "IF1 ADC2", "IF1 ADC2"}, 11688c2ecf20Sopenharmony_ci {"IF2 ADC", NULL, "I2S2"}, 11698c2ecf20Sopenharmony_ci 11708c2ecf20Sopenharmony_ci {"AIF1TX", NULL, "IF1 ADC1"}, 11718c2ecf20Sopenharmony_ci {"AIF1TX", NULL, "IF1 ADC2"}, 11728c2ecf20Sopenharmony_ci {"AIF2TX", NULL, "IF2 ADC"}, 11738c2ecf20Sopenharmony_ci 11748c2ecf20Sopenharmony_ci {"IF1 DAC", NULL, "AIF1RX"}, 11758c2ecf20Sopenharmony_ci {"IF1 DAC", NULL, "I2S1"}, 11768c2ecf20Sopenharmony_ci {"IF2 DAC", NULL, "AIF2RX"}, 11778c2ecf20Sopenharmony_ci {"IF2 DAC", NULL, "I2S2"}, 11788c2ecf20Sopenharmony_ci 11798c2ecf20Sopenharmony_ci {"IF1 DAC1 L", NULL, "IF1 DAC"}, 11808c2ecf20Sopenharmony_ci {"IF1 DAC1 R", NULL, "IF1 DAC"}, 11818c2ecf20Sopenharmony_ci {"IF1 DAC2 L", NULL, "IF1 DAC"}, 11828c2ecf20Sopenharmony_ci {"IF1 DAC2 R", NULL, "IF1 DAC"}, 11838c2ecf20Sopenharmony_ci {"IF2 DAC L", NULL, "IF2 DAC"}, 11848c2ecf20Sopenharmony_ci {"IF2 DAC R", NULL, "IF2 DAC"}, 11858c2ecf20Sopenharmony_ci 11868c2ecf20Sopenharmony_ci {"DAC MIXL", "Stereo ADC Switch", "Stereo1 ADC MIXL"}, 11878c2ecf20Sopenharmony_ci {"DAC MIXL", "INF1 Switch", "IF1 DAC1 L"}, 11888c2ecf20Sopenharmony_ci {"DAC MIXR", "Stereo ADC Switch", "Stereo1 ADC MIXR"}, 11898c2ecf20Sopenharmony_ci {"DAC MIXR", "INF1 Switch", "IF1 DAC1 R"}, 11908c2ecf20Sopenharmony_ci 11918c2ecf20Sopenharmony_ci {"Audio DSP", NULL, "DAC MIXL"}, 11928c2ecf20Sopenharmony_ci {"Audio DSP", NULL, "DAC MIXR"}, 11938c2ecf20Sopenharmony_ci 11948c2ecf20Sopenharmony_ci {"DAC L2 Mux", "IF1", "IF1 DAC2 L"}, 11958c2ecf20Sopenharmony_ci {"DAC L2 Mux", "IF2", "IF2 DAC L"}, 11968c2ecf20Sopenharmony_ci {"DAC L2 Volume", NULL, "DAC L2 Mux"}, 11978c2ecf20Sopenharmony_ci 11988c2ecf20Sopenharmony_ci {"DAC R2 Mux", "IF1", "IF1 DAC2 R"}, 11998c2ecf20Sopenharmony_ci {"DAC R2 Mux", "IF2", "IF2 DAC R"}, 12008c2ecf20Sopenharmony_ci {"DAC R2 Volume", NULL, "DAC R2 Mux"}, 12018c2ecf20Sopenharmony_ci 12028c2ecf20Sopenharmony_ci {"Stereo DAC MIXL", "DAC L1 Switch", "Audio DSP"}, 12038c2ecf20Sopenharmony_ci {"Stereo DAC MIXL", "DAC L2 Switch", "DAC L2 Volume"}, 12048c2ecf20Sopenharmony_ci {"Stereo DAC MIXL", "DAC R1 Switch", "DAC MIXR"}, 12058c2ecf20Sopenharmony_ci {"Stereo DAC MIXL", NULL, "Stero1 DAC Power"}, 12068c2ecf20Sopenharmony_ci {"Stereo DAC MIXL", NULL, "Stero2 DAC Power"}, 12078c2ecf20Sopenharmony_ci {"Stereo DAC MIXR", "DAC R1 Switch", "Audio DSP"}, 12088c2ecf20Sopenharmony_ci {"Stereo DAC MIXR", "DAC R2 Switch", "DAC R2 Volume"}, 12098c2ecf20Sopenharmony_ci {"Stereo DAC MIXR", "DAC L1 Switch", "DAC MIXL"}, 12108c2ecf20Sopenharmony_ci {"Stereo DAC MIXR", NULL, "Stero1 DAC Power"}, 12118c2ecf20Sopenharmony_ci {"Stereo DAC MIXR", NULL, "Stero2 DAC Power"}, 12128c2ecf20Sopenharmony_ci 12138c2ecf20Sopenharmony_ci {"PDM L Mux", "Stereo DAC MIX", "Stereo DAC MIXL"}, 12148c2ecf20Sopenharmony_ci {"PDM L Mux", "DD MIX", "DAC MIXL"}, 12158c2ecf20Sopenharmony_ci {"PDM R Mux", "Stereo DAC MIX", "Stereo DAC MIXR"}, 12168c2ecf20Sopenharmony_ci {"PDM R Mux", "DD MIX", "DAC MIXR"}, 12178c2ecf20Sopenharmony_ci 12188c2ecf20Sopenharmony_ci {"DAC L1", NULL, "Stereo DAC MIXL"}, 12198c2ecf20Sopenharmony_ci {"DAC L1", NULL, "DAC L1 Power"}, 12208c2ecf20Sopenharmony_ci {"DAC R1", NULL, "Stereo DAC MIXR"}, 12218c2ecf20Sopenharmony_ci {"DAC R1", NULL, "DAC R1 Power"}, 12228c2ecf20Sopenharmony_ci 12238c2ecf20Sopenharmony_ci {"DD MIXL", "DAC L1 Switch", "DAC MIXL"}, 12248c2ecf20Sopenharmony_ci {"DD MIXL", "DAC L2 Switch", "DAC L2 Volume"}, 12258c2ecf20Sopenharmony_ci {"DD MIXL", "DAC R2 Switch", "DAC R2 Volume"}, 12268c2ecf20Sopenharmony_ci {"DD MIXL", NULL, "Stero2 DAC Power"}, 12278c2ecf20Sopenharmony_ci 12288c2ecf20Sopenharmony_ci {"DD MIXR", "DAC R1 Switch", "DAC MIXR"}, 12298c2ecf20Sopenharmony_ci {"DD MIXR", "DAC R2 Switch", "DAC R2 Volume"}, 12308c2ecf20Sopenharmony_ci {"DD MIXR", "DAC L2 Switch", "DAC L2 Volume"}, 12318c2ecf20Sopenharmony_ci {"DD MIXR", NULL, "Stero2 DAC Power"}, 12328c2ecf20Sopenharmony_ci 12338c2ecf20Sopenharmony_ci {"OUT MIXL", "BST1 Switch", "BST1"}, 12348c2ecf20Sopenharmony_ci {"OUT MIXL", "BST2 Switch", "BST2"}, 12358c2ecf20Sopenharmony_ci {"OUT MIXL", "INL1 Switch", "INL1 VOL"}, 12368c2ecf20Sopenharmony_ci {"OUT MIXL", "REC MIXL Switch", "RECMIXL"}, 12378c2ecf20Sopenharmony_ci {"OUT MIXL", "DAC L1 Switch", "DAC L1"}, 12388c2ecf20Sopenharmony_ci 12398c2ecf20Sopenharmony_ci {"OUT MIXR", "BST2 Switch", "BST2"}, 12408c2ecf20Sopenharmony_ci {"OUT MIXR", "BST1 Switch", "BST1"}, 12418c2ecf20Sopenharmony_ci {"OUT MIXR", "INR1 Switch", "INR1 VOL"}, 12428c2ecf20Sopenharmony_ci {"OUT MIXR", "REC MIXR Switch", "RECMIXR"}, 12438c2ecf20Sopenharmony_ci {"OUT MIXR", "DAC R1 Switch", "DAC R1"}, 12448c2ecf20Sopenharmony_ci 12458c2ecf20Sopenharmony_ci {"HPOVOL L", "Switch", "OUT MIXL"}, 12468c2ecf20Sopenharmony_ci {"HPOVOL R", "Switch", "OUT MIXR"}, 12478c2ecf20Sopenharmony_ci {"OUTVOL L", "Switch", "OUT MIXL"}, 12488c2ecf20Sopenharmony_ci {"OUTVOL R", "Switch", "OUT MIXR"}, 12498c2ecf20Sopenharmony_ci 12508c2ecf20Sopenharmony_ci {"HPOL MIX", "HPO MIX DAC1 Switch", "DAC L1"}, 12518c2ecf20Sopenharmony_ci {"HPOL MIX", "HPO MIX HPVOL Switch", "HPOVOL L"}, 12528c2ecf20Sopenharmony_ci {"HPOL MIX", NULL, "HP L Amp"}, 12538c2ecf20Sopenharmony_ci {"HPOR MIX", "HPO MIX DAC1 Switch", "DAC R1"}, 12548c2ecf20Sopenharmony_ci {"HPOR MIX", "HPO MIX HPVOL Switch", "HPOVOL R"}, 12558c2ecf20Sopenharmony_ci {"HPOR MIX", NULL, "HP R Amp"}, 12568c2ecf20Sopenharmony_ci 12578c2ecf20Sopenharmony_ci {"LOUT MIX", "DAC L1 Switch", "DAC L1"}, 12588c2ecf20Sopenharmony_ci {"LOUT MIX", "DAC R1 Switch", "DAC R1"}, 12598c2ecf20Sopenharmony_ci {"LOUT MIX", "OUTVOL L Switch", "OUTVOL L"}, 12608c2ecf20Sopenharmony_ci {"LOUT MIX", "OUTVOL R Switch", "OUTVOL R"}, 12618c2ecf20Sopenharmony_ci 12628c2ecf20Sopenharmony_ci {"HP Amp", NULL, "HPOL MIX"}, 12638c2ecf20Sopenharmony_ci {"HP Amp", NULL, "HPOR MIX"}, 12648c2ecf20Sopenharmony_ci {"HP Amp", NULL, "Amp Power"}, 12658c2ecf20Sopenharmony_ci {"HPO L Playback", "Switch", "HP Amp"}, 12668c2ecf20Sopenharmony_ci {"HPO R Playback", "Switch", "HP Amp"}, 12678c2ecf20Sopenharmony_ci {"HPOL", NULL, "HPO L Playback"}, 12688c2ecf20Sopenharmony_ci {"HPOR", NULL, "HPO R Playback"}, 12698c2ecf20Sopenharmony_ci 12708c2ecf20Sopenharmony_ci {"LOUT L Playback", "Switch", "LOUT MIX"}, 12718c2ecf20Sopenharmony_ci {"LOUT R Playback", "Switch", "LOUT MIX"}, 12728c2ecf20Sopenharmony_ci {"LOUTL", NULL, "LOUT L Playback"}, 12738c2ecf20Sopenharmony_ci {"LOUTL", NULL, "Amp Power"}, 12748c2ecf20Sopenharmony_ci {"LOUTR", NULL, "LOUT R Playback"}, 12758c2ecf20Sopenharmony_ci {"LOUTR", NULL, "Amp Power"}, 12768c2ecf20Sopenharmony_ci 12778c2ecf20Sopenharmony_ci {"PDML", NULL, "PDM L Mux"}, 12788c2ecf20Sopenharmony_ci {"PDMR", NULL, "PDM R Mux"}, 12798c2ecf20Sopenharmony_ci}; 12808c2ecf20Sopenharmony_ci 12818c2ecf20Sopenharmony_cistatic int rt5651_hw_params(struct snd_pcm_substream *substream, 12828c2ecf20Sopenharmony_ci struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 12838c2ecf20Sopenharmony_ci{ 12848c2ecf20Sopenharmony_ci struct snd_soc_component *component = dai->component; 12858c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 12868c2ecf20Sopenharmony_ci unsigned int val_len = 0, val_clk, mask_clk; 12878c2ecf20Sopenharmony_ci int pre_div, bclk_ms, frame_size; 12888c2ecf20Sopenharmony_ci 12898c2ecf20Sopenharmony_ci rt5651->lrck[dai->id] = params_rate(params); 12908c2ecf20Sopenharmony_ci pre_div = rl6231_get_clk_info(rt5651->sysclk, rt5651->lrck[dai->id]); 12918c2ecf20Sopenharmony_ci 12928c2ecf20Sopenharmony_ci if (pre_div < 0) { 12938c2ecf20Sopenharmony_ci dev_err(component->dev, "Unsupported clock setting\n"); 12948c2ecf20Sopenharmony_ci return -EINVAL; 12958c2ecf20Sopenharmony_ci } 12968c2ecf20Sopenharmony_ci frame_size = snd_soc_params_to_frame_size(params); 12978c2ecf20Sopenharmony_ci if (frame_size < 0) { 12988c2ecf20Sopenharmony_ci dev_err(component->dev, "Unsupported frame size: %d\n", frame_size); 12998c2ecf20Sopenharmony_ci return -EINVAL; 13008c2ecf20Sopenharmony_ci } 13018c2ecf20Sopenharmony_ci bclk_ms = frame_size > 32 ? 1 : 0; 13028c2ecf20Sopenharmony_ci rt5651->bclk[dai->id] = rt5651->lrck[dai->id] * (32 << bclk_ms); 13038c2ecf20Sopenharmony_ci 13048c2ecf20Sopenharmony_ci dev_dbg(dai->dev, "bclk is %dHz and lrck is %dHz\n", 13058c2ecf20Sopenharmony_ci rt5651->bclk[dai->id], rt5651->lrck[dai->id]); 13068c2ecf20Sopenharmony_ci dev_dbg(dai->dev, "bclk_ms is %d and pre_div is %d for iis %d\n", 13078c2ecf20Sopenharmony_ci bclk_ms, pre_div, dai->id); 13088c2ecf20Sopenharmony_ci 13098c2ecf20Sopenharmony_ci switch (params_width(params)) { 13108c2ecf20Sopenharmony_ci case 16: 13118c2ecf20Sopenharmony_ci break; 13128c2ecf20Sopenharmony_ci case 20: 13138c2ecf20Sopenharmony_ci val_len |= RT5651_I2S_DL_20; 13148c2ecf20Sopenharmony_ci break; 13158c2ecf20Sopenharmony_ci case 24: 13168c2ecf20Sopenharmony_ci val_len |= RT5651_I2S_DL_24; 13178c2ecf20Sopenharmony_ci break; 13188c2ecf20Sopenharmony_ci case 8: 13198c2ecf20Sopenharmony_ci val_len |= RT5651_I2S_DL_8; 13208c2ecf20Sopenharmony_ci break; 13218c2ecf20Sopenharmony_ci default: 13228c2ecf20Sopenharmony_ci return -EINVAL; 13238c2ecf20Sopenharmony_ci } 13248c2ecf20Sopenharmony_ci 13258c2ecf20Sopenharmony_ci switch (dai->id) { 13268c2ecf20Sopenharmony_ci case RT5651_AIF1: 13278c2ecf20Sopenharmony_ci mask_clk = RT5651_I2S_PD1_MASK; 13288c2ecf20Sopenharmony_ci val_clk = pre_div << RT5651_I2S_PD1_SFT; 13298c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_I2S1_SDP, 13308c2ecf20Sopenharmony_ci RT5651_I2S_DL_MASK, val_len); 13318c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_ADDA_CLK1, mask_clk, val_clk); 13328c2ecf20Sopenharmony_ci break; 13338c2ecf20Sopenharmony_ci case RT5651_AIF2: 13348c2ecf20Sopenharmony_ci mask_clk = RT5651_I2S_BCLK_MS2_MASK | RT5651_I2S_PD2_MASK; 13358c2ecf20Sopenharmony_ci val_clk = pre_div << RT5651_I2S_PD2_SFT; 13368c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_I2S2_SDP, 13378c2ecf20Sopenharmony_ci RT5651_I2S_DL_MASK, val_len); 13388c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_ADDA_CLK1, mask_clk, val_clk); 13398c2ecf20Sopenharmony_ci break; 13408c2ecf20Sopenharmony_ci default: 13418c2ecf20Sopenharmony_ci dev_err(component->dev, "Wrong dai->id: %d\n", dai->id); 13428c2ecf20Sopenharmony_ci return -EINVAL; 13438c2ecf20Sopenharmony_ci } 13448c2ecf20Sopenharmony_ci 13458c2ecf20Sopenharmony_ci return 0; 13468c2ecf20Sopenharmony_ci} 13478c2ecf20Sopenharmony_ci 13488c2ecf20Sopenharmony_cistatic int rt5651_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) 13498c2ecf20Sopenharmony_ci{ 13508c2ecf20Sopenharmony_ci struct snd_soc_component *component = dai->component; 13518c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 13528c2ecf20Sopenharmony_ci unsigned int reg_val = 0; 13538c2ecf20Sopenharmony_ci 13548c2ecf20Sopenharmony_ci switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 13558c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_CBM_CFM: 13568c2ecf20Sopenharmony_ci rt5651->master[dai->id] = 1; 13578c2ecf20Sopenharmony_ci break; 13588c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_CBS_CFS: 13598c2ecf20Sopenharmony_ci reg_val |= RT5651_I2S_MS_S; 13608c2ecf20Sopenharmony_ci rt5651->master[dai->id] = 0; 13618c2ecf20Sopenharmony_ci break; 13628c2ecf20Sopenharmony_ci default: 13638c2ecf20Sopenharmony_ci return -EINVAL; 13648c2ecf20Sopenharmony_ci } 13658c2ecf20Sopenharmony_ci 13668c2ecf20Sopenharmony_ci switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 13678c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_NB_NF: 13688c2ecf20Sopenharmony_ci break; 13698c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_IB_NF: 13708c2ecf20Sopenharmony_ci reg_val |= RT5651_I2S_BP_INV; 13718c2ecf20Sopenharmony_ci break; 13728c2ecf20Sopenharmony_ci default: 13738c2ecf20Sopenharmony_ci return -EINVAL; 13748c2ecf20Sopenharmony_ci } 13758c2ecf20Sopenharmony_ci 13768c2ecf20Sopenharmony_ci switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 13778c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_I2S: 13788c2ecf20Sopenharmony_ci break; 13798c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_LEFT_J: 13808c2ecf20Sopenharmony_ci reg_val |= RT5651_I2S_DF_LEFT; 13818c2ecf20Sopenharmony_ci break; 13828c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_DSP_A: 13838c2ecf20Sopenharmony_ci reg_val |= RT5651_I2S_DF_PCM_A; 13848c2ecf20Sopenharmony_ci break; 13858c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_DSP_B: 13868c2ecf20Sopenharmony_ci reg_val |= RT5651_I2S_DF_PCM_B; 13878c2ecf20Sopenharmony_ci break; 13888c2ecf20Sopenharmony_ci default: 13898c2ecf20Sopenharmony_ci return -EINVAL; 13908c2ecf20Sopenharmony_ci } 13918c2ecf20Sopenharmony_ci 13928c2ecf20Sopenharmony_ci switch (dai->id) { 13938c2ecf20Sopenharmony_ci case RT5651_AIF1: 13948c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_I2S1_SDP, 13958c2ecf20Sopenharmony_ci RT5651_I2S_MS_MASK | RT5651_I2S_BP_MASK | 13968c2ecf20Sopenharmony_ci RT5651_I2S_DF_MASK, reg_val); 13978c2ecf20Sopenharmony_ci break; 13988c2ecf20Sopenharmony_ci case RT5651_AIF2: 13998c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_I2S2_SDP, 14008c2ecf20Sopenharmony_ci RT5651_I2S_MS_MASK | RT5651_I2S_BP_MASK | 14018c2ecf20Sopenharmony_ci RT5651_I2S_DF_MASK, reg_val); 14028c2ecf20Sopenharmony_ci break; 14038c2ecf20Sopenharmony_ci default: 14048c2ecf20Sopenharmony_ci dev_err(component->dev, "Wrong dai->id: %d\n", dai->id); 14058c2ecf20Sopenharmony_ci return -EINVAL; 14068c2ecf20Sopenharmony_ci } 14078c2ecf20Sopenharmony_ci return 0; 14088c2ecf20Sopenharmony_ci} 14098c2ecf20Sopenharmony_ci 14108c2ecf20Sopenharmony_cistatic int rt5651_set_dai_sysclk(struct snd_soc_dai *dai, 14118c2ecf20Sopenharmony_ci int clk_id, unsigned int freq, int dir) 14128c2ecf20Sopenharmony_ci{ 14138c2ecf20Sopenharmony_ci struct snd_soc_component *component = dai->component; 14148c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 14158c2ecf20Sopenharmony_ci unsigned int reg_val = 0; 14168c2ecf20Sopenharmony_ci unsigned int pll_bit = 0; 14178c2ecf20Sopenharmony_ci 14188c2ecf20Sopenharmony_ci if (freq == rt5651->sysclk && clk_id == rt5651->sysclk_src) 14198c2ecf20Sopenharmony_ci return 0; 14208c2ecf20Sopenharmony_ci 14218c2ecf20Sopenharmony_ci switch (clk_id) { 14228c2ecf20Sopenharmony_ci case RT5651_SCLK_S_MCLK: 14238c2ecf20Sopenharmony_ci reg_val |= RT5651_SCLK_SRC_MCLK; 14248c2ecf20Sopenharmony_ci break; 14258c2ecf20Sopenharmony_ci case RT5651_SCLK_S_PLL1: 14268c2ecf20Sopenharmony_ci reg_val |= RT5651_SCLK_SRC_PLL1; 14278c2ecf20Sopenharmony_ci pll_bit |= RT5651_PWR_PLL; 14288c2ecf20Sopenharmony_ci break; 14298c2ecf20Sopenharmony_ci case RT5651_SCLK_S_RCCLK: 14308c2ecf20Sopenharmony_ci reg_val |= RT5651_SCLK_SRC_RCCLK; 14318c2ecf20Sopenharmony_ci break; 14328c2ecf20Sopenharmony_ci default: 14338c2ecf20Sopenharmony_ci dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); 14348c2ecf20Sopenharmony_ci return -EINVAL; 14358c2ecf20Sopenharmony_ci } 14368c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, 14378c2ecf20Sopenharmony_ci RT5651_PWR_PLL, pll_bit); 14388c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_GLB_CLK, 14398c2ecf20Sopenharmony_ci RT5651_SCLK_SRC_MASK, reg_val); 14408c2ecf20Sopenharmony_ci rt5651->sysclk = freq; 14418c2ecf20Sopenharmony_ci rt5651->sysclk_src = clk_id; 14428c2ecf20Sopenharmony_ci 14438c2ecf20Sopenharmony_ci dev_dbg(dai->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id); 14448c2ecf20Sopenharmony_ci 14458c2ecf20Sopenharmony_ci return 0; 14468c2ecf20Sopenharmony_ci} 14478c2ecf20Sopenharmony_ci 14488c2ecf20Sopenharmony_cistatic int rt5651_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, 14498c2ecf20Sopenharmony_ci unsigned int freq_in, unsigned int freq_out) 14508c2ecf20Sopenharmony_ci{ 14518c2ecf20Sopenharmony_ci struct snd_soc_component *component = dai->component; 14528c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 14538c2ecf20Sopenharmony_ci struct rl6231_pll_code pll_code; 14548c2ecf20Sopenharmony_ci int ret; 14558c2ecf20Sopenharmony_ci 14568c2ecf20Sopenharmony_ci if (source == rt5651->pll_src && freq_in == rt5651->pll_in && 14578c2ecf20Sopenharmony_ci freq_out == rt5651->pll_out) 14588c2ecf20Sopenharmony_ci return 0; 14598c2ecf20Sopenharmony_ci 14608c2ecf20Sopenharmony_ci if (!freq_in || !freq_out) { 14618c2ecf20Sopenharmony_ci dev_dbg(component->dev, "PLL disabled\n"); 14628c2ecf20Sopenharmony_ci 14638c2ecf20Sopenharmony_ci rt5651->pll_in = 0; 14648c2ecf20Sopenharmony_ci rt5651->pll_out = 0; 14658c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_GLB_CLK, 14668c2ecf20Sopenharmony_ci RT5651_SCLK_SRC_MASK, RT5651_SCLK_SRC_MCLK); 14678c2ecf20Sopenharmony_ci return 0; 14688c2ecf20Sopenharmony_ci } 14698c2ecf20Sopenharmony_ci 14708c2ecf20Sopenharmony_ci switch (source) { 14718c2ecf20Sopenharmony_ci case RT5651_PLL1_S_MCLK: 14728c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_GLB_CLK, 14738c2ecf20Sopenharmony_ci RT5651_PLL1_SRC_MASK, RT5651_PLL1_SRC_MCLK); 14748c2ecf20Sopenharmony_ci break; 14758c2ecf20Sopenharmony_ci case RT5651_PLL1_S_BCLK1: 14768c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_GLB_CLK, 14778c2ecf20Sopenharmony_ci RT5651_PLL1_SRC_MASK, RT5651_PLL1_SRC_BCLK1); 14788c2ecf20Sopenharmony_ci break; 14798c2ecf20Sopenharmony_ci case RT5651_PLL1_S_BCLK2: 14808c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_GLB_CLK, 14818c2ecf20Sopenharmony_ci RT5651_PLL1_SRC_MASK, RT5651_PLL1_SRC_BCLK2); 14828c2ecf20Sopenharmony_ci break; 14838c2ecf20Sopenharmony_ci default: 14848c2ecf20Sopenharmony_ci dev_err(component->dev, "Unknown PLL source %d\n", source); 14858c2ecf20Sopenharmony_ci return -EINVAL; 14868c2ecf20Sopenharmony_ci } 14878c2ecf20Sopenharmony_ci 14888c2ecf20Sopenharmony_ci ret = rl6231_pll_calc(freq_in, freq_out, &pll_code); 14898c2ecf20Sopenharmony_ci if (ret < 0) { 14908c2ecf20Sopenharmony_ci dev_err(component->dev, "Unsupport input clock %d\n", freq_in); 14918c2ecf20Sopenharmony_ci return ret; 14928c2ecf20Sopenharmony_ci } 14938c2ecf20Sopenharmony_ci 14948c2ecf20Sopenharmony_ci dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", 14958c2ecf20Sopenharmony_ci pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code), 14968c2ecf20Sopenharmony_ci pll_code.n_code, pll_code.k_code); 14978c2ecf20Sopenharmony_ci 14988c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT5651_PLL_CTRL1, 14998c2ecf20Sopenharmony_ci pll_code.n_code << RT5651_PLL_N_SFT | pll_code.k_code); 15008c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT5651_PLL_CTRL2, 15018c2ecf20Sopenharmony_ci (pll_code.m_bp ? 0 : pll_code.m_code) << RT5651_PLL_M_SFT | 15028c2ecf20Sopenharmony_ci pll_code.m_bp << RT5651_PLL_M_BP_SFT); 15038c2ecf20Sopenharmony_ci 15048c2ecf20Sopenharmony_ci rt5651->pll_in = freq_in; 15058c2ecf20Sopenharmony_ci rt5651->pll_out = freq_out; 15068c2ecf20Sopenharmony_ci rt5651->pll_src = source; 15078c2ecf20Sopenharmony_ci 15088c2ecf20Sopenharmony_ci return 0; 15098c2ecf20Sopenharmony_ci} 15108c2ecf20Sopenharmony_ci 15118c2ecf20Sopenharmony_cistatic int rt5651_set_bias_level(struct snd_soc_component *component, 15128c2ecf20Sopenharmony_ci enum snd_soc_bias_level level) 15138c2ecf20Sopenharmony_ci{ 15148c2ecf20Sopenharmony_ci switch (level) { 15158c2ecf20Sopenharmony_ci case SND_SOC_BIAS_PREPARE: 15168c2ecf20Sopenharmony_ci if (SND_SOC_BIAS_STANDBY == snd_soc_component_get_bias_level(component)) { 15178c2ecf20Sopenharmony_ci if (snd_soc_component_read(component, RT5651_PLL_MODE_1) & 0x9200) 15188c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_D_MISC, 15198c2ecf20Sopenharmony_ci 0xc00, 0xc00); 15208c2ecf20Sopenharmony_ci } 15218c2ecf20Sopenharmony_ci break; 15228c2ecf20Sopenharmony_ci case SND_SOC_BIAS_STANDBY: 15238c2ecf20Sopenharmony_ci if (SND_SOC_BIAS_OFF == snd_soc_component_get_bias_level(component)) { 15248c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_PWR_ANLG1, 15258c2ecf20Sopenharmony_ci RT5651_PWR_VREF1 | RT5651_PWR_MB | 15268c2ecf20Sopenharmony_ci RT5651_PWR_BG | RT5651_PWR_VREF2, 15278c2ecf20Sopenharmony_ci RT5651_PWR_VREF1 | RT5651_PWR_MB | 15288c2ecf20Sopenharmony_ci RT5651_PWR_BG | RT5651_PWR_VREF2); 15298c2ecf20Sopenharmony_ci usleep_range(10000, 15000); 15308c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_PWR_ANLG1, 15318c2ecf20Sopenharmony_ci RT5651_PWR_FV1 | RT5651_PWR_FV2, 15328c2ecf20Sopenharmony_ci RT5651_PWR_FV1 | RT5651_PWR_FV2); 15338c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_D_MISC, 0x1, 0x1); 15348c2ecf20Sopenharmony_ci } 15358c2ecf20Sopenharmony_ci break; 15368c2ecf20Sopenharmony_ci 15378c2ecf20Sopenharmony_ci case SND_SOC_BIAS_OFF: 15388c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT5651_D_MISC, 0x0010); 15398c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT5651_PWR_DIG1, 0x0000); 15408c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT5651_PWR_DIG2, 0x0000); 15418c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT5651_PWR_VOL, 0x0000); 15428c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT5651_PWR_MIXER, 0x0000); 15438c2ecf20Sopenharmony_ci /* Do not touch the LDO voltage select bits on bias-off */ 15448c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_PWR_ANLG1, 15458c2ecf20Sopenharmony_ci ~RT5651_PWR_LDO_DVO_MASK, 0); 15468c2ecf20Sopenharmony_ci /* Leave PLL1 and jack-detect power as is, all others off */ 15478c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, 15488c2ecf20Sopenharmony_ci ~(RT5651_PWR_PLL | RT5651_PWR_JD_M), 0); 15498c2ecf20Sopenharmony_ci break; 15508c2ecf20Sopenharmony_ci 15518c2ecf20Sopenharmony_ci default: 15528c2ecf20Sopenharmony_ci break; 15538c2ecf20Sopenharmony_ci } 15548c2ecf20Sopenharmony_ci 15558c2ecf20Sopenharmony_ci return 0; 15568c2ecf20Sopenharmony_ci} 15578c2ecf20Sopenharmony_ci 15588c2ecf20Sopenharmony_cistatic void rt5651_enable_micbias1_for_ovcd(struct snd_soc_component *component) 15598c2ecf20Sopenharmony_ci{ 15608c2ecf20Sopenharmony_ci struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); 15618c2ecf20Sopenharmony_ci 15628c2ecf20Sopenharmony_ci snd_soc_dapm_mutex_lock(dapm); 15638c2ecf20Sopenharmony_ci snd_soc_dapm_force_enable_pin_unlocked(dapm, "LDO"); 15648c2ecf20Sopenharmony_ci snd_soc_dapm_force_enable_pin_unlocked(dapm, "micbias1"); 15658c2ecf20Sopenharmony_ci /* OVCD is unreliable when used with RCCLK as sysclk-source */ 15668c2ecf20Sopenharmony_ci snd_soc_dapm_force_enable_pin_unlocked(dapm, "Platform Clock"); 15678c2ecf20Sopenharmony_ci snd_soc_dapm_sync_unlocked(dapm); 15688c2ecf20Sopenharmony_ci snd_soc_dapm_mutex_unlock(dapm); 15698c2ecf20Sopenharmony_ci} 15708c2ecf20Sopenharmony_ci 15718c2ecf20Sopenharmony_cistatic void rt5651_disable_micbias1_for_ovcd(struct snd_soc_component *component) 15728c2ecf20Sopenharmony_ci{ 15738c2ecf20Sopenharmony_ci struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); 15748c2ecf20Sopenharmony_ci 15758c2ecf20Sopenharmony_ci snd_soc_dapm_mutex_lock(dapm); 15768c2ecf20Sopenharmony_ci snd_soc_dapm_disable_pin_unlocked(dapm, "Platform Clock"); 15778c2ecf20Sopenharmony_ci snd_soc_dapm_disable_pin_unlocked(dapm, "micbias1"); 15788c2ecf20Sopenharmony_ci snd_soc_dapm_disable_pin_unlocked(dapm, "LDO"); 15798c2ecf20Sopenharmony_ci snd_soc_dapm_sync_unlocked(dapm); 15808c2ecf20Sopenharmony_ci snd_soc_dapm_mutex_unlock(dapm); 15818c2ecf20Sopenharmony_ci} 15828c2ecf20Sopenharmony_ci 15838c2ecf20Sopenharmony_cistatic void rt5651_enable_micbias1_ovcd_irq(struct snd_soc_component *component) 15848c2ecf20Sopenharmony_ci{ 15858c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 15868c2ecf20Sopenharmony_ci 15878c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_IRQ_CTRL2, 15888c2ecf20Sopenharmony_ci RT5651_IRQ_MB1_OC_MASK, RT5651_IRQ_MB1_OC_NOR); 15898c2ecf20Sopenharmony_ci rt5651->ovcd_irq_enabled = true; 15908c2ecf20Sopenharmony_ci} 15918c2ecf20Sopenharmony_ci 15928c2ecf20Sopenharmony_cistatic void rt5651_disable_micbias1_ovcd_irq(struct snd_soc_component *component) 15938c2ecf20Sopenharmony_ci{ 15948c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 15958c2ecf20Sopenharmony_ci 15968c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_IRQ_CTRL2, 15978c2ecf20Sopenharmony_ci RT5651_IRQ_MB1_OC_MASK, RT5651_IRQ_MB1_OC_BP); 15988c2ecf20Sopenharmony_ci rt5651->ovcd_irq_enabled = false; 15998c2ecf20Sopenharmony_ci} 16008c2ecf20Sopenharmony_ci 16018c2ecf20Sopenharmony_cistatic void rt5651_clear_micbias1_ovcd(struct snd_soc_component *component) 16028c2ecf20Sopenharmony_ci{ 16038c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_IRQ_CTRL2, 16048c2ecf20Sopenharmony_ci RT5651_MB1_OC_CLR, 0); 16058c2ecf20Sopenharmony_ci} 16068c2ecf20Sopenharmony_ci 16078c2ecf20Sopenharmony_cistatic bool rt5651_micbias1_ovcd(struct snd_soc_component *component) 16088c2ecf20Sopenharmony_ci{ 16098c2ecf20Sopenharmony_ci int val; 16108c2ecf20Sopenharmony_ci 16118c2ecf20Sopenharmony_ci val = snd_soc_component_read(component, RT5651_IRQ_CTRL2); 16128c2ecf20Sopenharmony_ci dev_dbg(component->dev, "irq ctrl2 %#04x\n", val); 16138c2ecf20Sopenharmony_ci 16148c2ecf20Sopenharmony_ci return (val & RT5651_MB1_OC_CLR); 16158c2ecf20Sopenharmony_ci} 16168c2ecf20Sopenharmony_ci 16178c2ecf20Sopenharmony_cistatic bool rt5651_jack_inserted(struct snd_soc_component *component) 16188c2ecf20Sopenharmony_ci{ 16198c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 16208c2ecf20Sopenharmony_ci int val; 16218c2ecf20Sopenharmony_ci 16228c2ecf20Sopenharmony_ci if (rt5651->gpiod_hp_det) { 16238c2ecf20Sopenharmony_ci val = gpiod_get_value_cansleep(rt5651->gpiod_hp_det); 16248c2ecf20Sopenharmony_ci dev_dbg(component->dev, "jack-detect gpio %d\n", val); 16258c2ecf20Sopenharmony_ci return val; 16268c2ecf20Sopenharmony_ci } 16278c2ecf20Sopenharmony_ci 16288c2ecf20Sopenharmony_ci val = snd_soc_component_read(component, RT5651_INT_IRQ_ST); 16298c2ecf20Sopenharmony_ci dev_dbg(component->dev, "irq status %#04x\n", val); 16308c2ecf20Sopenharmony_ci 16318c2ecf20Sopenharmony_ci switch (rt5651->jd_src) { 16328c2ecf20Sopenharmony_ci case RT5651_JD1_1: 16338c2ecf20Sopenharmony_ci val &= 0x1000; 16348c2ecf20Sopenharmony_ci break; 16358c2ecf20Sopenharmony_ci case RT5651_JD1_2: 16368c2ecf20Sopenharmony_ci val &= 0x2000; 16378c2ecf20Sopenharmony_ci break; 16388c2ecf20Sopenharmony_ci case RT5651_JD2: 16398c2ecf20Sopenharmony_ci val &= 0x4000; 16408c2ecf20Sopenharmony_ci break; 16418c2ecf20Sopenharmony_ci default: 16428c2ecf20Sopenharmony_ci break; 16438c2ecf20Sopenharmony_ci } 16448c2ecf20Sopenharmony_ci 16458c2ecf20Sopenharmony_ci if (rt5651->jd_active_high) 16468c2ecf20Sopenharmony_ci return val != 0; 16478c2ecf20Sopenharmony_ci else 16488c2ecf20Sopenharmony_ci return val == 0; 16498c2ecf20Sopenharmony_ci} 16508c2ecf20Sopenharmony_ci 16518c2ecf20Sopenharmony_ci/* Jack detect and button-press timings */ 16528c2ecf20Sopenharmony_ci#define JACK_SETTLE_TIME 100 /* milli seconds */ 16538c2ecf20Sopenharmony_ci#define JACK_DETECT_COUNT 5 16548c2ecf20Sopenharmony_ci#define JACK_DETECT_MAXCOUNT 20 /* Aprox. 2 seconds worth of tries */ 16558c2ecf20Sopenharmony_ci#define JACK_UNPLUG_TIME 80 /* milli seconds */ 16568c2ecf20Sopenharmony_ci#define BP_POLL_TIME 10 /* milli seconds */ 16578c2ecf20Sopenharmony_ci#define BP_POLL_MAXCOUNT 200 /* assume something is wrong after this */ 16588c2ecf20Sopenharmony_ci#define BP_THRESHOLD 3 16598c2ecf20Sopenharmony_ci 16608c2ecf20Sopenharmony_cistatic void rt5651_start_button_press_work(struct snd_soc_component *component) 16618c2ecf20Sopenharmony_ci{ 16628c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 16638c2ecf20Sopenharmony_ci 16648c2ecf20Sopenharmony_ci rt5651->poll_count = 0; 16658c2ecf20Sopenharmony_ci rt5651->press_count = 0; 16668c2ecf20Sopenharmony_ci rt5651->release_count = 0; 16678c2ecf20Sopenharmony_ci rt5651->pressed = false; 16688c2ecf20Sopenharmony_ci rt5651->press_reported = false; 16698c2ecf20Sopenharmony_ci rt5651_clear_micbias1_ovcd(component); 16708c2ecf20Sopenharmony_ci schedule_delayed_work(&rt5651->bp_work, msecs_to_jiffies(BP_POLL_TIME)); 16718c2ecf20Sopenharmony_ci} 16728c2ecf20Sopenharmony_ci 16738c2ecf20Sopenharmony_cistatic void rt5651_button_press_work(struct work_struct *work) 16748c2ecf20Sopenharmony_ci{ 16758c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = 16768c2ecf20Sopenharmony_ci container_of(work, struct rt5651_priv, bp_work.work); 16778c2ecf20Sopenharmony_ci struct snd_soc_component *component = rt5651->component; 16788c2ecf20Sopenharmony_ci 16798c2ecf20Sopenharmony_ci /* Check the jack was not removed underneath us */ 16808c2ecf20Sopenharmony_ci if (!rt5651_jack_inserted(component)) 16818c2ecf20Sopenharmony_ci return; 16828c2ecf20Sopenharmony_ci 16838c2ecf20Sopenharmony_ci if (rt5651_micbias1_ovcd(component)) { 16848c2ecf20Sopenharmony_ci rt5651->release_count = 0; 16858c2ecf20Sopenharmony_ci rt5651->press_count++; 16868c2ecf20Sopenharmony_ci /* Remember till after JACK_UNPLUG_TIME wait */ 16878c2ecf20Sopenharmony_ci if (rt5651->press_count >= BP_THRESHOLD) 16888c2ecf20Sopenharmony_ci rt5651->pressed = true; 16898c2ecf20Sopenharmony_ci rt5651_clear_micbias1_ovcd(component); 16908c2ecf20Sopenharmony_ci } else { 16918c2ecf20Sopenharmony_ci rt5651->press_count = 0; 16928c2ecf20Sopenharmony_ci rt5651->release_count++; 16938c2ecf20Sopenharmony_ci } 16948c2ecf20Sopenharmony_ci 16958c2ecf20Sopenharmony_ci /* 16968c2ecf20Sopenharmony_ci * The pins get temporarily shorted on jack unplug, so we poll for 16978c2ecf20Sopenharmony_ci * at least JACK_UNPLUG_TIME milli-seconds before reporting a press. 16988c2ecf20Sopenharmony_ci */ 16998c2ecf20Sopenharmony_ci rt5651->poll_count++; 17008c2ecf20Sopenharmony_ci if (rt5651->poll_count < (JACK_UNPLUG_TIME / BP_POLL_TIME)) { 17018c2ecf20Sopenharmony_ci schedule_delayed_work(&rt5651->bp_work, 17028c2ecf20Sopenharmony_ci msecs_to_jiffies(BP_POLL_TIME)); 17038c2ecf20Sopenharmony_ci return; 17048c2ecf20Sopenharmony_ci } 17058c2ecf20Sopenharmony_ci 17068c2ecf20Sopenharmony_ci if (rt5651->pressed && !rt5651->press_reported) { 17078c2ecf20Sopenharmony_ci dev_dbg(component->dev, "headset button press\n"); 17088c2ecf20Sopenharmony_ci snd_soc_jack_report(rt5651->hp_jack, SND_JACK_BTN_0, 17098c2ecf20Sopenharmony_ci SND_JACK_BTN_0); 17108c2ecf20Sopenharmony_ci rt5651->press_reported = true; 17118c2ecf20Sopenharmony_ci } 17128c2ecf20Sopenharmony_ci 17138c2ecf20Sopenharmony_ci if (rt5651->release_count >= BP_THRESHOLD) { 17148c2ecf20Sopenharmony_ci if (rt5651->press_reported) { 17158c2ecf20Sopenharmony_ci dev_dbg(component->dev, "headset button release\n"); 17168c2ecf20Sopenharmony_ci snd_soc_jack_report(rt5651->hp_jack, 0, SND_JACK_BTN_0); 17178c2ecf20Sopenharmony_ci } 17188c2ecf20Sopenharmony_ci /* Re-enable OVCD IRQ to detect next press */ 17198c2ecf20Sopenharmony_ci rt5651_enable_micbias1_ovcd_irq(component); 17208c2ecf20Sopenharmony_ci return; /* Stop polling */ 17218c2ecf20Sopenharmony_ci } 17228c2ecf20Sopenharmony_ci 17238c2ecf20Sopenharmony_ci schedule_delayed_work(&rt5651->bp_work, msecs_to_jiffies(BP_POLL_TIME)); 17248c2ecf20Sopenharmony_ci} 17258c2ecf20Sopenharmony_ci 17268c2ecf20Sopenharmony_cistatic int rt5651_detect_headset(struct snd_soc_component *component) 17278c2ecf20Sopenharmony_ci{ 17288c2ecf20Sopenharmony_ci int i, headset_count = 0, headphone_count = 0; 17298c2ecf20Sopenharmony_ci 17308c2ecf20Sopenharmony_ci /* 17318c2ecf20Sopenharmony_ci * We get the insertion event before the jack is fully inserted at which 17328c2ecf20Sopenharmony_ci * point the second ring on a TRRS connector may short the 2nd ring and 17338c2ecf20Sopenharmony_ci * sleeve contacts, also the overcurrent detection is not entirely 17348c2ecf20Sopenharmony_ci * reliable. So we try several times with a wait in between until we 17358c2ecf20Sopenharmony_ci * detect the same type JACK_DETECT_COUNT times in a row. 17368c2ecf20Sopenharmony_ci */ 17378c2ecf20Sopenharmony_ci for (i = 0; i < JACK_DETECT_MAXCOUNT; i++) { 17388c2ecf20Sopenharmony_ci /* Clear any previous over-current status flag */ 17398c2ecf20Sopenharmony_ci rt5651_clear_micbias1_ovcd(component); 17408c2ecf20Sopenharmony_ci 17418c2ecf20Sopenharmony_ci msleep(JACK_SETTLE_TIME); 17428c2ecf20Sopenharmony_ci 17438c2ecf20Sopenharmony_ci /* Check the jack is still connected before checking ovcd */ 17448c2ecf20Sopenharmony_ci if (!rt5651_jack_inserted(component)) 17458c2ecf20Sopenharmony_ci return 0; 17468c2ecf20Sopenharmony_ci 17478c2ecf20Sopenharmony_ci if (rt5651_micbias1_ovcd(component)) { 17488c2ecf20Sopenharmony_ci /* 17498c2ecf20Sopenharmony_ci * Over current detected, there is a short between the 17508c2ecf20Sopenharmony_ci * 2nd ring contact and the ground, so a TRS connector 17518c2ecf20Sopenharmony_ci * without a mic contact and thus plain headphones. 17528c2ecf20Sopenharmony_ci */ 17538c2ecf20Sopenharmony_ci dev_dbg(component->dev, "mic-gnd shorted\n"); 17548c2ecf20Sopenharmony_ci headset_count = 0; 17558c2ecf20Sopenharmony_ci headphone_count++; 17568c2ecf20Sopenharmony_ci if (headphone_count == JACK_DETECT_COUNT) 17578c2ecf20Sopenharmony_ci return SND_JACK_HEADPHONE; 17588c2ecf20Sopenharmony_ci } else { 17598c2ecf20Sopenharmony_ci dev_dbg(component->dev, "mic-gnd open\n"); 17608c2ecf20Sopenharmony_ci headphone_count = 0; 17618c2ecf20Sopenharmony_ci headset_count++; 17628c2ecf20Sopenharmony_ci if (headset_count == JACK_DETECT_COUNT) 17638c2ecf20Sopenharmony_ci return SND_JACK_HEADSET; 17648c2ecf20Sopenharmony_ci } 17658c2ecf20Sopenharmony_ci } 17668c2ecf20Sopenharmony_ci 17678c2ecf20Sopenharmony_ci dev_err(component->dev, "Error detecting headset vs headphones, bad contact?, assuming headphones\n"); 17688c2ecf20Sopenharmony_ci return SND_JACK_HEADPHONE; 17698c2ecf20Sopenharmony_ci} 17708c2ecf20Sopenharmony_ci 17718c2ecf20Sopenharmony_cistatic bool rt5651_support_button_press(struct rt5651_priv *rt5651) 17728c2ecf20Sopenharmony_ci{ 17738c2ecf20Sopenharmony_ci if (!rt5651->hp_jack) 17748c2ecf20Sopenharmony_ci return false; 17758c2ecf20Sopenharmony_ci 17768c2ecf20Sopenharmony_ci /* Button press support only works with internal jack-detection */ 17778c2ecf20Sopenharmony_ci return (rt5651->hp_jack->status & SND_JACK_MICROPHONE) && 17788c2ecf20Sopenharmony_ci rt5651->gpiod_hp_det == NULL; 17798c2ecf20Sopenharmony_ci} 17808c2ecf20Sopenharmony_ci 17818c2ecf20Sopenharmony_cistatic void rt5651_jack_detect_work(struct work_struct *work) 17828c2ecf20Sopenharmony_ci{ 17838c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = 17848c2ecf20Sopenharmony_ci container_of(work, struct rt5651_priv, jack_detect_work); 17858c2ecf20Sopenharmony_ci struct snd_soc_component *component = rt5651->component; 17868c2ecf20Sopenharmony_ci int report = 0; 17878c2ecf20Sopenharmony_ci 17888c2ecf20Sopenharmony_ci if (!rt5651_jack_inserted(component)) { 17898c2ecf20Sopenharmony_ci /* Jack removed, or spurious IRQ? */ 17908c2ecf20Sopenharmony_ci if (rt5651->hp_jack->status & SND_JACK_HEADPHONE) { 17918c2ecf20Sopenharmony_ci if (rt5651->hp_jack->status & SND_JACK_MICROPHONE) { 17928c2ecf20Sopenharmony_ci cancel_delayed_work_sync(&rt5651->bp_work); 17938c2ecf20Sopenharmony_ci rt5651_disable_micbias1_ovcd_irq(component); 17948c2ecf20Sopenharmony_ci rt5651_disable_micbias1_for_ovcd(component); 17958c2ecf20Sopenharmony_ci } 17968c2ecf20Sopenharmony_ci snd_soc_jack_report(rt5651->hp_jack, 0, 17978c2ecf20Sopenharmony_ci SND_JACK_HEADSET | SND_JACK_BTN_0); 17988c2ecf20Sopenharmony_ci dev_dbg(component->dev, "jack unplugged\n"); 17998c2ecf20Sopenharmony_ci } 18008c2ecf20Sopenharmony_ci } else if (!(rt5651->hp_jack->status & SND_JACK_HEADPHONE)) { 18018c2ecf20Sopenharmony_ci /* Jack inserted */ 18028c2ecf20Sopenharmony_ci WARN_ON(rt5651->ovcd_irq_enabled); 18038c2ecf20Sopenharmony_ci rt5651_enable_micbias1_for_ovcd(component); 18048c2ecf20Sopenharmony_ci report = rt5651_detect_headset(component); 18058c2ecf20Sopenharmony_ci dev_dbg(component->dev, "detect report %#02x\n", report); 18068c2ecf20Sopenharmony_ci snd_soc_jack_report(rt5651->hp_jack, report, SND_JACK_HEADSET); 18078c2ecf20Sopenharmony_ci if (rt5651_support_button_press(rt5651)) { 18088c2ecf20Sopenharmony_ci /* Enable ovcd IRQ for button press detect. */ 18098c2ecf20Sopenharmony_ci rt5651_enable_micbias1_ovcd_irq(component); 18108c2ecf20Sopenharmony_ci } else { 18118c2ecf20Sopenharmony_ci /* No more need for overcurrent detect. */ 18128c2ecf20Sopenharmony_ci rt5651_disable_micbias1_for_ovcd(component); 18138c2ecf20Sopenharmony_ci } 18148c2ecf20Sopenharmony_ci } else if (rt5651->ovcd_irq_enabled && rt5651_micbias1_ovcd(component)) { 18158c2ecf20Sopenharmony_ci dev_dbg(component->dev, "OVCD IRQ\n"); 18168c2ecf20Sopenharmony_ci 18178c2ecf20Sopenharmony_ci /* 18188c2ecf20Sopenharmony_ci * The ovcd IRQ keeps firing while the button is pressed, so 18198c2ecf20Sopenharmony_ci * we disable it and start polling the button until released. 18208c2ecf20Sopenharmony_ci * 18218c2ecf20Sopenharmony_ci * The disable will make the IRQ pin 0 again and since we get 18228c2ecf20Sopenharmony_ci * IRQs on both edges (so as to detect both jack plugin and 18238c2ecf20Sopenharmony_ci * unplug) this means we will immediately get another IRQ. 18248c2ecf20Sopenharmony_ci * The ovcd_irq_enabled check above makes the 2ND IRQ a NOP. 18258c2ecf20Sopenharmony_ci */ 18268c2ecf20Sopenharmony_ci rt5651_disable_micbias1_ovcd_irq(component); 18278c2ecf20Sopenharmony_ci rt5651_start_button_press_work(component); 18288c2ecf20Sopenharmony_ci 18298c2ecf20Sopenharmony_ci /* 18308c2ecf20Sopenharmony_ci * If the jack-detect IRQ flag goes high (unplug) after our 18318c2ecf20Sopenharmony_ci * above rt5651_jack_inserted() check and before we have 18328c2ecf20Sopenharmony_ci * disabled the OVCD IRQ, the IRQ pin will stay high and as 18338c2ecf20Sopenharmony_ci * we react to edges, we miss the unplug event -> recheck. 18348c2ecf20Sopenharmony_ci */ 18358c2ecf20Sopenharmony_ci queue_work(system_long_wq, &rt5651->jack_detect_work); 18368c2ecf20Sopenharmony_ci } 18378c2ecf20Sopenharmony_ci} 18388c2ecf20Sopenharmony_ci 18398c2ecf20Sopenharmony_cistatic irqreturn_t rt5651_irq(int irq, void *data) 18408c2ecf20Sopenharmony_ci{ 18418c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = data; 18428c2ecf20Sopenharmony_ci 18438c2ecf20Sopenharmony_ci queue_work(system_power_efficient_wq, &rt5651->jack_detect_work); 18448c2ecf20Sopenharmony_ci 18458c2ecf20Sopenharmony_ci return IRQ_HANDLED; 18468c2ecf20Sopenharmony_ci} 18478c2ecf20Sopenharmony_ci 18488c2ecf20Sopenharmony_cistatic void rt5651_cancel_work(void *data) 18498c2ecf20Sopenharmony_ci{ 18508c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = data; 18518c2ecf20Sopenharmony_ci 18528c2ecf20Sopenharmony_ci cancel_work_sync(&rt5651->jack_detect_work); 18538c2ecf20Sopenharmony_ci cancel_delayed_work_sync(&rt5651->bp_work); 18548c2ecf20Sopenharmony_ci} 18558c2ecf20Sopenharmony_ci 18568c2ecf20Sopenharmony_cistatic void rt5651_enable_jack_detect(struct snd_soc_component *component, 18578c2ecf20Sopenharmony_ci struct snd_soc_jack *hp_jack, 18588c2ecf20Sopenharmony_ci struct gpio_desc *gpiod_hp_det) 18598c2ecf20Sopenharmony_ci{ 18608c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 18618c2ecf20Sopenharmony_ci bool using_internal_jack_detect = true; 18628c2ecf20Sopenharmony_ci 18638c2ecf20Sopenharmony_ci /* Select jack detect source */ 18648c2ecf20Sopenharmony_ci switch (rt5651->jd_src) { 18658c2ecf20Sopenharmony_ci case RT5651_JD_NULL: 18668c2ecf20Sopenharmony_ci rt5651->gpiod_hp_det = gpiod_hp_det; 18678c2ecf20Sopenharmony_ci if (!rt5651->gpiod_hp_det) 18688c2ecf20Sopenharmony_ci return; /* No jack detect */ 18698c2ecf20Sopenharmony_ci using_internal_jack_detect = false; 18708c2ecf20Sopenharmony_ci break; 18718c2ecf20Sopenharmony_ci case RT5651_JD1_1: 18728c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_JD_CTRL2, 18738c2ecf20Sopenharmony_ci RT5651_JD_TRG_SEL_MASK, RT5651_JD_TRG_SEL_JD1_1); 18748c2ecf20Sopenharmony_ci /* active-low is normal, set inv flag for active-high */ 18758c2ecf20Sopenharmony_ci if (rt5651->jd_active_high) 18768c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 18778c2ecf20Sopenharmony_ci RT5651_IRQ_CTRL1, 18788c2ecf20Sopenharmony_ci RT5651_JD1_1_IRQ_EN | RT5651_JD1_1_INV, 18798c2ecf20Sopenharmony_ci RT5651_JD1_1_IRQ_EN | RT5651_JD1_1_INV); 18808c2ecf20Sopenharmony_ci else 18818c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 18828c2ecf20Sopenharmony_ci RT5651_IRQ_CTRL1, 18838c2ecf20Sopenharmony_ci RT5651_JD1_1_IRQ_EN | RT5651_JD1_1_INV, 18848c2ecf20Sopenharmony_ci RT5651_JD1_1_IRQ_EN); 18858c2ecf20Sopenharmony_ci break; 18868c2ecf20Sopenharmony_ci case RT5651_JD1_2: 18878c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_JD_CTRL2, 18888c2ecf20Sopenharmony_ci RT5651_JD_TRG_SEL_MASK, RT5651_JD_TRG_SEL_JD1_2); 18898c2ecf20Sopenharmony_ci /* active-low is normal, set inv flag for active-high */ 18908c2ecf20Sopenharmony_ci if (rt5651->jd_active_high) 18918c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 18928c2ecf20Sopenharmony_ci RT5651_IRQ_CTRL1, 18938c2ecf20Sopenharmony_ci RT5651_JD1_2_IRQ_EN | RT5651_JD1_2_INV, 18948c2ecf20Sopenharmony_ci RT5651_JD1_2_IRQ_EN | RT5651_JD1_2_INV); 18958c2ecf20Sopenharmony_ci else 18968c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 18978c2ecf20Sopenharmony_ci RT5651_IRQ_CTRL1, 18988c2ecf20Sopenharmony_ci RT5651_JD1_2_IRQ_EN | RT5651_JD1_2_INV, 18998c2ecf20Sopenharmony_ci RT5651_JD1_2_IRQ_EN); 19008c2ecf20Sopenharmony_ci break; 19018c2ecf20Sopenharmony_ci case RT5651_JD2: 19028c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_JD_CTRL2, 19038c2ecf20Sopenharmony_ci RT5651_JD_TRG_SEL_MASK, RT5651_JD_TRG_SEL_JD2); 19048c2ecf20Sopenharmony_ci /* active-low is normal, set inv flag for active-high */ 19058c2ecf20Sopenharmony_ci if (rt5651->jd_active_high) 19068c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 19078c2ecf20Sopenharmony_ci RT5651_IRQ_CTRL1, 19088c2ecf20Sopenharmony_ci RT5651_JD2_IRQ_EN | RT5651_JD2_INV, 19098c2ecf20Sopenharmony_ci RT5651_JD2_IRQ_EN | RT5651_JD2_INV); 19108c2ecf20Sopenharmony_ci else 19118c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 19128c2ecf20Sopenharmony_ci RT5651_IRQ_CTRL1, 19138c2ecf20Sopenharmony_ci RT5651_JD2_IRQ_EN | RT5651_JD2_INV, 19148c2ecf20Sopenharmony_ci RT5651_JD2_IRQ_EN); 19158c2ecf20Sopenharmony_ci break; 19168c2ecf20Sopenharmony_ci default: 19178c2ecf20Sopenharmony_ci dev_err(component->dev, "Currently only JD1_1 / JD1_2 / JD2 are supported\n"); 19188c2ecf20Sopenharmony_ci return; 19198c2ecf20Sopenharmony_ci } 19208c2ecf20Sopenharmony_ci 19218c2ecf20Sopenharmony_ci if (using_internal_jack_detect) { 19228c2ecf20Sopenharmony_ci /* IRQ output on GPIO1 */ 19238c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_GPIO_CTRL1, 19248c2ecf20Sopenharmony_ci RT5651_GP1_PIN_MASK, RT5651_GP1_PIN_IRQ); 19258c2ecf20Sopenharmony_ci 19268c2ecf20Sopenharmony_ci /* Enable jack detect power */ 19278c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, 19288c2ecf20Sopenharmony_ci RT5651_PWR_JD_M, RT5651_PWR_JD_M); 19298c2ecf20Sopenharmony_ci } 19308c2ecf20Sopenharmony_ci 19318c2ecf20Sopenharmony_ci /* Set OVCD threshold current and scale-factor */ 19328c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT5651_PR_BASE + RT5651_BIAS_CUR4, 19338c2ecf20Sopenharmony_ci 0xa800 | rt5651->ovcd_sf); 19348c2ecf20Sopenharmony_ci 19358c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_MICBIAS, 19368c2ecf20Sopenharmony_ci RT5651_MIC1_OVCD_MASK | 19378c2ecf20Sopenharmony_ci RT5651_MIC1_OVTH_MASK | 19388c2ecf20Sopenharmony_ci RT5651_PWR_CLK12M_MASK | 19398c2ecf20Sopenharmony_ci RT5651_PWR_MB_MASK, 19408c2ecf20Sopenharmony_ci RT5651_MIC1_OVCD_EN | 19418c2ecf20Sopenharmony_ci rt5651->ovcd_th | 19428c2ecf20Sopenharmony_ci RT5651_PWR_MB_PU | 19438c2ecf20Sopenharmony_ci RT5651_PWR_CLK12M_PU); 19448c2ecf20Sopenharmony_ci 19458c2ecf20Sopenharmony_ci /* 19468c2ecf20Sopenharmony_ci * The over-current-detect is only reliable in detecting the absence 19478c2ecf20Sopenharmony_ci * of over-current, when the mic-contact in the jack is short-circuited, 19488c2ecf20Sopenharmony_ci * the hardware periodically retries if it can apply the bias-current 19498c2ecf20Sopenharmony_ci * leading to the ovcd status flip-flopping 1-0-1 with it being 0 about 19508c2ecf20Sopenharmony_ci * 10% of the time, as we poll the ovcd status bit we might hit that 19518c2ecf20Sopenharmony_ci * 10%, so we enable sticky mode and when checking OVCD we clear the 19528c2ecf20Sopenharmony_ci * status, msleep() a bit and then check to get a reliable reading. 19538c2ecf20Sopenharmony_ci */ 19548c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_IRQ_CTRL2, 19558c2ecf20Sopenharmony_ci RT5651_MB1_OC_STKY_MASK, RT5651_MB1_OC_STKY_EN); 19568c2ecf20Sopenharmony_ci 19578c2ecf20Sopenharmony_ci rt5651->hp_jack = hp_jack; 19588c2ecf20Sopenharmony_ci if (rt5651_support_button_press(rt5651)) { 19598c2ecf20Sopenharmony_ci rt5651_enable_micbias1_for_ovcd(component); 19608c2ecf20Sopenharmony_ci rt5651_enable_micbias1_ovcd_irq(component); 19618c2ecf20Sopenharmony_ci } 19628c2ecf20Sopenharmony_ci 19638c2ecf20Sopenharmony_ci enable_irq(rt5651->irq); 19648c2ecf20Sopenharmony_ci /* sync initial jack state */ 19658c2ecf20Sopenharmony_ci queue_work(system_power_efficient_wq, &rt5651->jack_detect_work); 19668c2ecf20Sopenharmony_ci} 19678c2ecf20Sopenharmony_ci 19688c2ecf20Sopenharmony_cistatic void rt5651_disable_jack_detect(struct snd_soc_component *component) 19698c2ecf20Sopenharmony_ci{ 19708c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 19718c2ecf20Sopenharmony_ci 19728c2ecf20Sopenharmony_ci disable_irq(rt5651->irq); 19738c2ecf20Sopenharmony_ci rt5651_cancel_work(rt5651); 19748c2ecf20Sopenharmony_ci 19758c2ecf20Sopenharmony_ci if (rt5651_support_button_press(rt5651)) { 19768c2ecf20Sopenharmony_ci rt5651_disable_micbias1_ovcd_irq(component); 19778c2ecf20Sopenharmony_ci rt5651_disable_micbias1_for_ovcd(component); 19788c2ecf20Sopenharmony_ci snd_soc_jack_report(rt5651->hp_jack, 0, SND_JACK_BTN_0); 19798c2ecf20Sopenharmony_ci } 19808c2ecf20Sopenharmony_ci 19818c2ecf20Sopenharmony_ci rt5651->hp_jack = NULL; 19828c2ecf20Sopenharmony_ci} 19838c2ecf20Sopenharmony_ci 19848c2ecf20Sopenharmony_cistatic int rt5651_set_jack(struct snd_soc_component *component, 19858c2ecf20Sopenharmony_ci struct snd_soc_jack *jack, void *data) 19868c2ecf20Sopenharmony_ci{ 19878c2ecf20Sopenharmony_ci if (jack) 19888c2ecf20Sopenharmony_ci rt5651_enable_jack_detect(component, jack, data); 19898c2ecf20Sopenharmony_ci else 19908c2ecf20Sopenharmony_ci rt5651_disable_jack_detect(component); 19918c2ecf20Sopenharmony_ci 19928c2ecf20Sopenharmony_ci return 0; 19938c2ecf20Sopenharmony_ci} 19948c2ecf20Sopenharmony_ci 19958c2ecf20Sopenharmony_ci/* 19968c2ecf20Sopenharmony_ci * Note on some platforms the platform code may need to add device-properties, 19978c2ecf20Sopenharmony_ci * rather then relying only on properties set by the firmware. Therefor the 19988c2ecf20Sopenharmony_ci * property parsing MUST be done from the component driver's probe function, 19998c2ecf20Sopenharmony_ci * rather then from the i2c driver's probe function, so that the platform-code 20008c2ecf20Sopenharmony_ci * can attach extra properties before calling snd_soc_register_card(). 20018c2ecf20Sopenharmony_ci */ 20028c2ecf20Sopenharmony_cistatic void rt5651_apply_properties(struct snd_soc_component *component) 20038c2ecf20Sopenharmony_ci{ 20048c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 20058c2ecf20Sopenharmony_ci u32 val; 20068c2ecf20Sopenharmony_ci 20078c2ecf20Sopenharmony_ci if (device_property_read_bool(component->dev, "realtek,in2-differential")) 20088c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_IN1_IN2, 20098c2ecf20Sopenharmony_ci RT5651_IN_DF2, RT5651_IN_DF2); 20108c2ecf20Sopenharmony_ci 20118c2ecf20Sopenharmony_ci if (device_property_read_bool(component->dev, "realtek,dmic-en")) 20128c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_GPIO_CTRL1, 20138c2ecf20Sopenharmony_ci RT5651_GP2_PIN_MASK, RT5651_GP2_PIN_DMIC1_SCL); 20148c2ecf20Sopenharmony_ci 20158c2ecf20Sopenharmony_ci if (device_property_read_u32(component->dev, 20168c2ecf20Sopenharmony_ci "realtek,jack-detect-source", &val) == 0) 20178c2ecf20Sopenharmony_ci rt5651->jd_src = val; 20188c2ecf20Sopenharmony_ci 20198c2ecf20Sopenharmony_ci if (device_property_read_bool(component->dev, "realtek,jack-detect-not-inverted")) 20208c2ecf20Sopenharmony_ci rt5651->jd_active_high = true; 20218c2ecf20Sopenharmony_ci 20228c2ecf20Sopenharmony_ci /* 20238c2ecf20Sopenharmony_ci * Testing on various boards has shown that good defaults for the OVCD 20248c2ecf20Sopenharmony_ci * threshold and scale-factor are 2000µA and 0.75. For an effective 20258c2ecf20Sopenharmony_ci * limit of 1500µA, this seems to be more reliable then 1500µA and 1.0. 20268c2ecf20Sopenharmony_ci */ 20278c2ecf20Sopenharmony_ci rt5651->ovcd_th = RT5651_MIC1_OVTH_2000UA; 20288c2ecf20Sopenharmony_ci rt5651->ovcd_sf = RT5651_MIC_OVCD_SF_0P75; 20298c2ecf20Sopenharmony_ci 20308c2ecf20Sopenharmony_ci if (device_property_read_u32(component->dev, 20318c2ecf20Sopenharmony_ci "realtek,over-current-threshold-microamp", &val) == 0) { 20328c2ecf20Sopenharmony_ci switch (val) { 20338c2ecf20Sopenharmony_ci case 600: 20348c2ecf20Sopenharmony_ci rt5651->ovcd_th = RT5651_MIC1_OVTH_600UA; 20358c2ecf20Sopenharmony_ci break; 20368c2ecf20Sopenharmony_ci case 1500: 20378c2ecf20Sopenharmony_ci rt5651->ovcd_th = RT5651_MIC1_OVTH_1500UA; 20388c2ecf20Sopenharmony_ci break; 20398c2ecf20Sopenharmony_ci case 2000: 20408c2ecf20Sopenharmony_ci rt5651->ovcd_th = RT5651_MIC1_OVTH_2000UA; 20418c2ecf20Sopenharmony_ci break; 20428c2ecf20Sopenharmony_ci default: 20438c2ecf20Sopenharmony_ci dev_warn(component->dev, "Warning: Invalid over-current-threshold-microamp value: %d, defaulting to 2000uA\n", 20448c2ecf20Sopenharmony_ci val); 20458c2ecf20Sopenharmony_ci } 20468c2ecf20Sopenharmony_ci } 20478c2ecf20Sopenharmony_ci 20488c2ecf20Sopenharmony_ci if (device_property_read_u32(component->dev, 20498c2ecf20Sopenharmony_ci "realtek,over-current-scale-factor", &val) == 0) { 20508c2ecf20Sopenharmony_ci if (val <= RT5651_OVCD_SF_1P5) 20518c2ecf20Sopenharmony_ci rt5651->ovcd_sf = val << RT5651_MIC_OVCD_SF_SFT; 20528c2ecf20Sopenharmony_ci else 20538c2ecf20Sopenharmony_ci dev_warn(component->dev, "Warning: Invalid over-current-scale-factor value: %d, defaulting to 0.75\n", 20548c2ecf20Sopenharmony_ci val); 20558c2ecf20Sopenharmony_ci } 20568c2ecf20Sopenharmony_ci} 20578c2ecf20Sopenharmony_ci 20588c2ecf20Sopenharmony_cistatic int rt5651_probe(struct snd_soc_component *component) 20598c2ecf20Sopenharmony_ci{ 20608c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 20618c2ecf20Sopenharmony_ci 20628c2ecf20Sopenharmony_ci rt5651->component = component; 20638c2ecf20Sopenharmony_ci 20648c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5651_PWR_ANLG1, 20658c2ecf20Sopenharmony_ci RT5651_PWR_LDO_DVO_MASK, RT5651_PWR_LDO_DVO_1_2V); 20668c2ecf20Sopenharmony_ci 20678c2ecf20Sopenharmony_ci snd_soc_component_force_bias_level(component, SND_SOC_BIAS_OFF); 20688c2ecf20Sopenharmony_ci 20698c2ecf20Sopenharmony_ci rt5651_apply_properties(component); 20708c2ecf20Sopenharmony_ci 20718c2ecf20Sopenharmony_ci return 0; 20728c2ecf20Sopenharmony_ci} 20738c2ecf20Sopenharmony_ci 20748c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 20758c2ecf20Sopenharmony_cistatic int rt5651_suspend(struct snd_soc_component *component) 20768c2ecf20Sopenharmony_ci{ 20778c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 20788c2ecf20Sopenharmony_ci 20798c2ecf20Sopenharmony_ci regcache_cache_only(rt5651->regmap, true); 20808c2ecf20Sopenharmony_ci regcache_mark_dirty(rt5651->regmap); 20818c2ecf20Sopenharmony_ci return 0; 20828c2ecf20Sopenharmony_ci} 20838c2ecf20Sopenharmony_ci 20848c2ecf20Sopenharmony_cistatic int rt5651_resume(struct snd_soc_component *component) 20858c2ecf20Sopenharmony_ci{ 20868c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 20878c2ecf20Sopenharmony_ci 20888c2ecf20Sopenharmony_ci regcache_cache_only(rt5651->regmap, false); 20898c2ecf20Sopenharmony_ci snd_soc_component_cache_sync(component); 20908c2ecf20Sopenharmony_ci 20918c2ecf20Sopenharmony_ci return 0; 20928c2ecf20Sopenharmony_ci} 20938c2ecf20Sopenharmony_ci#else 20948c2ecf20Sopenharmony_ci#define rt5651_suspend NULL 20958c2ecf20Sopenharmony_ci#define rt5651_resume NULL 20968c2ecf20Sopenharmony_ci#endif 20978c2ecf20Sopenharmony_ci 20988c2ecf20Sopenharmony_ci#define RT5651_STEREO_RATES SNDRV_PCM_RATE_8000_96000 20998c2ecf20Sopenharmony_ci#define RT5651_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ 21008c2ecf20Sopenharmony_ci SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8) 21018c2ecf20Sopenharmony_ci 21028c2ecf20Sopenharmony_cistatic const struct snd_soc_dai_ops rt5651_aif_dai_ops = { 21038c2ecf20Sopenharmony_ci .hw_params = rt5651_hw_params, 21048c2ecf20Sopenharmony_ci .set_fmt = rt5651_set_dai_fmt, 21058c2ecf20Sopenharmony_ci .set_sysclk = rt5651_set_dai_sysclk, 21068c2ecf20Sopenharmony_ci .set_pll = rt5651_set_dai_pll, 21078c2ecf20Sopenharmony_ci}; 21088c2ecf20Sopenharmony_ci 21098c2ecf20Sopenharmony_cistatic struct snd_soc_dai_driver rt5651_dai[] = { 21108c2ecf20Sopenharmony_ci { 21118c2ecf20Sopenharmony_ci .name = "rt5651-aif1", 21128c2ecf20Sopenharmony_ci .id = RT5651_AIF1, 21138c2ecf20Sopenharmony_ci .playback = { 21148c2ecf20Sopenharmony_ci .stream_name = "AIF1 Playback", 21158c2ecf20Sopenharmony_ci .channels_min = 1, 21168c2ecf20Sopenharmony_ci .channels_max = 2, 21178c2ecf20Sopenharmony_ci .rates = RT5651_STEREO_RATES, 21188c2ecf20Sopenharmony_ci .formats = RT5651_FORMATS, 21198c2ecf20Sopenharmony_ci }, 21208c2ecf20Sopenharmony_ci .capture = { 21218c2ecf20Sopenharmony_ci .stream_name = "AIF1 Capture", 21228c2ecf20Sopenharmony_ci .channels_min = 1, 21238c2ecf20Sopenharmony_ci .channels_max = 2, 21248c2ecf20Sopenharmony_ci .rates = RT5651_STEREO_RATES, 21258c2ecf20Sopenharmony_ci .formats = RT5651_FORMATS, 21268c2ecf20Sopenharmony_ci }, 21278c2ecf20Sopenharmony_ci .ops = &rt5651_aif_dai_ops, 21288c2ecf20Sopenharmony_ci }, 21298c2ecf20Sopenharmony_ci { 21308c2ecf20Sopenharmony_ci .name = "rt5651-aif2", 21318c2ecf20Sopenharmony_ci .id = RT5651_AIF2, 21328c2ecf20Sopenharmony_ci .playback = { 21338c2ecf20Sopenharmony_ci .stream_name = "AIF2 Playback", 21348c2ecf20Sopenharmony_ci .channels_min = 1, 21358c2ecf20Sopenharmony_ci .channels_max = 2, 21368c2ecf20Sopenharmony_ci .rates = RT5651_STEREO_RATES, 21378c2ecf20Sopenharmony_ci .formats = RT5651_FORMATS, 21388c2ecf20Sopenharmony_ci }, 21398c2ecf20Sopenharmony_ci .capture = { 21408c2ecf20Sopenharmony_ci .stream_name = "AIF2 Capture", 21418c2ecf20Sopenharmony_ci .channels_min = 1, 21428c2ecf20Sopenharmony_ci .channels_max = 2, 21438c2ecf20Sopenharmony_ci .rates = RT5651_STEREO_RATES, 21448c2ecf20Sopenharmony_ci .formats = RT5651_FORMATS, 21458c2ecf20Sopenharmony_ci }, 21468c2ecf20Sopenharmony_ci .ops = &rt5651_aif_dai_ops, 21478c2ecf20Sopenharmony_ci }, 21488c2ecf20Sopenharmony_ci}; 21498c2ecf20Sopenharmony_ci 21508c2ecf20Sopenharmony_cistatic const struct snd_soc_component_driver soc_component_dev_rt5651 = { 21518c2ecf20Sopenharmony_ci .probe = rt5651_probe, 21528c2ecf20Sopenharmony_ci .suspend = rt5651_suspend, 21538c2ecf20Sopenharmony_ci .resume = rt5651_resume, 21548c2ecf20Sopenharmony_ci .set_bias_level = rt5651_set_bias_level, 21558c2ecf20Sopenharmony_ci .set_jack = rt5651_set_jack, 21568c2ecf20Sopenharmony_ci .controls = rt5651_snd_controls, 21578c2ecf20Sopenharmony_ci .num_controls = ARRAY_SIZE(rt5651_snd_controls), 21588c2ecf20Sopenharmony_ci .dapm_widgets = rt5651_dapm_widgets, 21598c2ecf20Sopenharmony_ci .num_dapm_widgets = ARRAY_SIZE(rt5651_dapm_widgets), 21608c2ecf20Sopenharmony_ci .dapm_routes = rt5651_dapm_routes, 21618c2ecf20Sopenharmony_ci .num_dapm_routes = ARRAY_SIZE(rt5651_dapm_routes), 21628c2ecf20Sopenharmony_ci .use_pmdown_time = 1, 21638c2ecf20Sopenharmony_ci .endianness = 1, 21648c2ecf20Sopenharmony_ci .non_legacy_dai_naming = 1, 21658c2ecf20Sopenharmony_ci}; 21668c2ecf20Sopenharmony_ci 21678c2ecf20Sopenharmony_cistatic const struct regmap_config rt5651_regmap = { 21688c2ecf20Sopenharmony_ci .reg_bits = 8, 21698c2ecf20Sopenharmony_ci .val_bits = 16, 21708c2ecf20Sopenharmony_ci 21718c2ecf20Sopenharmony_ci .max_register = RT5651_DEVICE_ID + 1 + (ARRAY_SIZE(rt5651_ranges) * 21728c2ecf20Sopenharmony_ci RT5651_PR_SPACING), 21738c2ecf20Sopenharmony_ci .volatile_reg = rt5651_volatile_register, 21748c2ecf20Sopenharmony_ci .readable_reg = rt5651_readable_register, 21758c2ecf20Sopenharmony_ci 21768c2ecf20Sopenharmony_ci .cache_type = REGCACHE_RBTREE, 21778c2ecf20Sopenharmony_ci .reg_defaults = rt5651_reg, 21788c2ecf20Sopenharmony_ci .num_reg_defaults = ARRAY_SIZE(rt5651_reg), 21798c2ecf20Sopenharmony_ci .ranges = rt5651_ranges, 21808c2ecf20Sopenharmony_ci .num_ranges = ARRAY_SIZE(rt5651_ranges), 21818c2ecf20Sopenharmony_ci .use_single_read = true, 21828c2ecf20Sopenharmony_ci .use_single_write = true, 21838c2ecf20Sopenharmony_ci}; 21848c2ecf20Sopenharmony_ci 21858c2ecf20Sopenharmony_ci#if defined(CONFIG_OF) 21868c2ecf20Sopenharmony_cistatic const struct of_device_id rt5651_of_match[] = { 21878c2ecf20Sopenharmony_ci { .compatible = "realtek,rt5651", }, 21888c2ecf20Sopenharmony_ci {}, 21898c2ecf20Sopenharmony_ci}; 21908c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, rt5651_of_match); 21918c2ecf20Sopenharmony_ci#endif 21928c2ecf20Sopenharmony_ci 21938c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI 21948c2ecf20Sopenharmony_cistatic const struct acpi_device_id rt5651_acpi_match[] = { 21958c2ecf20Sopenharmony_ci { "10EC5651", 0 }, 21968c2ecf20Sopenharmony_ci { "10EC5640", 0 }, 21978c2ecf20Sopenharmony_ci { }, 21988c2ecf20Sopenharmony_ci}; 21998c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(acpi, rt5651_acpi_match); 22008c2ecf20Sopenharmony_ci#endif 22018c2ecf20Sopenharmony_ci 22028c2ecf20Sopenharmony_cistatic const struct i2c_device_id rt5651_i2c_id[] = { 22038c2ecf20Sopenharmony_ci { "rt5651", 0 }, 22048c2ecf20Sopenharmony_ci { } 22058c2ecf20Sopenharmony_ci}; 22068c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, rt5651_i2c_id); 22078c2ecf20Sopenharmony_ci 22088c2ecf20Sopenharmony_ci/* 22098c2ecf20Sopenharmony_ci * Note this function MUST not look at device-properties, see the comment 22108c2ecf20Sopenharmony_ci * above rt5651_apply_properties(). 22118c2ecf20Sopenharmony_ci */ 22128c2ecf20Sopenharmony_cistatic int rt5651_i2c_probe(struct i2c_client *i2c, 22138c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 22148c2ecf20Sopenharmony_ci{ 22158c2ecf20Sopenharmony_ci struct rt5651_priv *rt5651; 22168c2ecf20Sopenharmony_ci int ret; 22178c2ecf20Sopenharmony_ci int err; 22188c2ecf20Sopenharmony_ci 22198c2ecf20Sopenharmony_ci rt5651 = devm_kzalloc(&i2c->dev, sizeof(*rt5651), 22208c2ecf20Sopenharmony_ci GFP_KERNEL); 22218c2ecf20Sopenharmony_ci if (NULL == rt5651) 22228c2ecf20Sopenharmony_ci return -ENOMEM; 22238c2ecf20Sopenharmony_ci 22248c2ecf20Sopenharmony_ci i2c_set_clientdata(i2c, rt5651); 22258c2ecf20Sopenharmony_ci 22268c2ecf20Sopenharmony_ci rt5651->regmap = devm_regmap_init_i2c(i2c, &rt5651_regmap); 22278c2ecf20Sopenharmony_ci if (IS_ERR(rt5651->regmap)) { 22288c2ecf20Sopenharmony_ci ret = PTR_ERR(rt5651->regmap); 22298c2ecf20Sopenharmony_ci dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 22308c2ecf20Sopenharmony_ci ret); 22318c2ecf20Sopenharmony_ci return ret; 22328c2ecf20Sopenharmony_ci } 22338c2ecf20Sopenharmony_ci 22348c2ecf20Sopenharmony_ci err = regmap_read(rt5651->regmap, RT5651_DEVICE_ID, &ret); 22358c2ecf20Sopenharmony_ci if (err) 22368c2ecf20Sopenharmony_ci return err; 22378c2ecf20Sopenharmony_ci 22388c2ecf20Sopenharmony_ci if (ret != RT5651_DEVICE_ID_VALUE) { 22398c2ecf20Sopenharmony_ci dev_err(&i2c->dev, 22408c2ecf20Sopenharmony_ci "Device with ID register %#x is not rt5651\n", ret); 22418c2ecf20Sopenharmony_ci return -ENODEV; 22428c2ecf20Sopenharmony_ci } 22438c2ecf20Sopenharmony_ci 22448c2ecf20Sopenharmony_ci regmap_write(rt5651->regmap, RT5651_RESET, 0); 22458c2ecf20Sopenharmony_ci 22468c2ecf20Sopenharmony_ci ret = regmap_register_patch(rt5651->regmap, init_list, 22478c2ecf20Sopenharmony_ci ARRAY_SIZE(init_list)); 22488c2ecf20Sopenharmony_ci if (ret != 0) 22498c2ecf20Sopenharmony_ci dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret); 22508c2ecf20Sopenharmony_ci 22518c2ecf20Sopenharmony_ci rt5651->irq = i2c->irq; 22528c2ecf20Sopenharmony_ci rt5651->hp_mute = true; 22538c2ecf20Sopenharmony_ci 22548c2ecf20Sopenharmony_ci INIT_DELAYED_WORK(&rt5651->bp_work, rt5651_button_press_work); 22558c2ecf20Sopenharmony_ci INIT_WORK(&rt5651->jack_detect_work, rt5651_jack_detect_work); 22568c2ecf20Sopenharmony_ci 22578c2ecf20Sopenharmony_ci /* Make sure work is stopped on probe-error / remove */ 22588c2ecf20Sopenharmony_ci ret = devm_add_action_or_reset(&i2c->dev, rt5651_cancel_work, rt5651); 22598c2ecf20Sopenharmony_ci if (ret) 22608c2ecf20Sopenharmony_ci return ret; 22618c2ecf20Sopenharmony_ci 22628c2ecf20Sopenharmony_ci ret = devm_request_irq(&i2c->dev, rt5651->irq, rt5651_irq, 22638c2ecf20Sopenharmony_ci IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING 22648c2ecf20Sopenharmony_ci | IRQF_ONESHOT, "rt5651", rt5651); 22658c2ecf20Sopenharmony_ci if (ret == 0) { 22668c2ecf20Sopenharmony_ci /* Gets re-enabled by rt5651_set_jack() */ 22678c2ecf20Sopenharmony_ci disable_irq(rt5651->irq); 22688c2ecf20Sopenharmony_ci } else { 22698c2ecf20Sopenharmony_ci dev_warn(&i2c->dev, "Failed to reguest IRQ %d: %d\n", 22708c2ecf20Sopenharmony_ci rt5651->irq, ret); 22718c2ecf20Sopenharmony_ci rt5651->irq = -ENXIO; 22728c2ecf20Sopenharmony_ci } 22738c2ecf20Sopenharmony_ci 22748c2ecf20Sopenharmony_ci ret = devm_snd_soc_register_component(&i2c->dev, 22758c2ecf20Sopenharmony_ci &soc_component_dev_rt5651, 22768c2ecf20Sopenharmony_ci rt5651_dai, ARRAY_SIZE(rt5651_dai)); 22778c2ecf20Sopenharmony_ci 22788c2ecf20Sopenharmony_ci return ret; 22798c2ecf20Sopenharmony_ci} 22808c2ecf20Sopenharmony_ci 22818c2ecf20Sopenharmony_cistatic struct i2c_driver rt5651_i2c_driver = { 22828c2ecf20Sopenharmony_ci .driver = { 22838c2ecf20Sopenharmony_ci .name = "rt5651", 22848c2ecf20Sopenharmony_ci .acpi_match_table = ACPI_PTR(rt5651_acpi_match), 22858c2ecf20Sopenharmony_ci .of_match_table = of_match_ptr(rt5651_of_match), 22868c2ecf20Sopenharmony_ci }, 22878c2ecf20Sopenharmony_ci .probe = rt5651_i2c_probe, 22888c2ecf20Sopenharmony_ci .id_table = rt5651_i2c_id, 22898c2ecf20Sopenharmony_ci}; 22908c2ecf20Sopenharmony_cimodule_i2c_driver(rt5651_i2c_driver); 22918c2ecf20Sopenharmony_ci 22928c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("ASoC RT5651 driver"); 22938c2ecf20Sopenharmony_ciMODULE_AUTHOR("Bard Liao <bardliao@realtek.com>"); 22948c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 2295