18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * rt5660.c -- RT5660 ALSA SoC audio codec driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2016 Realtek Semiconductor Corp. 68c2ecf20Sopenharmony_ci * Author: Oder Chiou <oder_chiou@realtek.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/module.h> 108c2ecf20Sopenharmony_ci#include <linux/moduleparam.h> 118c2ecf20Sopenharmony_ci#include <linux/init.h> 128c2ecf20Sopenharmony_ci#include <linux/delay.h> 138c2ecf20Sopenharmony_ci#include <linux/pm.h> 148c2ecf20Sopenharmony_ci#include <linux/gpio.h> 158c2ecf20Sopenharmony_ci#include <linux/i2c.h> 168c2ecf20Sopenharmony_ci#include <linux/regmap.h> 178c2ecf20Sopenharmony_ci#include <linux/of.h> 188c2ecf20Sopenharmony_ci#include <linux/of_gpio.h> 198c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 208c2ecf20Sopenharmony_ci#include <linux/spi/spi.h> 218c2ecf20Sopenharmony_ci#include <linux/acpi.h> 228c2ecf20Sopenharmony_ci#include <sound/core.h> 238c2ecf20Sopenharmony_ci#include <sound/pcm.h> 248c2ecf20Sopenharmony_ci#include <sound/pcm_params.h> 258c2ecf20Sopenharmony_ci#include <sound/soc.h> 268c2ecf20Sopenharmony_ci#include <sound/soc-dapm.h> 278c2ecf20Sopenharmony_ci#include <sound/initval.h> 288c2ecf20Sopenharmony_ci#include <sound/tlv.h> 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#include "rl6231.h" 318c2ecf20Sopenharmony_ci#include "rt5660.h" 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define RT5660_DEVICE_ID 0x6338 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#define RT5660_PR_RANGE_BASE (0xff + 1) 368c2ecf20Sopenharmony_ci#define RT5660_PR_SPACING 0x100 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define RT5660_PR_BASE (RT5660_PR_RANGE_BASE + (0 * RT5660_PR_SPACING)) 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistatic const struct regmap_range_cfg rt5660_ranges[] = { 418c2ecf20Sopenharmony_ci { .name = "PR", .range_min = RT5660_PR_BASE, 428c2ecf20Sopenharmony_ci .range_max = RT5660_PR_BASE + 0xf3, 438c2ecf20Sopenharmony_ci .selector_reg = RT5660_PRIV_INDEX, 448c2ecf20Sopenharmony_ci .selector_mask = 0xff, 458c2ecf20Sopenharmony_ci .selector_shift = 0x0, 468c2ecf20Sopenharmony_ci .window_start = RT5660_PRIV_DATA, 478c2ecf20Sopenharmony_ci .window_len = 0x1, }, 488c2ecf20Sopenharmony_ci}; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistatic const struct reg_sequence rt5660_patch[] = { 518c2ecf20Sopenharmony_ci { RT5660_ALC_PGA_CTRL2, 0x44c3 }, 528c2ecf20Sopenharmony_ci { RT5660_PR_BASE + 0x3d, 0x2600 }, 538c2ecf20Sopenharmony_ci}; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_cistatic const struct reg_default rt5660_reg[] = { 568c2ecf20Sopenharmony_ci { 0x00, 0x0000 }, 578c2ecf20Sopenharmony_ci { 0x01, 0xc800 }, 588c2ecf20Sopenharmony_ci { 0x02, 0xc8c8 }, 598c2ecf20Sopenharmony_ci { 0x0d, 0x1010 }, 608c2ecf20Sopenharmony_ci { 0x0e, 0x1010 }, 618c2ecf20Sopenharmony_ci { 0x19, 0xafaf }, 628c2ecf20Sopenharmony_ci { 0x1c, 0x2f2f }, 638c2ecf20Sopenharmony_ci { 0x1e, 0x0000 }, 648c2ecf20Sopenharmony_ci { 0x27, 0x6060 }, 658c2ecf20Sopenharmony_ci { 0x29, 0x8080 }, 668c2ecf20Sopenharmony_ci { 0x2a, 0x4242 }, 678c2ecf20Sopenharmony_ci { 0x2f, 0x0000 }, 688c2ecf20Sopenharmony_ci { 0x3b, 0x0000 }, 698c2ecf20Sopenharmony_ci { 0x3c, 0x007f }, 708c2ecf20Sopenharmony_ci { 0x3d, 0x0000 }, 718c2ecf20Sopenharmony_ci { 0x3e, 0x007f }, 728c2ecf20Sopenharmony_ci { 0x45, 0xe000 }, 738c2ecf20Sopenharmony_ci { 0x46, 0x003e }, 748c2ecf20Sopenharmony_ci { 0x48, 0xf800 }, 758c2ecf20Sopenharmony_ci { 0x4a, 0x0004 }, 768c2ecf20Sopenharmony_ci { 0x4d, 0x0000 }, 778c2ecf20Sopenharmony_ci { 0x4e, 0x0000 }, 788c2ecf20Sopenharmony_ci { 0x4f, 0x01ff }, 798c2ecf20Sopenharmony_ci { 0x50, 0x0000 }, 808c2ecf20Sopenharmony_ci { 0x51, 0x0000 }, 818c2ecf20Sopenharmony_ci { 0x52, 0x01ff }, 828c2ecf20Sopenharmony_ci { 0x61, 0x0000 }, 838c2ecf20Sopenharmony_ci { 0x62, 0x0000 }, 848c2ecf20Sopenharmony_ci { 0x63, 0x00c0 }, 858c2ecf20Sopenharmony_ci { 0x64, 0x0000 }, 868c2ecf20Sopenharmony_ci { 0x65, 0x0000 }, 878c2ecf20Sopenharmony_ci { 0x66, 0x0000 }, 888c2ecf20Sopenharmony_ci { 0x70, 0x8000 }, 898c2ecf20Sopenharmony_ci { 0x73, 0x7000 }, 908c2ecf20Sopenharmony_ci { 0x74, 0x3c00 }, 918c2ecf20Sopenharmony_ci { 0x75, 0x2800 }, 928c2ecf20Sopenharmony_ci { 0x80, 0x0000 }, 938c2ecf20Sopenharmony_ci { 0x81, 0x0000 }, 948c2ecf20Sopenharmony_ci { 0x82, 0x0000 }, 958c2ecf20Sopenharmony_ci { 0x8c, 0x0228 }, 968c2ecf20Sopenharmony_ci { 0x8d, 0xa000 }, 978c2ecf20Sopenharmony_ci { 0x8e, 0x0000 }, 988c2ecf20Sopenharmony_ci { 0x92, 0x0000 }, 998c2ecf20Sopenharmony_ci { 0x93, 0x3000 }, 1008c2ecf20Sopenharmony_ci { 0xa1, 0x0059 }, 1018c2ecf20Sopenharmony_ci { 0xa2, 0x0001 }, 1028c2ecf20Sopenharmony_ci { 0xa3, 0x5c80 }, 1038c2ecf20Sopenharmony_ci { 0xa4, 0x0146 }, 1048c2ecf20Sopenharmony_ci { 0xa5, 0x1f1f }, 1058c2ecf20Sopenharmony_ci { 0xa6, 0x78c6 }, 1068c2ecf20Sopenharmony_ci { 0xa7, 0xe5ec }, 1078c2ecf20Sopenharmony_ci { 0xa8, 0xba61 }, 1088c2ecf20Sopenharmony_ci { 0xa9, 0x3c78 }, 1098c2ecf20Sopenharmony_ci { 0xaa, 0x8ae2 }, 1108c2ecf20Sopenharmony_ci { 0xab, 0xe5ec }, 1118c2ecf20Sopenharmony_ci { 0xac, 0xc600 }, 1128c2ecf20Sopenharmony_ci { 0xad, 0xba61 }, 1138c2ecf20Sopenharmony_ci { 0xae, 0x17ed }, 1148c2ecf20Sopenharmony_ci { 0xb0, 0x2080 }, 1158c2ecf20Sopenharmony_ci { 0xb1, 0x0000 }, 1168c2ecf20Sopenharmony_ci { 0xb3, 0x001f }, 1178c2ecf20Sopenharmony_ci { 0xb4, 0x020c }, 1188c2ecf20Sopenharmony_ci { 0xb5, 0x1f00 }, 1198c2ecf20Sopenharmony_ci { 0xb6, 0x0000 }, 1208c2ecf20Sopenharmony_ci { 0xb7, 0x4000 }, 1218c2ecf20Sopenharmony_ci { 0xbb, 0x0000 }, 1228c2ecf20Sopenharmony_ci { 0xbd, 0x0000 }, 1238c2ecf20Sopenharmony_ci { 0xbe, 0x0000 }, 1248c2ecf20Sopenharmony_ci { 0xbf, 0x0100 }, 1258c2ecf20Sopenharmony_ci { 0xc0, 0x0000 }, 1268c2ecf20Sopenharmony_ci { 0xc2, 0x0000 }, 1278c2ecf20Sopenharmony_ci { 0xd3, 0xa220 }, 1288c2ecf20Sopenharmony_ci { 0xd9, 0x0809 }, 1298c2ecf20Sopenharmony_ci { 0xda, 0x0000 }, 1308c2ecf20Sopenharmony_ci { 0xe0, 0x8000 }, 1318c2ecf20Sopenharmony_ci { 0xe1, 0x0200 }, 1328c2ecf20Sopenharmony_ci { 0xe2, 0x8000 }, 1338c2ecf20Sopenharmony_ci { 0xe3, 0x0200 }, 1348c2ecf20Sopenharmony_ci { 0xe4, 0x0f20 }, 1358c2ecf20Sopenharmony_ci { 0xe5, 0x001f }, 1368c2ecf20Sopenharmony_ci { 0xe6, 0x020c }, 1378c2ecf20Sopenharmony_ci { 0xe7, 0x1f00 }, 1388c2ecf20Sopenharmony_ci { 0xe8, 0x0000 }, 1398c2ecf20Sopenharmony_ci { 0xe9, 0x4000 }, 1408c2ecf20Sopenharmony_ci { 0xea, 0x00a6 }, 1418c2ecf20Sopenharmony_ci { 0xeb, 0x04c3 }, 1428c2ecf20Sopenharmony_ci { 0xec, 0x27c8 }, 1438c2ecf20Sopenharmony_ci { 0xed, 0x7418 }, 1448c2ecf20Sopenharmony_ci { 0xee, 0xbf50 }, 1458c2ecf20Sopenharmony_ci { 0xef, 0x0045 }, 1468c2ecf20Sopenharmony_ci { 0xf0, 0x0007 }, 1478c2ecf20Sopenharmony_ci { 0xfa, 0x0000 }, 1488c2ecf20Sopenharmony_ci { 0xfd, 0x0000 }, 1498c2ecf20Sopenharmony_ci { 0xfe, 0x10ec }, 1508c2ecf20Sopenharmony_ci { 0xff, 0x6338 }, 1518c2ecf20Sopenharmony_ci}; 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_cistatic bool rt5660_volatile_register(struct device *dev, unsigned int reg) 1548c2ecf20Sopenharmony_ci{ 1558c2ecf20Sopenharmony_ci int i; 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(rt5660_ranges); i++) 1588c2ecf20Sopenharmony_ci if ((reg >= rt5660_ranges[i].window_start && 1598c2ecf20Sopenharmony_ci reg <= rt5660_ranges[i].window_start + 1608c2ecf20Sopenharmony_ci rt5660_ranges[i].window_len) || 1618c2ecf20Sopenharmony_ci (reg >= rt5660_ranges[i].range_min && 1628c2ecf20Sopenharmony_ci reg <= rt5660_ranges[i].range_max)) 1638c2ecf20Sopenharmony_ci return true; 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci switch (reg) { 1668c2ecf20Sopenharmony_ci case RT5660_RESET: 1678c2ecf20Sopenharmony_ci case RT5660_PRIV_DATA: 1688c2ecf20Sopenharmony_ci case RT5660_EQ_CTRL1: 1698c2ecf20Sopenharmony_ci case RT5660_IRQ_CTRL2: 1708c2ecf20Sopenharmony_ci case RT5660_INT_IRQ_ST: 1718c2ecf20Sopenharmony_ci case RT5660_VENDOR_ID: 1728c2ecf20Sopenharmony_ci case RT5660_VENDOR_ID1: 1738c2ecf20Sopenharmony_ci case RT5660_VENDOR_ID2: 1748c2ecf20Sopenharmony_ci return true; 1758c2ecf20Sopenharmony_ci default: 1768c2ecf20Sopenharmony_ci return false; 1778c2ecf20Sopenharmony_ci } 1788c2ecf20Sopenharmony_ci} 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_cistatic bool rt5660_readable_register(struct device *dev, unsigned int reg) 1818c2ecf20Sopenharmony_ci{ 1828c2ecf20Sopenharmony_ci int i; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(rt5660_ranges); i++) 1858c2ecf20Sopenharmony_ci if ((reg >= rt5660_ranges[i].window_start && 1868c2ecf20Sopenharmony_ci reg <= rt5660_ranges[i].window_start + 1878c2ecf20Sopenharmony_ci rt5660_ranges[i].window_len) || 1888c2ecf20Sopenharmony_ci (reg >= rt5660_ranges[i].range_min && 1898c2ecf20Sopenharmony_ci reg <= rt5660_ranges[i].range_max)) 1908c2ecf20Sopenharmony_ci return true; 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci switch (reg) { 1938c2ecf20Sopenharmony_ci case RT5660_RESET: 1948c2ecf20Sopenharmony_ci case RT5660_SPK_VOL: 1958c2ecf20Sopenharmony_ci case RT5660_LOUT_VOL: 1968c2ecf20Sopenharmony_ci case RT5660_IN1_IN2: 1978c2ecf20Sopenharmony_ci case RT5660_IN3_IN4: 1988c2ecf20Sopenharmony_ci case RT5660_DAC1_DIG_VOL: 1998c2ecf20Sopenharmony_ci case RT5660_STO1_ADC_DIG_VOL: 2008c2ecf20Sopenharmony_ci case RT5660_ADC_BST_VOL1: 2018c2ecf20Sopenharmony_ci case RT5660_STO1_ADC_MIXER: 2028c2ecf20Sopenharmony_ci case RT5660_AD_DA_MIXER: 2038c2ecf20Sopenharmony_ci case RT5660_STO_DAC_MIXER: 2048c2ecf20Sopenharmony_ci case RT5660_DIG_INF1_DATA: 2058c2ecf20Sopenharmony_ci case RT5660_REC_L1_MIXER: 2068c2ecf20Sopenharmony_ci case RT5660_REC_L2_MIXER: 2078c2ecf20Sopenharmony_ci case RT5660_REC_R1_MIXER: 2088c2ecf20Sopenharmony_ci case RT5660_REC_R2_MIXER: 2098c2ecf20Sopenharmony_ci case RT5660_LOUT_MIXER: 2108c2ecf20Sopenharmony_ci case RT5660_SPK_MIXER: 2118c2ecf20Sopenharmony_ci case RT5660_SPO_MIXER: 2128c2ecf20Sopenharmony_ci case RT5660_SPO_CLSD_RATIO: 2138c2ecf20Sopenharmony_ci case RT5660_OUT_L_GAIN1: 2148c2ecf20Sopenharmony_ci case RT5660_OUT_L_GAIN2: 2158c2ecf20Sopenharmony_ci case RT5660_OUT_L1_MIXER: 2168c2ecf20Sopenharmony_ci case RT5660_OUT_R_GAIN1: 2178c2ecf20Sopenharmony_ci case RT5660_OUT_R_GAIN2: 2188c2ecf20Sopenharmony_ci case RT5660_OUT_R1_MIXER: 2198c2ecf20Sopenharmony_ci case RT5660_PWR_DIG1: 2208c2ecf20Sopenharmony_ci case RT5660_PWR_DIG2: 2218c2ecf20Sopenharmony_ci case RT5660_PWR_ANLG1: 2228c2ecf20Sopenharmony_ci case RT5660_PWR_ANLG2: 2238c2ecf20Sopenharmony_ci case RT5660_PWR_MIXER: 2248c2ecf20Sopenharmony_ci case RT5660_PWR_VOL: 2258c2ecf20Sopenharmony_ci case RT5660_PRIV_INDEX: 2268c2ecf20Sopenharmony_ci case RT5660_PRIV_DATA: 2278c2ecf20Sopenharmony_ci case RT5660_I2S1_SDP: 2288c2ecf20Sopenharmony_ci case RT5660_ADDA_CLK1: 2298c2ecf20Sopenharmony_ci case RT5660_ADDA_CLK2: 2308c2ecf20Sopenharmony_ci case RT5660_DMIC_CTRL1: 2318c2ecf20Sopenharmony_ci case RT5660_GLB_CLK: 2328c2ecf20Sopenharmony_ci case RT5660_PLL_CTRL1: 2338c2ecf20Sopenharmony_ci case RT5660_PLL_CTRL2: 2348c2ecf20Sopenharmony_ci case RT5660_CLSD_AMP_OC_CTRL: 2358c2ecf20Sopenharmony_ci case RT5660_CLSD_AMP_CTRL: 2368c2ecf20Sopenharmony_ci case RT5660_LOUT_AMP_CTRL: 2378c2ecf20Sopenharmony_ci case RT5660_SPK_AMP_SPKVDD: 2388c2ecf20Sopenharmony_ci case RT5660_MICBIAS: 2398c2ecf20Sopenharmony_ci case RT5660_CLSD_OUT_CTRL1: 2408c2ecf20Sopenharmony_ci case RT5660_CLSD_OUT_CTRL2: 2418c2ecf20Sopenharmony_ci case RT5660_DIPOLE_MIC_CTRL1: 2428c2ecf20Sopenharmony_ci case RT5660_DIPOLE_MIC_CTRL2: 2438c2ecf20Sopenharmony_ci case RT5660_DIPOLE_MIC_CTRL3: 2448c2ecf20Sopenharmony_ci case RT5660_DIPOLE_MIC_CTRL4: 2458c2ecf20Sopenharmony_ci case RT5660_DIPOLE_MIC_CTRL5: 2468c2ecf20Sopenharmony_ci case RT5660_DIPOLE_MIC_CTRL6: 2478c2ecf20Sopenharmony_ci case RT5660_DIPOLE_MIC_CTRL7: 2488c2ecf20Sopenharmony_ci case RT5660_DIPOLE_MIC_CTRL8: 2498c2ecf20Sopenharmony_ci case RT5660_DIPOLE_MIC_CTRL9: 2508c2ecf20Sopenharmony_ci case RT5660_DIPOLE_MIC_CTRL10: 2518c2ecf20Sopenharmony_ci case RT5660_DIPOLE_MIC_CTRL11: 2528c2ecf20Sopenharmony_ci case RT5660_DIPOLE_MIC_CTRL12: 2538c2ecf20Sopenharmony_ci case RT5660_EQ_CTRL1: 2548c2ecf20Sopenharmony_ci case RT5660_EQ_CTRL2: 2558c2ecf20Sopenharmony_ci case RT5660_DRC_AGC_CTRL1: 2568c2ecf20Sopenharmony_ci case RT5660_DRC_AGC_CTRL2: 2578c2ecf20Sopenharmony_ci case RT5660_DRC_AGC_CTRL3: 2588c2ecf20Sopenharmony_ci case RT5660_DRC_AGC_CTRL4: 2598c2ecf20Sopenharmony_ci case RT5660_DRC_AGC_CTRL5: 2608c2ecf20Sopenharmony_ci case RT5660_JD_CTRL: 2618c2ecf20Sopenharmony_ci case RT5660_IRQ_CTRL1: 2628c2ecf20Sopenharmony_ci case RT5660_IRQ_CTRL2: 2638c2ecf20Sopenharmony_ci case RT5660_INT_IRQ_ST: 2648c2ecf20Sopenharmony_ci case RT5660_GPIO_CTRL1: 2658c2ecf20Sopenharmony_ci case RT5660_GPIO_CTRL2: 2668c2ecf20Sopenharmony_ci case RT5660_WIND_FILTER_CTRL1: 2678c2ecf20Sopenharmony_ci case RT5660_SV_ZCD1: 2688c2ecf20Sopenharmony_ci case RT5660_SV_ZCD2: 2698c2ecf20Sopenharmony_ci case RT5660_DRC1_LM_CTRL1: 2708c2ecf20Sopenharmony_ci case RT5660_DRC1_LM_CTRL2: 2718c2ecf20Sopenharmony_ci case RT5660_DRC2_LM_CTRL1: 2728c2ecf20Sopenharmony_ci case RT5660_DRC2_LM_CTRL2: 2738c2ecf20Sopenharmony_ci case RT5660_MULTI_DRC_CTRL: 2748c2ecf20Sopenharmony_ci case RT5660_DRC2_CTRL1: 2758c2ecf20Sopenharmony_ci case RT5660_DRC2_CTRL2: 2768c2ecf20Sopenharmony_ci case RT5660_DRC2_CTRL3: 2778c2ecf20Sopenharmony_ci case RT5660_DRC2_CTRL4: 2788c2ecf20Sopenharmony_ci case RT5660_DRC2_CTRL5: 2798c2ecf20Sopenharmony_ci case RT5660_ALC_PGA_CTRL1: 2808c2ecf20Sopenharmony_ci case RT5660_ALC_PGA_CTRL2: 2818c2ecf20Sopenharmony_ci case RT5660_ALC_PGA_CTRL3: 2828c2ecf20Sopenharmony_ci case RT5660_ALC_PGA_CTRL4: 2838c2ecf20Sopenharmony_ci case RT5660_ALC_PGA_CTRL5: 2848c2ecf20Sopenharmony_ci case RT5660_ALC_PGA_CTRL6: 2858c2ecf20Sopenharmony_ci case RT5660_ALC_PGA_CTRL7: 2868c2ecf20Sopenharmony_ci case RT5660_GEN_CTRL1: 2878c2ecf20Sopenharmony_ci case RT5660_GEN_CTRL2: 2888c2ecf20Sopenharmony_ci case RT5660_GEN_CTRL3: 2898c2ecf20Sopenharmony_ci case RT5660_VENDOR_ID: 2908c2ecf20Sopenharmony_ci case RT5660_VENDOR_ID1: 2918c2ecf20Sopenharmony_ci case RT5660_VENDOR_ID2: 2928c2ecf20Sopenharmony_ci return true; 2938c2ecf20Sopenharmony_ci default: 2948c2ecf20Sopenharmony_ci return false; 2958c2ecf20Sopenharmony_ci } 2968c2ecf20Sopenharmony_ci} 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(rt5660_out_vol_tlv, -4650, 150, 0); 2998c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(rt5660_dac_vol_tlv, -6525, 75, 0); 3008c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(rt5660_adc_vol_tlv, -1725, 75, 0); 3018c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(rt5660_adc_bst_tlv, 0, 1200, 0); 3028c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(rt5660_bst_tlv, -1200, 75, 0); 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5660_snd_controls[] = { 3058c2ecf20Sopenharmony_ci /* Speaker Output Volume */ 3068c2ecf20Sopenharmony_ci SOC_SINGLE("Speaker Playback Switch", RT5660_SPK_VOL, RT5660_L_MUTE_SFT, 3078c2ecf20Sopenharmony_ci 1, 1), 3088c2ecf20Sopenharmony_ci SOC_SINGLE_TLV("Speaker Playback Volume", RT5660_SPK_VOL, 3098c2ecf20Sopenharmony_ci RT5660_L_VOL_SFT, 39, 1, rt5660_out_vol_tlv), 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci /* OUTPUT Control */ 3128c2ecf20Sopenharmony_ci SOC_DOUBLE("OUT Playback Switch", RT5660_LOUT_VOL, RT5660_L_MUTE_SFT, 3138c2ecf20Sopenharmony_ci RT5660_R_MUTE_SFT, 1, 1), 3148c2ecf20Sopenharmony_ci SOC_DOUBLE_TLV("OUT Playback Volume", RT5660_LOUT_VOL, RT5660_L_VOL_SFT, 3158c2ecf20Sopenharmony_ci RT5660_R_VOL_SFT, 39, 1, rt5660_out_vol_tlv), 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci /* DAC Digital Volume */ 3188c2ecf20Sopenharmony_ci SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5660_DAC1_DIG_VOL, 3198c2ecf20Sopenharmony_ci RT5660_DAC_L1_VOL_SFT, RT5660_DAC_R1_VOL_SFT, 87, 0, 3208c2ecf20Sopenharmony_ci rt5660_dac_vol_tlv), 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci /* IN1/IN2/IN3 Control */ 3238c2ecf20Sopenharmony_ci SOC_SINGLE_TLV("IN1 Boost Volume", RT5660_IN1_IN2, RT5660_BST_SFT1, 69, 3248c2ecf20Sopenharmony_ci 0, rt5660_bst_tlv), 3258c2ecf20Sopenharmony_ci SOC_SINGLE_TLV("IN2 Boost Volume", RT5660_IN1_IN2, RT5660_BST_SFT2, 69, 3268c2ecf20Sopenharmony_ci 0, rt5660_bst_tlv), 3278c2ecf20Sopenharmony_ci SOC_SINGLE_TLV("IN3 Boost Volume", RT5660_IN3_IN4, RT5660_BST_SFT3, 69, 3288c2ecf20Sopenharmony_ci 0, rt5660_bst_tlv), 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci /* ADC Digital Volume Control */ 3318c2ecf20Sopenharmony_ci SOC_DOUBLE("ADC Capture Switch", RT5660_STO1_ADC_DIG_VOL, 3328c2ecf20Sopenharmony_ci RT5660_L_MUTE_SFT, RT5660_R_MUTE_SFT, 1, 1), 3338c2ecf20Sopenharmony_ci SOC_DOUBLE_TLV("ADC Capture Volume", RT5660_STO1_ADC_DIG_VOL, 3348c2ecf20Sopenharmony_ci RT5660_ADC_L_VOL_SFT, RT5660_ADC_R_VOL_SFT, 63, 0, 3358c2ecf20Sopenharmony_ci rt5660_adc_vol_tlv), 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci /* ADC Boost Volume Control */ 3388c2ecf20Sopenharmony_ci SOC_DOUBLE_TLV("STO1 ADC Boost Gain Volume", RT5660_ADC_BST_VOL1, 3398c2ecf20Sopenharmony_ci RT5660_STO1_ADC_L_BST_SFT, RT5660_STO1_ADC_R_BST_SFT, 3, 0, 3408c2ecf20Sopenharmony_ci rt5660_adc_bst_tlv), 3418c2ecf20Sopenharmony_ci}; 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci/** 3448c2ecf20Sopenharmony_ci * rt5660_set_dmic_clk - Set parameter of dmic. 3458c2ecf20Sopenharmony_ci * 3468c2ecf20Sopenharmony_ci * @w: DAPM widget. 3478c2ecf20Sopenharmony_ci * @kcontrol: The kcontrol of this widget. 3488c2ecf20Sopenharmony_ci * @event: Event id. 3498c2ecf20Sopenharmony_ci * 3508c2ecf20Sopenharmony_ci */ 3518c2ecf20Sopenharmony_cistatic int rt5660_set_dmic_clk(struct snd_soc_dapm_widget *w, 3528c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 3538c2ecf20Sopenharmony_ci{ 3548c2ecf20Sopenharmony_ci struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 3558c2ecf20Sopenharmony_ci struct rt5660_priv *rt5660 = snd_soc_component_get_drvdata(component); 3568c2ecf20Sopenharmony_ci int idx, rate; 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_ci rate = rt5660->sysclk / rl6231_get_pre_div(rt5660->regmap, 3598c2ecf20Sopenharmony_ci RT5660_ADDA_CLK1, RT5660_I2S_PD1_SFT); 3608c2ecf20Sopenharmony_ci idx = rl6231_calc_dmic_clk(rate); 3618c2ecf20Sopenharmony_ci if (idx < 0) 3628c2ecf20Sopenharmony_ci dev_err(component->dev, "Failed to set DMIC clock\n"); 3638c2ecf20Sopenharmony_ci else 3648c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5660_DMIC_CTRL1, 3658c2ecf20Sopenharmony_ci RT5660_DMIC_CLK_MASK, idx << RT5660_DMIC_CLK_SFT); 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci return idx; 3688c2ecf20Sopenharmony_ci} 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_cistatic int rt5660_is_sys_clk_from_pll(struct snd_soc_dapm_widget *source, 3718c2ecf20Sopenharmony_ci struct snd_soc_dapm_widget *sink) 3728c2ecf20Sopenharmony_ci{ 3738c2ecf20Sopenharmony_ci struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); 3748c2ecf20Sopenharmony_ci unsigned int val; 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci val = snd_soc_component_read(component, RT5660_GLB_CLK); 3778c2ecf20Sopenharmony_ci val &= RT5660_SCLK_SRC_MASK; 3788c2ecf20Sopenharmony_ci if (val == RT5660_SCLK_SRC_PLL1) 3798c2ecf20Sopenharmony_ci return 1; 3808c2ecf20Sopenharmony_ci else 3818c2ecf20Sopenharmony_ci return 0; 3828c2ecf20Sopenharmony_ci} 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ci/* Digital Mixer */ 3858c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5660_sto1_adc_l_mix[] = { 3868c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("ADC1 Switch", RT5660_STO1_ADC_MIXER, 3878c2ecf20Sopenharmony_ci RT5660_M_ADC_L1_SFT, 1, 1), 3888c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("ADC2 Switch", RT5660_STO1_ADC_MIXER, 3898c2ecf20Sopenharmony_ci RT5660_M_ADC_L2_SFT, 1, 1), 3908c2ecf20Sopenharmony_ci}; 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5660_sto1_adc_r_mix[] = { 3938c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("ADC1 Switch", RT5660_STO1_ADC_MIXER, 3948c2ecf20Sopenharmony_ci RT5660_M_ADC_R1_SFT, 1, 1), 3958c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("ADC2 Switch", RT5660_STO1_ADC_MIXER, 3968c2ecf20Sopenharmony_ci RT5660_M_ADC_R2_SFT, 1, 1), 3978c2ecf20Sopenharmony_ci}; 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5660_dac_l_mix[] = { 4008c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("Stereo ADC Switch", RT5660_AD_DA_MIXER, 4018c2ecf20Sopenharmony_ci RT5660_M_ADCMIX_L_SFT, 1, 1), 4028c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC1 Switch", RT5660_AD_DA_MIXER, 4038c2ecf20Sopenharmony_ci RT5660_M_DAC1_L_SFT, 1, 1), 4048c2ecf20Sopenharmony_ci}; 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5660_dac_r_mix[] = { 4078c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("Stereo ADC Switch", RT5660_AD_DA_MIXER, 4088c2ecf20Sopenharmony_ci RT5660_M_ADCMIX_R_SFT, 1, 1), 4098c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC1 Switch", RT5660_AD_DA_MIXER, 4108c2ecf20Sopenharmony_ci RT5660_M_DAC1_R_SFT, 1, 1), 4118c2ecf20Sopenharmony_ci}; 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5660_sto_dac_l_mix[] = { 4148c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC L1 Switch", RT5660_STO_DAC_MIXER, 4158c2ecf20Sopenharmony_ci RT5660_M_DAC_L1_SFT, 1, 1), 4168c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC R1 Switch", RT5660_STO_DAC_MIXER, 4178c2ecf20Sopenharmony_ci RT5660_M_DAC_R1_STO_L_SFT, 1, 1), 4188c2ecf20Sopenharmony_ci}; 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5660_sto_dac_r_mix[] = { 4218c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC R1 Switch", RT5660_STO_DAC_MIXER, 4228c2ecf20Sopenharmony_ci RT5660_M_DAC_R1_SFT, 1, 1), 4238c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC L1 Switch", RT5660_STO_DAC_MIXER, 4248c2ecf20Sopenharmony_ci RT5660_M_DAC_L1_STO_R_SFT, 1, 1), 4258c2ecf20Sopenharmony_ci}; 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ci/* Analog Input Mixer */ 4288c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5660_rec_l_mix[] = { 4298c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST3 Switch", RT5660_REC_L2_MIXER, 4308c2ecf20Sopenharmony_ci RT5660_M_BST3_RM_L_SFT, 1, 1), 4318c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST2 Switch", RT5660_REC_L2_MIXER, 4328c2ecf20Sopenharmony_ci RT5660_M_BST2_RM_L_SFT, 1, 1), 4338c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST1 Switch", RT5660_REC_L2_MIXER, 4348c2ecf20Sopenharmony_ci RT5660_M_BST1_RM_L_SFT, 1, 1), 4358c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("OUT MIXL Switch", RT5660_REC_L2_MIXER, 4368c2ecf20Sopenharmony_ci RT5660_M_OM_L_RM_L_SFT, 1, 1), 4378c2ecf20Sopenharmony_ci}; 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5660_rec_r_mix[] = { 4408c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST3 Switch", RT5660_REC_R2_MIXER, 4418c2ecf20Sopenharmony_ci RT5660_M_BST3_RM_R_SFT, 1, 1), 4428c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST2 Switch", RT5660_REC_R2_MIXER, 4438c2ecf20Sopenharmony_ci RT5660_M_BST2_RM_R_SFT, 1, 1), 4448c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST1 Switch", RT5660_REC_R2_MIXER, 4458c2ecf20Sopenharmony_ci RT5660_M_BST1_RM_R_SFT, 1, 1), 4468c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("OUT MIXR Switch", RT5660_REC_R2_MIXER, 4478c2ecf20Sopenharmony_ci RT5660_M_OM_R_RM_R_SFT, 1, 1), 4488c2ecf20Sopenharmony_ci}; 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5660_spk_mix[] = { 4518c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST3 Switch", RT5660_SPK_MIXER, 4528c2ecf20Sopenharmony_ci RT5660_M_BST3_SM_SFT, 1, 1), 4538c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST1 Switch", RT5660_SPK_MIXER, 4548c2ecf20Sopenharmony_ci RT5660_M_BST1_SM_SFT, 1, 1), 4558c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DACL Switch", RT5660_SPK_MIXER, 4568c2ecf20Sopenharmony_ci RT5660_M_DACL_SM_SFT, 1, 1), 4578c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DACR Switch", RT5660_SPK_MIXER, 4588c2ecf20Sopenharmony_ci RT5660_M_DACR_SM_SFT, 1, 1), 4598c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("OUTMIXL Switch", RT5660_SPK_MIXER, 4608c2ecf20Sopenharmony_ci RT5660_M_OM_L_SM_SFT, 1, 1), 4618c2ecf20Sopenharmony_ci}; 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5660_out_l_mix[] = { 4648c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST3 Switch", RT5660_OUT_L1_MIXER, 4658c2ecf20Sopenharmony_ci RT5660_M_BST3_OM_L_SFT, 1, 1), 4668c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST2 Switch", RT5660_OUT_L1_MIXER, 4678c2ecf20Sopenharmony_ci RT5660_M_BST2_OM_L_SFT, 1, 1), 4688c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST1 Switch", RT5660_OUT_L1_MIXER, 4698c2ecf20Sopenharmony_ci RT5660_M_BST1_OM_L_SFT, 1, 1), 4708c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("RECMIXL Switch", RT5660_OUT_L1_MIXER, 4718c2ecf20Sopenharmony_ci RT5660_M_RM_L_OM_L_SFT, 1, 1), 4728c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DACR Switch", RT5660_OUT_L1_MIXER, 4738c2ecf20Sopenharmony_ci RT5660_M_DAC_R_OM_L_SFT, 1, 1), 4748c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DACL Switch", RT5660_OUT_L1_MIXER, 4758c2ecf20Sopenharmony_ci RT5660_M_DAC_L_OM_L_SFT, 1, 1), 4768c2ecf20Sopenharmony_ci}; 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5660_out_r_mix[] = { 4798c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST2 Switch", RT5660_OUT_R1_MIXER, 4808c2ecf20Sopenharmony_ci RT5660_M_BST2_OM_R_SFT, 1, 1), 4818c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST1 Switch", RT5660_OUT_R1_MIXER, 4828c2ecf20Sopenharmony_ci RT5660_M_BST1_OM_R_SFT, 1, 1), 4838c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("RECMIXR Switch", RT5660_OUT_R1_MIXER, 4848c2ecf20Sopenharmony_ci RT5660_M_RM_R_OM_R_SFT, 1, 1), 4858c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DACR Switch", RT5660_OUT_R1_MIXER, 4868c2ecf20Sopenharmony_ci RT5660_M_DAC_R_OM_R_SFT, 1, 1), 4878c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DACL Switch", RT5660_OUT_R1_MIXER, 4888c2ecf20Sopenharmony_ci RT5660_M_DAC_L_OM_R_SFT, 1, 1), 4898c2ecf20Sopenharmony_ci}; 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5660_spo_mix[] = { 4928c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DACR Switch", RT5660_SPO_MIXER, 4938c2ecf20Sopenharmony_ci RT5660_M_DAC_R_SPM_SFT, 1, 1), 4948c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DACL Switch", RT5660_SPO_MIXER, 4958c2ecf20Sopenharmony_ci RT5660_M_DAC_L_SPM_SFT, 1, 1), 4968c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("SPKVOL Switch", RT5660_SPO_MIXER, 4978c2ecf20Sopenharmony_ci RT5660_M_SV_SPM_SFT, 1, 1), 4988c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("BST1 Switch", RT5660_SPO_MIXER, 4998c2ecf20Sopenharmony_ci RT5660_M_BST1_SPM_SFT, 1, 1), 5008c2ecf20Sopenharmony_ci}; 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5660_lout_mix[] = { 5038c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC Switch", RT5660_LOUT_MIXER, 5048c2ecf20Sopenharmony_ci RT5660_M_DAC1_LM_SFT, 1, 1), 5058c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("OUTMIX Switch", RT5660_LOUT_MIXER, 5068c2ecf20Sopenharmony_ci RT5660_M_LOVOL_LM_SFT, 1, 1), 5078c2ecf20Sopenharmony_ci}; 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new spk_vol_control = 5108c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("Switch", RT5660_SPK_VOL, 5118c2ecf20Sopenharmony_ci RT5660_VOL_L_SFT, 1, 1); 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new lout_l_vol_control = 5148c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("Switch", RT5660_LOUT_VOL, 5158c2ecf20Sopenharmony_ci RT5660_VOL_L_SFT, 1, 1); 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new lout_r_vol_control = 5188c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("Switch", RT5660_LOUT_VOL, 5198c2ecf20Sopenharmony_ci RT5660_VOL_R_SFT, 1, 1); 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ci/* Interface data select */ 5228c2ecf20Sopenharmony_cistatic const char * const rt5660_data_select[] = { 5238c2ecf20Sopenharmony_ci "L/R", "R/L", "L/L", "R/R" 5248c2ecf20Sopenharmony_ci}; 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5660_if1_dac_enum, 5278c2ecf20Sopenharmony_ci RT5660_DIG_INF1_DATA, RT5660_IF1_DAC_IN_SFT, rt5660_data_select); 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5660_if1_adc_enum, 5308c2ecf20Sopenharmony_ci RT5660_DIG_INF1_DATA, RT5660_IF1_ADC_IN_SFT, rt5660_data_select); 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5660_if1_dac_swap_mux = 5338c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("IF1 DAC Swap Source", rt5660_if1_dac_enum); 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5660_if1_adc_swap_mux = 5368c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("IF1 ADC Swap Source", rt5660_if1_adc_enum); 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_cistatic int rt5660_lout_event(struct snd_soc_dapm_widget *w, 5398c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 5408c2ecf20Sopenharmony_ci{ 5418c2ecf20Sopenharmony_ci struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci switch (event) { 5448c2ecf20Sopenharmony_ci case SND_SOC_DAPM_POST_PMU: 5458c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5660_LOUT_AMP_CTRL, 5468c2ecf20Sopenharmony_ci RT5660_LOUT_CO_MASK | RT5660_LOUT_CB_MASK, 5478c2ecf20Sopenharmony_ci RT5660_LOUT_CO_EN | RT5660_LOUT_CB_PU); 5488c2ecf20Sopenharmony_ci break; 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci case SND_SOC_DAPM_PRE_PMD: 5518c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5660_LOUT_AMP_CTRL, 5528c2ecf20Sopenharmony_ci RT5660_LOUT_CO_MASK | RT5660_LOUT_CB_MASK, 5538c2ecf20Sopenharmony_ci RT5660_LOUT_CO_DIS | RT5660_LOUT_CB_PD); 5548c2ecf20Sopenharmony_ci break; 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci default: 5578c2ecf20Sopenharmony_ci return 0; 5588c2ecf20Sopenharmony_ci } 5598c2ecf20Sopenharmony_ci 5608c2ecf20Sopenharmony_ci return 0; 5618c2ecf20Sopenharmony_ci} 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget rt5660_dapm_widgets[] = { 5648c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("LDO2", RT5660_PWR_ANLG1, 5658c2ecf20Sopenharmony_ci RT5660_PWR_LDO2_BIT, 0, NULL, 0), 5668c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("PLL1", RT5660_PWR_ANLG2, 5678c2ecf20Sopenharmony_ci RT5660_PWR_PLL_BIT, 0, NULL, 0), 5688c2ecf20Sopenharmony_ci 5698c2ecf20Sopenharmony_ci /* MICBIAS */ 5708c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("MICBIAS1", RT5660_PWR_ANLG2, 5718c2ecf20Sopenharmony_ci RT5660_PWR_MB1_BIT, 0, NULL, 0), 5728c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("MICBIAS2", RT5660_PWR_ANLG2, 5738c2ecf20Sopenharmony_ci RT5660_PWR_MB2_BIT, 0, NULL, 0), 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci /* Input Side */ 5768c2ecf20Sopenharmony_ci /* Input Lines */ 5778c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("DMIC L1"), 5788c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("DMIC R1"), 5798c2ecf20Sopenharmony_ci 5808c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("IN1P"), 5818c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("IN1N"), 5828c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("IN2P"), 5838c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("IN3P"), 5848c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("IN3N"), 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("DMIC CLK", SND_SOC_NOPM, 0, 0, 5878c2ecf20Sopenharmony_ci rt5660_set_dmic_clk, SND_SOC_DAPM_PRE_PMU), 5888c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("DMIC Power", RT5660_DMIC_CTRL1, 5898c2ecf20Sopenharmony_ci RT5660_DMIC_1_EN_SFT, 0, NULL, 0), 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_ci /* Boost */ 5928c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("BST1", RT5660_PWR_ANLG2, RT5660_PWR_BST1_BIT, 0, 5938c2ecf20Sopenharmony_ci NULL, 0), 5948c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("BST2", RT5660_PWR_ANLG2, RT5660_PWR_BST2_BIT, 0, 5958c2ecf20Sopenharmony_ci NULL, 0), 5968c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("BST3", RT5660_PWR_ANLG2, RT5660_PWR_BST3_BIT, 0, 5978c2ecf20Sopenharmony_ci NULL, 0), 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_ci /* REC Mixer */ 6008c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("RECMIXL", RT5660_PWR_MIXER, RT5660_PWR_RM_L_BIT, 6018c2ecf20Sopenharmony_ci 0, rt5660_rec_l_mix, ARRAY_SIZE(rt5660_rec_l_mix)), 6028c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("RECMIXR", RT5660_PWR_MIXER, RT5660_PWR_RM_R_BIT, 6038c2ecf20Sopenharmony_ci 0, rt5660_rec_r_mix, ARRAY_SIZE(rt5660_rec_r_mix)), 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci /* ADCs */ 6068c2ecf20Sopenharmony_ci SND_SOC_DAPM_ADC("ADC L", NULL, SND_SOC_NOPM, 0, 0), 6078c2ecf20Sopenharmony_ci SND_SOC_DAPM_ADC("ADC R", NULL, SND_SOC_NOPM, 0, 0), 6088c2ecf20Sopenharmony_ci 6098c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("ADC L power", RT5660_PWR_DIG1, 6108c2ecf20Sopenharmony_ci RT5660_PWR_ADC_L_BIT, 0, NULL, 0), 6118c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("ADC R power", RT5660_PWR_DIG1, 6128c2ecf20Sopenharmony_ci RT5660_PWR_ADC_R_BIT, 0, NULL, 0), 6138c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("ADC clock", RT5660_PR_BASE + RT5660_CHOP_DAC_ADC, 6148c2ecf20Sopenharmony_ci 12, 0, NULL, 0), 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_ci /* ADC Mixer */ 6178c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("adc stereo1 filter", RT5660_PWR_DIG2, 6188c2ecf20Sopenharmony_ci RT5660_PWR_ADC_S1F_BIT, 0, NULL, 0), 6198c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("Sto1 ADC MIXL", SND_SOC_NOPM, 0, 0, 6208c2ecf20Sopenharmony_ci rt5660_sto1_adc_l_mix, ARRAY_SIZE(rt5660_sto1_adc_l_mix)), 6218c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("Sto1 ADC MIXR", SND_SOC_NOPM, 0, 0, 6228c2ecf20Sopenharmony_ci rt5660_sto1_adc_r_mix, ARRAY_SIZE(rt5660_sto1_adc_r_mix)), 6238c2ecf20Sopenharmony_ci 6248c2ecf20Sopenharmony_ci /* ADC */ 6258c2ecf20Sopenharmony_ci SND_SOC_DAPM_ADC("Stereo1 ADC MIXL", NULL, RT5660_STO1_ADC_DIG_VOL, 6268c2ecf20Sopenharmony_ci RT5660_L_MUTE_SFT, 1), 6278c2ecf20Sopenharmony_ci SND_SOC_DAPM_ADC("Stereo1 ADC MIXR", NULL, RT5660_STO1_ADC_DIG_VOL, 6288c2ecf20Sopenharmony_ci RT5660_R_MUTE_SFT, 1), 6298c2ecf20Sopenharmony_ci 6308c2ecf20Sopenharmony_ci /* Digital Interface */ 6318c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("I2S1", RT5660_PWR_DIG1, RT5660_PWR_I2S1_BIT, 0, 6328c2ecf20Sopenharmony_ci NULL, 0), 6338c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("IF1 DAC", SND_SOC_NOPM, 0, 0, NULL, 0), 6348c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("IF1 DAC L", SND_SOC_NOPM, 0, 0, NULL, 0), 6358c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("IF1 DAC R", SND_SOC_NOPM, 0, 0, NULL, 0), 6368c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("IF1 DAC Swap Mux", SND_SOC_NOPM, 0, 0, 6378c2ecf20Sopenharmony_ci &rt5660_if1_dac_swap_mux), 6388c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("IF1 ADC", SND_SOC_NOPM, 0, 0, NULL, 0), 6398c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("IF1 ADC Swap Mux", SND_SOC_NOPM, 0, 0, 6408c2ecf20Sopenharmony_ci &rt5660_if1_adc_swap_mux), 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_ci /* Audio Interface */ 6438c2ecf20Sopenharmony_ci SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), 6448c2ecf20Sopenharmony_ci SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0), 6458c2ecf20Sopenharmony_ci 6468c2ecf20Sopenharmony_ci /* Output Side */ 6478c2ecf20Sopenharmony_ci /* DAC mixer before sound effect */ 6488c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("DAC1 MIXL", SND_SOC_NOPM, 0, 0, rt5660_dac_l_mix, 6498c2ecf20Sopenharmony_ci ARRAY_SIZE(rt5660_dac_l_mix)), 6508c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("DAC1 MIXR", SND_SOC_NOPM, 0, 0, rt5660_dac_r_mix, 6518c2ecf20Sopenharmony_ci ARRAY_SIZE(rt5660_dac_r_mix)), 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci /* DAC Mixer */ 6548c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("dac stereo1 filter", RT5660_PWR_DIG2, 6558c2ecf20Sopenharmony_ci RT5660_PWR_DAC_S1F_BIT, 0, NULL, 0), 6568c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("Stereo DAC MIXL", SND_SOC_NOPM, 0, 0, 6578c2ecf20Sopenharmony_ci rt5660_sto_dac_l_mix, ARRAY_SIZE(rt5660_sto_dac_l_mix)), 6588c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("Stereo DAC MIXR", SND_SOC_NOPM, 0, 0, 6598c2ecf20Sopenharmony_ci rt5660_sto_dac_r_mix, ARRAY_SIZE(rt5660_sto_dac_r_mix)), 6608c2ecf20Sopenharmony_ci 6618c2ecf20Sopenharmony_ci /* DACs */ 6628c2ecf20Sopenharmony_ci SND_SOC_DAPM_DAC("DAC L1", NULL, RT5660_PWR_DIG1, 6638c2ecf20Sopenharmony_ci RT5660_PWR_DAC_L1_BIT, 0), 6648c2ecf20Sopenharmony_ci SND_SOC_DAPM_DAC("DAC R1", NULL, RT5660_PWR_DIG1, 6658c2ecf20Sopenharmony_ci RT5660_PWR_DAC_R1_BIT, 0), 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_ci /* OUT Mixer */ 6688c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("SPK MIX", RT5660_PWR_MIXER, RT5660_PWR_SM_BIT, 6698c2ecf20Sopenharmony_ci 0, rt5660_spk_mix, ARRAY_SIZE(rt5660_spk_mix)), 6708c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("OUT MIXL", RT5660_PWR_MIXER, RT5660_PWR_OM_L_BIT, 6718c2ecf20Sopenharmony_ci 0, rt5660_out_l_mix, ARRAY_SIZE(rt5660_out_l_mix)), 6728c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("OUT MIXR", RT5660_PWR_MIXER, RT5660_PWR_OM_R_BIT, 6738c2ecf20Sopenharmony_ci 0, rt5660_out_r_mix, ARRAY_SIZE(rt5660_out_r_mix)), 6748c2ecf20Sopenharmony_ci 6758c2ecf20Sopenharmony_ci /* Output Volume */ 6768c2ecf20Sopenharmony_ci SND_SOC_DAPM_SWITCH("SPKVOL", RT5660_PWR_VOL, 6778c2ecf20Sopenharmony_ci RT5660_PWR_SV_BIT, 0, &spk_vol_control), 6788c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("DAC 1", SND_SOC_NOPM, 6798c2ecf20Sopenharmony_ci 0, 0, NULL, 0), 6808c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("LOUTVOL", SND_SOC_NOPM, 6818c2ecf20Sopenharmony_ci 0, 0, NULL, 0), 6828c2ecf20Sopenharmony_ci SND_SOC_DAPM_SWITCH("LOUTVOL L", SND_SOC_NOPM, 6838c2ecf20Sopenharmony_ci RT5660_PWR_LV_L_BIT, 0, &lout_l_vol_control), 6848c2ecf20Sopenharmony_ci SND_SOC_DAPM_SWITCH("LOUTVOL R", SND_SOC_NOPM, 6858c2ecf20Sopenharmony_ci RT5660_PWR_LV_R_BIT, 0, &lout_r_vol_control), 6868c2ecf20Sopenharmony_ci 6878c2ecf20Sopenharmony_ci /* HPO/LOUT/Mono Mixer */ 6888c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("SPO MIX", SND_SOC_NOPM, 0, 6898c2ecf20Sopenharmony_ci 0, rt5660_spo_mix, ARRAY_SIZE(rt5660_spo_mix)), 6908c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("LOUT MIX", SND_SOC_NOPM, 0, 0, 6918c2ecf20Sopenharmony_ci rt5660_lout_mix, ARRAY_SIZE(rt5660_lout_mix)), 6928c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("VREF HP", RT5660_GEN_CTRL1, 6938c2ecf20Sopenharmony_ci RT5660_PWR_VREF_HP_SFT, 0, NULL, 0), 6948c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA_S("LOUT amp", 1, RT5660_PWR_ANLG1, 6958c2ecf20Sopenharmony_ci RT5660_PWR_HA_BIT, 0, rt5660_lout_event, 6968c2ecf20Sopenharmony_ci SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 6978c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA_S("SPK amp", 1, RT5660_PWR_DIG1, 6988c2ecf20Sopenharmony_ci RT5660_PWR_CLS_D_BIT, 0, NULL, 0), 6998c2ecf20Sopenharmony_ci 7008c2ecf20Sopenharmony_ci /* Output Lines */ 7018c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("LOUTL"), 7028c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("LOUTR"), 7038c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("SPO"), 7048c2ecf20Sopenharmony_ci}; 7058c2ecf20Sopenharmony_ci 7068c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route rt5660_dapm_routes[] = { 7078c2ecf20Sopenharmony_ci { "MICBIAS1", NULL, "LDO2" }, 7088c2ecf20Sopenharmony_ci { "MICBIAS2", NULL, "LDO2" }, 7098c2ecf20Sopenharmony_ci 7108c2ecf20Sopenharmony_ci { "BST1", NULL, "IN1P" }, 7118c2ecf20Sopenharmony_ci { "BST1", NULL, "IN1N" }, 7128c2ecf20Sopenharmony_ci { "BST2", NULL, "IN2P" }, 7138c2ecf20Sopenharmony_ci { "BST3", NULL, "IN3P" }, 7148c2ecf20Sopenharmony_ci { "BST3", NULL, "IN3N" }, 7158c2ecf20Sopenharmony_ci 7168c2ecf20Sopenharmony_ci { "RECMIXL", "BST3 Switch", "BST3" }, 7178c2ecf20Sopenharmony_ci { "RECMIXL", "BST2 Switch", "BST2" }, 7188c2ecf20Sopenharmony_ci { "RECMIXL", "BST1 Switch", "BST1" }, 7198c2ecf20Sopenharmony_ci { "RECMIXL", "OUT MIXL Switch", "OUT MIXL" }, 7208c2ecf20Sopenharmony_ci 7218c2ecf20Sopenharmony_ci { "RECMIXR", "BST3 Switch", "BST3" }, 7228c2ecf20Sopenharmony_ci { "RECMIXR", "BST2 Switch", "BST2" }, 7238c2ecf20Sopenharmony_ci { "RECMIXR", "BST1 Switch", "BST1" }, 7248c2ecf20Sopenharmony_ci { "RECMIXR", "OUT MIXR Switch", "OUT MIXR" }, 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_ci { "ADC L", NULL, "RECMIXL" }, 7278c2ecf20Sopenharmony_ci { "ADC L", NULL, "ADC L power" }, 7288c2ecf20Sopenharmony_ci { "ADC L", NULL, "ADC clock" }, 7298c2ecf20Sopenharmony_ci { "ADC R", NULL, "RECMIXR" }, 7308c2ecf20Sopenharmony_ci { "ADC R", NULL, "ADC R power" }, 7318c2ecf20Sopenharmony_ci { "ADC R", NULL, "ADC clock" }, 7328c2ecf20Sopenharmony_ci 7338c2ecf20Sopenharmony_ci {"DMIC L1", NULL, "DMIC CLK"}, 7348c2ecf20Sopenharmony_ci {"DMIC L1", NULL, "DMIC Power"}, 7358c2ecf20Sopenharmony_ci {"DMIC R1", NULL, "DMIC CLK"}, 7368c2ecf20Sopenharmony_ci {"DMIC R1", NULL, "DMIC Power"}, 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_ci { "Sto1 ADC MIXL", "ADC1 Switch", "ADC L" }, 7398c2ecf20Sopenharmony_ci { "Sto1 ADC MIXL", "ADC2 Switch", "DMIC L1" }, 7408c2ecf20Sopenharmony_ci { "Sto1 ADC MIXR", "ADC1 Switch", "ADC R" }, 7418c2ecf20Sopenharmony_ci { "Sto1 ADC MIXR", "ADC2 Switch", "DMIC R1" }, 7428c2ecf20Sopenharmony_ci 7438c2ecf20Sopenharmony_ci { "Stereo1 ADC MIXL", NULL, "Sto1 ADC MIXL" }, 7448c2ecf20Sopenharmony_ci { "Stereo1 ADC MIXL", NULL, "adc stereo1 filter" }, 7458c2ecf20Sopenharmony_ci { "adc stereo1 filter", NULL, "PLL1", rt5660_is_sys_clk_from_pll }, 7468c2ecf20Sopenharmony_ci 7478c2ecf20Sopenharmony_ci { "Stereo1 ADC MIXR", NULL, "Sto1 ADC MIXR" }, 7488c2ecf20Sopenharmony_ci { "Stereo1 ADC MIXR", NULL, "adc stereo1 filter" }, 7498c2ecf20Sopenharmony_ci { "adc stereo1 filter", NULL, "PLL1", rt5660_is_sys_clk_from_pll }, 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci { "IF1 ADC", NULL, "Stereo1 ADC MIXL" }, 7528c2ecf20Sopenharmony_ci { "IF1 ADC", NULL, "Stereo1 ADC MIXR" }, 7538c2ecf20Sopenharmony_ci { "IF1 ADC", NULL, "I2S1" }, 7548c2ecf20Sopenharmony_ci 7558c2ecf20Sopenharmony_ci { "IF1 ADC Swap Mux", "L/R", "IF1 ADC" }, 7568c2ecf20Sopenharmony_ci { "IF1 ADC Swap Mux", "R/L", "IF1 ADC" }, 7578c2ecf20Sopenharmony_ci { "IF1 ADC Swap Mux", "L/L", "IF1 ADC" }, 7588c2ecf20Sopenharmony_ci { "IF1 ADC Swap Mux", "R/R", "IF1 ADC" }, 7598c2ecf20Sopenharmony_ci { "AIF1TX", NULL, "IF1 ADC Swap Mux" }, 7608c2ecf20Sopenharmony_ci 7618c2ecf20Sopenharmony_ci { "IF1 DAC", NULL, "AIF1RX" }, 7628c2ecf20Sopenharmony_ci { "IF1 DAC", NULL, "I2S1" }, 7638c2ecf20Sopenharmony_ci 7648c2ecf20Sopenharmony_ci { "IF1 DAC Swap Mux", "L/R", "IF1 DAC" }, 7658c2ecf20Sopenharmony_ci { "IF1 DAC Swap Mux", "R/L", "IF1 DAC" }, 7668c2ecf20Sopenharmony_ci { "IF1 DAC Swap Mux", "L/L", "IF1 DAC" }, 7678c2ecf20Sopenharmony_ci { "IF1 DAC Swap Mux", "R/R", "IF1 DAC" }, 7688c2ecf20Sopenharmony_ci 7698c2ecf20Sopenharmony_ci { "IF1 DAC L", NULL, "IF1 DAC Swap Mux" }, 7708c2ecf20Sopenharmony_ci { "IF1 DAC R", NULL, "IF1 DAC Swap Mux" }, 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_ci { "DAC1 MIXL", "Stereo ADC Switch", "Stereo1 ADC MIXL" }, 7738c2ecf20Sopenharmony_ci { "DAC1 MIXL", "DAC1 Switch", "IF1 DAC L" }, 7748c2ecf20Sopenharmony_ci { "DAC1 MIXR", "Stereo ADC Switch", "Stereo1 ADC MIXR" }, 7758c2ecf20Sopenharmony_ci { "DAC1 MIXR", "DAC1 Switch", "IF1 DAC R" }, 7768c2ecf20Sopenharmony_ci 7778c2ecf20Sopenharmony_ci { "Stereo DAC MIXL", "DAC L1 Switch", "DAC1 MIXL" }, 7788c2ecf20Sopenharmony_ci { "Stereo DAC MIXL", "DAC R1 Switch", "DAC1 MIXR" }, 7798c2ecf20Sopenharmony_ci { "Stereo DAC MIXL", NULL, "dac stereo1 filter" }, 7808c2ecf20Sopenharmony_ci { "dac stereo1 filter", NULL, "PLL1", rt5660_is_sys_clk_from_pll }, 7818c2ecf20Sopenharmony_ci { "Stereo DAC MIXR", "DAC R1 Switch", "DAC1 MIXR" }, 7828c2ecf20Sopenharmony_ci { "Stereo DAC MIXR", "DAC L1 Switch", "DAC1 MIXL" }, 7838c2ecf20Sopenharmony_ci { "Stereo DAC MIXR", NULL, "dac stereo1 filter" }, 7848c2ecf20Sopenharmony_ci { "dac stereo1 filter", NULL, "PLL1", rt5660_is_sys_clk_from_pll }, 7858c2ecf20Sopenharmony_ci 7868c2ecf20Sopenharmony_ci { "DAC L1", NULL, "Stereo DAC MIXL" }, 7878c2ecf20Sopenharmony_ci { "DAC R1", NULL, "Stereo DAC MIXR" }, 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_ci { "SPK MIX", "BST3 Switch", "BST3" }, 7908c2ecf20Sopenharmony_ci { "SPK MIX", "BST1 Switch", "BST1" }, 7918c2ecf20Sopenharmony_ci { "SPK MIX", "DACL Switch", "DAC L1" }, 7928c2ecf20Sopenharmony_ci { "SPK MIX", "DACR Switch", "DAC R1" }, 7938c2ecf20Sopenharmony_ci { "SPK MIX", "OUTMIXL Switch", "OUT MIXL" }, 7948c2ecf20Sopenharmony_ci 7958c2ecf20Sopenharmony_ci { "OUT MIXL", "BST3 Switch", "BST3" }, 7968c2ecf20Sopenharmony_ci { "OUT MIXL", "BST2 Switch", "BST2" }, 7978c2ecf20Sopenharmony_ci { "OUT MIXL", "BST1 Switch", "BST1" }, 7988c2ecf20Sopenharmony_ci { "OUT MIXL", "RECMIXL Switch", "RECMIXL" }, 7998c2ecf20Sopenharmony_ci { "OUT MIXL", "DACR Switch", "DAC R1" }, 8008c2ecf20Sopenharmony_ci { "OUT MIXL", "DACL Switch", "DAC L1" }, 8018c2ecf20Sopenharmony_ci 8028c2ecf20Sopenharmony_ci { "OUT MIXR", "BST2 Switch", "BST2" }, 8038c2ecf20Sopenharmony_ci { "OUT MIXR", "BST1 Switch", "BST1" }, 8048c2ecf20Sopenharmony_ci { "OUT MIXR", "RECMIXR Switch", "RECMIXR" }, 8058c2ecf20Sopenharmony_ci { "OUT MIXR", "DACR Switch", "DAC R1" }, 8068c2ecf20Sopenharmony_ci { "OUT MIXR", "DACL Switch", "DAC L1" }, 8078c2ecf20Sopenharmony_ci 8088c2ecf20Sopenharmony_ci { "SPO MIX", "DACR Switch", "DAC R1" }, 8098c2ecf20Sopenharmony_ci { "SPO MIX", "DACL Switch", "DAC L1" }, 8108c2ecf20Sopenharmony_ci { "SPO MIX", "SPKVOL Switch", "SPKVOL" }, 8118c2ecf20Sopenharmony_ci { "SPO MIX", "BST1 Switch", "BST1" }, 8128c2ecf20Sopenharmony_ci 8138c2ecf20Sopenharmony_ci { "SPKVOL", "Switch", "SPK MIX" }, 8148c2ecf20Sopenharmony_ci { "LOUTVOL L", "Switch", "OUT MIXL" }, 8158c2ecf20Sopenharmony_ci { "LOUTVOL R", "Switch", "OUT MIXR" }, 8168c2ecf20Sopenharmony_ci 8178c2ecf20Sopenharmony_ci { "LOUTVOL", NULL, "LOUTVOL L" }, 8188c2ecf20Sopenharmony_ci { "LOUTVOL", NULL, "LOUTVOL R" }, 8198c2ecf20Sopenharmony_ci 8208c2ecf20Sopenharmony_ci { "DAC 1", NULL, "DAC L1" }, 8218c2ecf20Sopenharmony_ci { "DAC 1", NULL, "DAC R1" }, 8228c2ecf20Sopenharmony_ci 8238c2ecf20Sopenharmony_ci { "LOUT MIX", "DAC Switch", "DAC 1" }, 8248c2ecf20Sopenharmony_ci { "LOUT MIX", "OUTMIX Switch", "LOUTVOL" }, 8258c2ecf20Sopenharmony_ci 8268c2ecf20Sopenharmony_ci { "LOUT amp", NULL, "LOUT MIX" }, 8278c2ecf20Sopenharmony_ci { "LOUT amp", NULL, "VREF HP" }, 8288c2ecf20Sopenharmony_ci { "LOUTL", NULL, "LOUT amp" }, 8298c2ecf20Sopenharmony_ci { "LOUTR", NULL, "LOUT amp" }, 8308c2ecf20Sopenharmony_ci 8318c2ecf20Sopenharmony_ci { "SPK amp", NULL, "SPO MIX" }, 8328c2ecf20Sopenharmony_ci { "SPO", NULL, "SPK amp" }, 8338c2ecf20Sopenharmony_ci}; 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_cistatic int rt5660_hw_params(struct snd_pcm_substream *substream, 8368c2ecf20Sopenharmony_ci struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 8378c2ecf20Sopenharmony_ci{ 8388c2ecf20Sopenharmony_ci struct snd_soc_component *component = dai->component; 8398c2ecf20Sopenharmony_ci struct rt5660_priv *rt5660 = snd_soc_component_get_drvdata(component); 8408c2ecf20Sopenharmony_ci unsigned int val_len = 0, val_clk, mask_clk; 8418c2ecf20Sopenharmony_ci int pre_div, bclk_ms, frame_size; 8428c2ecf20Sopenharmony_ci 8438c2ecf20Sopenharmony_ci rt5660->lrck[dai->id] = params_rate(params); 8448c2ecf20Sopenharmony_ci pre_div = rl6231_get_clk_info(rt5660->sysclk, rt5660->lrck[dai->id]); 8458c2ecf20Sopenharmony_ci if (pre_div < 0) { 8468c2ecf20Sopenharmony_ci dev_err(component->dev, "Unsupported clock setting %d for DAI %d\n", 8478c2ecf20Sopenharmony_ci rt5660->lrck[dai->id], dai->id); 8488c2ecf20Sopenharmony_ci return -EINVAL; 8498c2ecf20Sopenharmony_ci } 8508c2ecf20Sopenharmony_ci 8518c2ecf20Sopenharmony_ci frame_size = snd_soc_params_to_frame_size(params); 8528c2ecf20Sopenharmony_ci if (frame_size < 0) { 8538c2ecf20Sopenharmony_ci dev_err(component->dev, "Unsupported frame size: %d\n", frame_size); 8548c2ecf20Sopenharmony_ci return frame_size; 8558c2ecf20Sopenharmony_ci } 8568c2ecf20Sopenharmony_ci 8578c2ecf20Sopenharmony_ci if (frame_size > 32) 8588c2ecf20Sopenharmony_ci bclk_ms = 1; 8598c2ecf20Sopenharmony_ci else 8608c2ecf20Sopenharmony_ci bclk_ms = 0; 8618c2ecf20Sopenharmony_ci 8628c2ecf20Sopenharmony_ci rt5660->bclk[dai->id] = rt5660->lrck[dai->id] * (32 << bclk_ms); 8638c2ecf20Sopenharmony_ci 8648c2ecf20Sopenharmony_ci dev_dbg(dai->dev, "bclk is %dHz and lrck is %dHz\n", 8658c2ecf20Sopenharmony_ci rt5660->bclk[dai->id], rt5660->lrck[dai->id]); 8668c2ecf20Sopenharmony_ci dev_dbg(dai->dev, "bclk_ms is %d and pre_div is %d for iis %d\n", 8678c2ecf20Sopenharmony_ci bclk_ms, pre_div, dai->id); 8688c2ecf20Sopenharmony_ci 8698c2ecf20Sopenharmony_ci switch (params_width(params)) { 8708c2ecf20Sopenharmony_ci case 16: 8718c2ecf20Sopenharmony_ci break; 8728c2ecf20Sopenharmony_ci case 20: 8738c2ecf20Sopenharmony_ci val_len |= RT5660_I2S_DL_20; 8748c2ecf20Sopenharmony_ci break; 8758c2ecf20Sopenharmony_ci case 24: 8768c2ecf20Sopenharmony_ci val_len |= RT5660_I2S_DL_24; 8778c2ecf20Sopenharmony_ci break; 8788c2ecf20Sopenharmony_ci case 8: 8798c2ecf20Sopenharmony_ci val_len |= RT5660_I2S_DL_8; 8808c2ecf20Sopenharmony_ci break; 8818c2ecf20Sopenharmony_ci default: 8828c2ecf20Sopenharmony_ci return -EINVAL; 8838c2ecf20Sopenharmony_ci } 8848c2ecf20Sopenharmony_ci 8858c2ecf20Sopenharmony_ci switch (dai->id) { 8868c2ecf20Sopenharmony_ci case RT5660_AIF1: 8878c2ecf20Sopenharmony_ci mask_clk = RT5660_I2S_BCLK_MS1_MASK | RT5660_I2S_PD1_MASK; 8888c2ecf20Sopenharmony_ci val_clk = bclk_ms << RT5660_I2S_BCLK_MS1_SFT | 8898c2ecf20Sopenharmony_ci pre_div << RT5660_I2S_PD1_SFT; 8908c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5660_I2S1_SDP, RT5660_I2S_DL_MASK, 8918c2ecf20Sopenharmony_ci val_len); 8928c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5660_ADDA_CLK1, mask_clk, val_clk); 8938c2ecf20Sopenharmony_ci break; 8948c2ecf20Sopenharmony_ci 8958c2ecf20Sopenharmony_ci default: 8968c2ecf20Sopenharmony_ci dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); 8978c2ecf20Sopenharmony_ci return -EINVAL; 8988c2ecf20Sopenharmony_ci } 8998c2ecf20Sopenharmony_ci 9008c2ecf20Sopenharmony_ci return 0; 9018c2ecf20Sopenharmony_ci} 9028c2ecf20Sopenharmony_ci 9038c2ecf20Sopenharmony_cistatic int rt5660_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) 9048c2ecf20Sopenharmony_ci{ 9058c2ecf20Sopenharmony_ci struct snd_soc_component *component = dai->component; 9068c2ecf20Sopenharmony_ci struct rt5660_priv *rt5660 = snd_soc_component_get_drvdata(component); 9078c2ecf20Sopenharmony_ci unsigned int reg_val = 0; 9088c2ecf20Sopenharmony_ci 9098c2ecf20Sopenharmony_ci switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 9108c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_CBM_CFM: 9118c2ecf20Sopenharmony_ci rt5660->master[dai->id] = 1; 9128c2ecf20Sopenharmony_ci break; 9138c2ecf20Sopenharmony_ci 9148c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_CBS_CFS: 9158c2ecf20Sopenharmony_ci reg_val |= RT5660_I2S_MS_S; 9168c2ecf20Sopenharmony_ci rt5660->master[dai->id] = 0; 9178c2ecf20Sopenharmony_ci break; 9188c2ecf20Sopenharmony_ci 9198c2ecf20Sopenharmony_ci default: 9208c2ecf20Sopenharmony_ci return -EINVAL; 9218c2ecf20Sopenharmony_ci } 9228c2ecf20Sopenharmony_ci 9238c2ecf20Sopenharmony_ci switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 9248c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_NB_NF: 9258c2ecf20Sopenharmony_ci break; 9268c2ecf20Sopenharmony_ci 9278c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_IB_NF: 9288c2ecf20Sopenharmony_ci reg_val |= RT5660_I2S_BP_INV; 9298c2ecf20Sopenharmony_ci break; 9308c2ecf20Sopenharmony_ci 9318c2ecf20Sopenharmony_ci default: 9328c2ecf20Sopenharmony_ci return -EINVAL; 9338c2ecf20Sopenharmony_ci } 9348c2ecf20Sopenharmony_ci 9358c2ecf20Sopenharmony_ci switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 9368c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_I2S: 9378c2ecf20Sopenharmony_ci break; 9388c2ecf20Sopenharmony_ci 9398c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_LEFT_J: 9408c2ecf20Sopenharmony_ci reg_val |= RT5660_I2S_DF_LEFT; 9418c2ecf20Sopenharmony_ci break; 9428c2ecf20Sopenharmony_ci 9438c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_DSP_A: 9448c2ecf20Sopenharmony_ci reg_val |= RT5660_I2S_DF_PCM_A; 9458c2ecf20Sopenharmony_ci break; 9468c2ecf20Sopenharmony_ci 9478c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_DSP_B: 9488c2ecf20Sopenharmony_ci reg_val |= RT5660_I2S_DF_PCM_B; 9498c2ecf20Sopenharmony_ci break; 9508c2ecf20Sopenharmony_ci 9518c2ecf20Sopenharmony_ci default: 9528c2ecf20Sopenharmony_ci return -EINVAL; 9538c2ecf20Sopenharmony_ci } 9548c2ecf20Sopenharmony_ci 9558c2ecf20Sopenharmony_ci switch (dai->id) { 9568c2ecf20Sopenharmony_ci case RT5660_AIF1: 9578c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5660_I2S1_SDP, 9588c2ecf20Sopenharmony_ci RT5660_I2S_MS_MASK | RT5660_I2S_BP_MASK | 9598c2ecf20Sopenharmony_ci RT5660_I2S_DF_MASK, reg_val); 9608c2ecf20Sopenharmony_ci break; 9618c2ecf20Sopenharmony_ci 9628c2ecf20Sopenharmony_ci default: 9638c2ecf20Sopenharmony_ci dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); 9648c2ecf20Sopenharmony_ci return -EINVAL; 9658c2ecf20Sopenharmony_ci } 9668c2ecf20Sopenharmony_ci 9678c2ecf20Sopenharmony_ci return 0; 9688c2ecf20Sopenharmony_ci} 9698c2ecf20Sopenharmony_ci 9708c2ecf20Sopenharmony_cistatic int rt5660_set_dai_sysclk(struct snd_soc_dai *dai, 9718c2ecf20Sopenharmony_ci int clk_id, unsigned int freq, int dir) 9728c2ecf20Sopenharmony_ci{ 9738c2ecf20Sopenharmony_ci struct snd_soc_component *component = dai->component; 9748c2ecf20Sopenharmony_ci struct rt5660_priv *rt5660 = snd_soc_component_get_drvdata(component); 9758c2ecf20Sopenharmony_ci unsigned int reg_val = 0; 9768c2ecf20Sopenharmony_ci 9778c2ecf20Sopenharmony_ci if (freq == rt5660->sysclk && clk_id == rt5660->sysclk_src) 9788c2ecf20Sopenharmony_ci return 0; 9798c2ecf20Sopenharmony_ci 9808c2ecf20Sopenharmony_ci switch (clk_id) { 9818c2ecf20Sopenharmony_ci case RT5660_SCLK_S_MCLK: 9828c2ecf20Sopenharmony_ci reg_val |= RT5660_SCLK_SRC_MCLK; 9838c2ecf20Sopenharmony_ci break; 9848c2ecf20Sopenharmony_ci 9858c2ecf20Sopenharmony_ci case RT5660_SCLK_S_PLL1: 9868c2ecf20Sopenharmony_ci reg_val |= RT5660_SCLK_SRC_PLL1; 9878c2ecf20Sopenharmony_ci break; 9888c2ecf20Sopenharmony_ci 9898c2ecf20Sopenharmony_ci case RT5660_SCLK_S_RCCLK: 9908c2ecf20Sopenharmony_ci reg_val |= RT5660_SCLK_SRC_RCCLK; 9918c2ecf20Sopenharmony_ci break; 9928c2ecf20Sopenharmony_ci 9938c2ecf20Sopenharmony_ci default: 9948c2ecf20Sopenharmony_ci dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); 9958c2ecf20Sopenharmony_ci return -EINVAL; 9968c2ecf20Sopenharmony_ci } 9978c2ecf20Sopenharmony_ci 9988c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5660_GLB_CLK, RT5660_SCLK_SRC_MASK, 9998c2ecf20Sopenharmony_ci reg_val); 10008c2ecf20Sopenharmony_ci 10018c2ecf20Sopenharmony_ci rt5660->sysclk = freq; 10028c2ecf20Sopenharmony_ci rt5660->sysclk_src = clk_id; 10038c2ecf20Sopenharmony_ci 10048c2ecf20Sopenharmony_ci dev_dbg(dai->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id); 10058c2ecf20Sopenharmony_ci 10068c2ecf20Sopenharmony_ci return 0; 10078c2ecf20Sopenharmony_ci} 10088c2ecf20Sopenharmony_ci 10098c2ecf20Sopenharmony_cistatic int rt5660_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, 10108c2ecf20Sopenharmony_ci unsigned int freq_in, unsigned int freq_out) 10118c2ecf20Sopenharmony_ci{ 10128c2ecf20Sopenharmony_ci struct snd_soc_component *component = dai->component; 10138c2ecf20Sopenharmony_ci struct rt5660_priv *rt5660 = snd_soc_component_get_drvdata(component); 10148c2ecf20Sopenharmony_ci struct rl6231_pll_code pll_code; 10158c2ecf20Sopenharmony_ci int ret; 10168c2ecf20Sopenharmony_ci 10178c2ecf20Sopenharmony_ci if (source == rt5660->pll_src && freq_in == rt5660->pll_in && 10188c2ecf20Sopenharmony_ci freq_out == rt5660->pll_out) 10198c2ecf20Sopenharmony_ci return 0; 10208c2ecf20Sopenharmony_ci 10218c2ecf20Sopenharmony_ci if (!freq_in || !freq_out) { 10228c2ecf20Sopenharmony_ci dev_dbg(component->dev, "PLL disabled\n"); 10238c2ecf20Sopenharmony_ci 10248c2ecf20Sopenharmony_ci rt5660->pll_in = 0; 10258c2ecf20Sopenharmony_ci rt5660->pll_out = 0; 10268c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5660_GLB_CLK, 10278c2ecf20Sopenharmony_ci RT5660_SCLK_SRC_MASK, RT5660_SCLK_SRC_MCLK); 10288c2ecf20Sopenharmony_ci return 0; 10298c2ecf20Sopenharmony_ci } 10308c2ecf20Sopenharmony_ci 10318c2ecf20Sopenharmony_ci switch (source) { 10328c2ecf20Sopenharmony_ci case RT5660_PLL1_S_MCLK: 10338c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5660_GLB_CLK, 10348c2ecf20Sopenharmony_ci RT5660_PLL1_SRC_MASK, RT5660_PLL1_SRC_MCLK); 10358c2ecf20Sopenharmony_ci break; 10368c2ecf20Sopenharmony_ci 10378c2ecf20Sopenharmony_ci case RT5660_PLL1_S_BCLK: 10388c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5660_GLB_CLK, 10398c2ecf20Sopenharmony_ci RT5660_PLL1_SRC_MASK, RT5660_PLL1_SRC_BCLK1); 10408c2ecf20Sopenharmony_ci break; 10418c2ecf20Sopenharmony_ci 10428c2ecf20Sopenharmony_ci default: 10438c2ecf20Sopenharmony_ci dev_err(component->dev, "Unknown PLL source %d\n", source); 10448c2ecf20Sopenharmony_ci return -EINVAL; 10458c2ecf20Sopenharmony_ci } 10468c2ecf20Sopenharmony_ci 10478c2ecf20Sopenharmony_ci ret = rl6231_pll_calc(freq_in, freq_out, &pll_code); 10488c2ecf20Sopenharmony_ci if (ret < 0) { 10498c2ecf20Sopenharmony_ci dev_err(component->dev, "Unsupport input clock %d\n", freq_in); 10508c2ecf20Sopenharmony_ci return ret; 10518c2ecf20Sopenharmony_ci } 10528c2ecf20Sopenharmony_ci 10538c2ecf20Sopenharmony_ci dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", 10548c2ecf20Sopenharmony_ci pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code), 10558c2ecf20Sopenharmony_ci pll_code.n_code, pll_code.k_code); 10568c2ecf20Sopenharmony_ci 10578c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT5660_PLL_CTRL1, 10588c2ecf20Sopenharmony_ci pll_code.n_code << RT5660_PLL_N_SFT | pll_code.k_code); 10598c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT5660_PLL_CTRL2, 10608c2ecf20Sopenharmony_ci (pll_code.m_bp ? 0 : pll_code.m_code) << RT5660_PLL_M_SFT | 10618c2ecf20Sopenharmony_ci pll_code.m_bp << RT5660_PLL_M_BP_SFT); 10628c2ecf20Sopenharmony_ci 10638c2ecf20Sopenharmony_ci rt5660->pll_in = freq_in; 10648c2ecf20Sopenharmony_ci rt5660->pll_out = freq_out; 10658c2ecf20Sopenharmony_ci rt5660->pll_src = source; 10668c2ecf20Sopenharmony_ci 10678c2ecf20Sopenharmony_ci return 0; 10688c2ecf20Sopenharmony_ci} 10698c2ecf20Sopenharmony_ci 10708c2ecf20Sopenharmony_cistatic int rt5660_set_bias_level(struct snd_soc_component *component, 10718c2ecf20Sopenharmony_ci enum snd_soc_bias_level level) 10728c2ecf20Sopenharmony_ci{ 10738c2ecf20Sopenharmony_ci struct rt5660_priv *rt5660 = snd_soc_component_get_drvdata(component); 10748c2ecf20Sopenharmony_ci int ret; 10758c2ecf20Sopenharmony_ci 10768c2ecf20Sopenharmony_ci switch (level) { 10778c2ecf20Sopenharmony_ci case SND_SOC_BIAS_ON: 10788c2ecf20Sopenharmony_ci break; 10798c2ecf20Sopenharmony_ci 10808c2ecf20Sopenharmony_ci case SND_SOC_BIAS_PREPARE: 10818c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5660_GEN_CTRL1, 10828c2ecf20Sopenharmony_ci RT5660_DIG_GATE_CTRL, RT5660_DIG_GATE_CTRL); 10838c2ecf20Sopenharmony_ci 10848c2ecf20Sopenharmony_ci if (IS_ERR(rt5660->mclk)) 10858c2ecf20Sopenharmony_ci break; 10868c2ecf20Sopenharmony_ci 10878c2ecf20Sopenharmony_ci if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) { 10888c2ecf20Sopenharmony_ci clk_disable_unprepare(rt5660->mclk); 10898c2ecf20Sopenharmony_ci } else { 10908c2ecf20Sopenharmony_ci ret = clk_prepare_enable(rt5660->mclk); 10918c2ecf20Sopenharmony_ci if (ret) 10928c2ecf20Sopenharmony_ci return ret; 10938c2ecf20Sopenharmony_ci } 10948c2ecf20Sopenharmony_ci break; 10958c2ecf20Sopenharmony_ci 10968c2ecf20Sopenharmony_ci case SND_SOC_BIAS_STANDBY: 10978c2ecf20Sopenharmony_ci if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) { 10988c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5660_PWR_ANLG1, 10998c2ecf20Sopenharmony_ci RT5660_PWR_VREF1 | RT5660_PWR_MB | 11008c2ecf20Sopenharmony_ci RT5660_PWR_BG | RT5660_PWR_VREF2, 11018c2ecf20Sopenharmony_ci RT5660_PWR_VREF1 | RT5660_PWR_MB | 11028c2ecf20Sopenharmony_ci RT5660_PWR_BG | RT5660_PWR_VREF2); 11038c2ecf20Sopenharmony_ci usleep_range(10000, 15000); 11048c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5660_PWR_ANLG1, 11058c2ecf20Sopenharmony_ci RT5660_PWR_FV1 | RT5660_PWR_FV2, 11068c2ecf20Sopenharmony_ci RT5660_PWR_FV1 | RT5660_PWR_FV2); 11078c2ecf20Sopenharmony_ci } 11088c2ecf20Sopenharmony_ci break; 11098c2ecf20Sopenharmony_ci 11108c2ecf20Sopenharmony_ci case SND_SOC_BIAS_OFF: 11118c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5660_GEN_CTRL1, 11128c2ecf20Sopenharmony_ci RT5660_DIG_GATE_CTRL, 0); 11138c2ecf20Sopenharmony_ci break; 11148c2ecf20Sopenharmony_ci 11158c2ecf20Sopenharmony_ci default: 11168c2ecf20Sopenharmony_ci break; 11178c2ecf20Sopenharmony_ci } 11188c2ecf20Sopenharmony_ci 11198c2ecf20Sopenharmony_ci return 0; 11208c2ecf20Sopenharmony_ci} 11218c2ecf20Sopenharmony_ci 11228c2ecf20Sopenharmony_cistatic int rt5660_probe(struct snd_soc_component *component) 11238c2ecf20Sopenharmony_ci{ 11248c2ecf20Sopenharmony_ci struct rt5660_priv *rt5660 = snd_soc_component_get_drvdata(component); 11258c2ecf20Sopenharmony_ci 11268c2ecf20Sopenharmony_ci rt5660->component = component; 11278c2ecf20Sopenharmony_ci 11288c2ecf20Sopenharmony_ci return 0; 11298c2ecf20Sopenharmony_ci} 11308c2ecf20Sopenharmony_ci 11318c2ecf20Sopenharmony_cistatic void rt5660_remove(struct snd_soc_component *component) 11328c2ecf20Sopenharmony_ci{ 11338c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT5660_RESET, 0); 11348c2ecf20Sopenharmony_ci} 11358c2ecf20Sopenharmony_ci 11368c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 11378c2ecf20Sopenharmony_cistatic int rt5660_suspend(struct snd_soc_component *component) 11388c2ecf20Sopenharmony_ci{ 11398c2ecf20Sopenharmony_ci struct rt5660_priv *rt5660 = snd_soc_component_get_drvdata(component); 11408c2ecf20Sopenharmony_ci 11418c2ecf20Sopenharmony_ci regcache_cache_only(rt5660->regmap, true); 11428c2ecf20Sopenharmony_ci regcache_mark_dirty(rt5660->regmap); 11438c2ecf20Sopenharmony_ci 11448c2ecf20Sopenharmony_ci return 0; 11458c2ecf20Sopenharmony_ci} 11468c2ecf20Sopenharmony_ci 11478c2ecf20Sopenharmony_cistatic int rt5660_resume(struct snd_soc_component *component) 11488c2ecf20Sopenharmony_ci{ 11498c2ecf20Sopenharmony_ci struct rt5660_priv *rt5660 = snd_soc_component_get_drvdata(component); 11508c2ecf20Sopenharmony_ci 11518c2ecf20Sopenharmony_ci if (rt5660->pdata.poweroff_codec_in_suspend) 11528c2ecf20Sopenharmony_ci msleep(350); 11538c2ecf20Sopenharmony_ci 11548c2ecf20Sopenharmony_ci regcache_cache_only(rt5660->regmap, false); 11558c2ecf20Sopenharmony_ci regcache_sync(rt5660->regmap); 11568c2ecf20Sopenharmony_ci 11578c2ecf20Sopenharmony_ci return 0; 11588c2ecf20Sopenharmony_ci} 11598c2ecf20Sopenharmony_ci#else 11608c2ecf20Sopenharmony_ci#define rt5660_suspend NULL 11618c2ecf20Sopenharmony_ci#define rt5660_resume NULL 11628c2ecf20Sopenharmony_ci#endif 11638c2ecf20Sopenharmony_ci 11648c2ecf20Sopenharmony_ci#define RT5660_STEREO_RATES SNDRV_PCM_RATE_8000_192000 11658c2ecf20Sopenharmony_ci#define RT5660_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ 11668c2ecf20Sopenharmony_ci SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8) 11678c2ecf20Sopenharmony_ci 11688c2ecf20Sopenharmony_cistatic const struct snd_soc_dai_ops rt5660_aif_dai_ops = { 11698c2ecf20Sopenharmony_ci .hw_params = rt5660_hw_params, 11708c2ecf20Sopenharmony_ci .set_fmt = rt5660_set_dai_fmt, 11718c2ecf20Sopenharmony_ci .set_sysclk = rt5660_set_dai_sysclk, 11728c2ecf20Sopenharmony_ci .set_pll = rt5660_set_dai_pll, 11738c2ecf20Sopenharmony_ci}; 11748c2ecf20Sopenharmony_ci 11758c2ecf20Sopenharmony_cistatic struct snd_soc_dai_driver rt5660_dai[] = { 11768c2ecf20Sopenharmony_ci { 11778c2ecf20Sopenharmony_ci .name = "rt5660-aif1", 11788c2ecf20Sopenharmony_ci .id = RT5660_AIF1, 11798c2ecf20Sopenharmony_ci .playback = { 11808c2ecf20Sopenharmony_ci .stream_name = "AIF1 Playback", 11818c2ecf20Sopenharmony_ci .channels_min = 1, 11828c2ecf20Sopenharmony_ci .channels_max = 2, 11838c2ecf20Sopenharmony_ci .rates = RT5660_STEREO_RATES, 11848c2ecf20Sopenharmony_ci .formats = RT5660_FORMATS, 11858c2ecf20Sopenharmony_ci }, 11868c2ecf20Sopenharmony_ci .capture = { 11878c2ecf20Sopenharmony_ci .stream_name = "AIF1 Capture", 11888c2ecf20Sopenharmony_ci .channels_min = 1, 11898c2ecf20Sopenharmony_ci .channels_max = 2, 11908c2ecf20Sopenharmony_ci .rates = RT5660_STEREO_RATES, 11918c2ecf20Sopenharmony_ci .formats = RT5660_FORMATS, 11928c2ecf20Sopenharmony_ci }, 11938c2ecf20Sopenharmony_ci .ops = &rt5660_aif_dai_ops, 11948c2ecf20Sopenharmony_ci }, 11958c2ecf20Sopenharmony_ci}; 11968c2ecf20Sopenharmony_ci 11978c2ecf20Sopenharmony_cistatic const struct snd_soc_component_driver soc_component_dev_rt5660 = { 11988c2ecf20Sopenharmony_ci .probe = rt5660_probe, 11998c2ecf20Sopenharmony_ci .remove = rt5660_remove, 12008c2ecf20Sopenharmony_ci .suspend = rt5660_suspend, 12018c2ecf20Sopenharmony_ci .resume = rt5660_resume, 12028c2ecf20Sopenharmony_ci .set_bias_level = rt5660_set_bias_level, 12038c2ecf20Sopenharmony_ci .controls = rt5660_snd_controls, 12048c2ecf20Sopenharmony_ci .num_controls = ARRAY_SIZE(rt5660_snd_controls), 12058c2ecf20Sopenharmony_ci .dapm_widgets = rt5660_dapm_widgets, 12068c2ecf20Sopenharmony_ci .num_dapm_widgets = ARRAY_SIZE(rt5660_dapm_widgets), 12078c2ecf20Sopenharmony_ci .dapm_routes = rt5660_dapm_routes, 12088c2ecf20Sopenharmony_ci .num_dapm_routes = ARRAY_SIZE(rt5660_dapm_routes), 12098c2ecf20Sopenharmony_ci .use_pmdown_time = 1, 12108c2ecf20Sopenharmony_ci .endianness = 1, 12118c2ecf20Sopenharmony_ci .non_legacy_dai_naming = 1, 12128c2ecf20Sopenharmony_ci}; 12138c2ecf20Sopenharmony_ci 12148c2ecf20Sopenharmony_cistatic const struct regmap_config rt5660_regmap = { 12158c2ecf20Sopenharmony_ci .reg_bits = 8, 12168c2ecf20Sopenharmony_ci .val_bits = 16, 12178c2ecf20Sopenharmony_ci .use_single_read = true, 12188c2ecf20Sopenharmony_ci .use_single_write = true, 12198c2ecf20Sopenharmony_ci 12208c2ecf20Sopenharmony_ci .max_register = RT5660_VENDOR_ID2 + 1 + (ARRAY_SIZE(rt5660_ranges) * 12218c2ecf20Sopenharmony_ci RT5660_PR_SPACING), 12228c2ecf20Sopenharmony_ci .volatile_reg = rt5660_volatile_register, 12238c2ecf20Sopenharmony_ci .readable_reg = rt5660_readable_register, 12248c2ecf20Sopenharmony_ci 12258c2ecf20Sopenharmony_ci .cache_type = REGCACHE_RBTREE, 12268c2ecf20Sopenharmony_ci .reg_defaults = rt5660_reg, 12278c2ecf20Sopenharmony_ci .num_reg_defaults = ARRAY_SIZE(rt5660_reg), 12288c2ecf20Sopenharmony_ci .ranges = rt5660_ranges, 12298c2ecf20Sopenharmony_ci .num_ranges = ARRAY_SIZE(rt5660_ranges), 12308c2ecf20Sopenharmony_ci}; 12318c2ecf20Sopenharmony_ci 12328c2ecf20Sopenharmony_cistatic const struct i2c_device_id rt5660_i2c_id[] = { 12338c2ecf20Sopenharmony_ci { "rt5660", 0 }, 12348c2ecf20Sopenharmony_ci { } 12358c2ecf20Sopenharmony_ci}; 12368c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, rt5660_i2c_id); 12378c2ecf20Sopenharmony_ci 12388c2ecf20Sopenharmony_cistatic const struct of_device_id rt5660_of_match[] = { 12398c2ecf20Sopenharmony_ci { .compatible = "realtek,rt5660", }, 12408c2ecf20Sopenharmony_ci {}, 12418c2ecf20Sopenharmony_ci}; 12428c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, rt5660_of_match); 12438c2ecf20Sopenharmony_ci 12448c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI 12458c2ecf20Sopenharmony_cistatic const struct acpi_device_id rt5660_acpi_match[] = { 12468c2ecf20Sopenharmony_ci { "10EC5660", 0 }, 12478c2ecf20Sopenharmony_ci { "10EC3277", 0 }, 12488c2ecf20Sopenharmony_ci { }, 12498c2ecf20Sopenharmony_ci}; 12508c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(acpi, rt5660_acpi_match); 12518c2ecf20Sopenharmony_ci#endif 12528c2ecf20Sopenharmony_ci 12538c2ecf20Sopenharmony_cistatic int rt5660_parse_dt(struct rt5660_priv *rt5660, struct device *dev) 12548c2ecf20Sopenharmony_ci{ 12558c2ecf20Sopenharmony_ci rt5660->pdata.in1_diff = device_property_read_bool(dev, 12568c2ecf20Sopenharmony_ci "realtek,in1-differential"); 12578c2ecf20Sopenharmony_ci rt5660->pdata.in3_diff = device_property_read_bool(dev, 12588c2ecf20Sopenharmony_ci "realtek,in3-differential"); 12598c2ecf20Sopenharmony_ci rt5660->pdata.poweroff_codec_in_suspend = device_property_read_bool(dev, 12608c2ecf20Sopenharmony_ci "realtek,poweroff-in-suspend"); 12618c2ecf20Sopenharmony_ci device_property_read_u32(dev, "realtek,dmic1-data-pin", 12628c2ecf20Sopenharmony_ci &rt5660->pdata.dmic1_data_pin); 12638c2ecf20Sopenharmony_ci 12648c2ecf20Sopenharmony_ci return 0; 12658c2ecf20Sopenharmony_ci} 12668c2ecf20Sopenharmony_ci 12678c2ecf20Sopenharmony_cistatic int rt5660_i2c_probe(struct i2c_client *i2c, 12688c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 12698c2ecf20Sopenharmony_ci{ 12708c2ecf20Sopenharmony_ci struct rt5660_platform_data *pdata = dev_get_platdata(&i2c->dev); 12718c2ecf20Sopenharmony_ci struct rt5660_priv *rt5660; 12728c2ecf20Sopenharmony_ci int ret; 12738c2ecf20Sopenharmony_ci unsigned int val; 12748c2ecf20Sopenharmony_ci 12758c2ecf20Sopenharmony_ci rt5660 = devm_kzalloc(&i2c->dev, sizeof(struct rt5660_priv), 12768c2ecf20Sopenharmony_ci GFP_KERNEL); 12778c2ecf20Sopenharmony_ci 12788c2ecf20Sopenharmony_ci if (rt5660 == NULL) 12798c2ecf20Sopenharmony_ci return -ENOMEM; 12808c2ecf20Sopenharmony_ci 12818c2ecf20Sopenharmony_ci /* Check if MCLK provided */ 12828c2ecf20Sopenharmony_ci rt5660->mclk = devm_clk_get(&i2c->dev, "mclk"); 12838c2ecf20Sopenharmony_ci if (PTR_ERR(rt5660->mclk) == -EPROBE_DEFER) 12848c2ecf20Sopenharmony_ci return -EPROBE_DEFER; 12858c2ecf20Sopenharmony_ci 12868c2ecf20Sopenharmony_ci i2c_set_clientdata(i2c, rt5660); 12878c2ecf20Sopenharmony_ci 12888c2ecf20Sopenharmony_ci if (pdata) 12898c2ecf20Sopenharmony_ci rt5660->pdata = *pdata; 12908c2ecf20Sopenharmony_ci else if (i2c->dev.of_node) 12918c2ecf20Sopenharmony_ci rt5660_parse_dt(rt5660, &i2c->dev); 12928c2ecf20Sopenharmony_ci 12938c2ecf20Sopenharmony_ci rt5660->regmap = devm_regmap_init_i2c(i2c, &rt5660_regmap); 12948c2ecf20Sopenharmony_ci if (IS_ERR(rt5660->regmap)) { 12958c2ecf20Sopenharmony_ci ret = PTR_ERR(rt5660->regmap); 12968c2ecf20Sopenharmony_ci dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 12978c2ecf20Sopenharmony_ci ret); 12988c2ecf20Sopenharmony_ci return ret; 12998c2ecf20Sopenharmony_ci } 13008c2ecf20Sopenharmony_ci 13018c2ecf20Sopenharmony_ci regmap_read(rt5660->regmap, RT5660_VENDOR_ID2, &val); 13028c2ecf20Sopenharmony_ci if (val != RT5660_DEVICE_ID) { 13038c2ecf20Sopenharmony_ci dev_err(&i2c->dev, 13048c2ecf20Sopenharmony_ci "Device with ID register %#x is not rt5660\n", val); 13058c2ecf20Sopenharmony_ci return -ENODEV; 13068c2ecf20Sopenharmony_ci } 13078c2ecf20Sopenharmony_ci 13088c2ecf20Sopenharmony_ci regmap_write(rt5660->regmap, RT5660_RESET, 0); 13098c2ecf20Sopenharmony_ci 13108c2ecf20Sopenharmony_ci ret = regmap_register_patch(rt5660->regmap, rt5660_patch, 13118c2ecf20Sopenharmony_ci ARRAY_SIZE(rt5660_patch)); 13128c2ecf20Sopenharmony_ci if (ret != 0) 13138c2ecf20Sopenharmony_ci dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret); 13148c2ecf20Sopenharmony_ci 13158c2ecf20Sopenharmony_ci regmap_update_bits(rt5660->regmap, RT5660_GEN_CTRL1, 13168c2ecf20Sopenharmony_ci RT5660_AUTO_DIS_AMP | RT5660_MCLK_DET | RT5660_POW_CLKDET, 13178c2ecf20Sopenharmony_ci RT5660_AUTO_DIS_AMP | RT5660_MCLK_DET | RT5660_POW_CLKDET); 13188c2ecf20Sopenharmony_ci 13198c2ecf20Sopenharmony_ci if (rt5660->pdata.dmic1_data_pin) { 13208c2ecf20Sopenharmony_ci regmap_update_bits(rt5660->regmap, RT5660_GPIO_CTRL1, 13218c2ecf20Sopenharmony_ci RT5660_GP1_PIN_MASK, RT5660_GP1_PIN_DMIC1_SCL); 13228c2ecf20Sopenharmony_ci 13238c2ecf20Sopenharmony_ci if (rt5660->pdata.dmic1_data_pin == RT5660_DMIC1_DATA_GPIO2) 13248c2ecf20Sopenharmony_ci regmap_update_bits(rt5660->regmap, RT5660_DMIC_CTRL1, 13258c2ecf20Sopenharmony_ci RT5660_SEL_DMIC_DATA_MASK, 13268c2ecf20Sopenharmony_ci RT5660_SEL_DMIC_DATA_GPIO2); 13278c2ecf20Sopenharmony_ci else if (rt5660->pdata.dmic1_data_pin == RT5660_DMIC1_DATA_IN1P) 13288c2ecf20Sopenharmony_ci regmap_update_bits(rt5660->regmap, RT5660_DMIC_CTRL1, 13298c2ecf20Sopenharmony_ci RT5660_SEL_DMIC_DATA_MASK, 13308c2ecf20Sopenharmony_ci RT5660_SEL_DMIC_DATA_IN1P); 13318c2ecf20Sopenharmony_ci } 13328c2ecf20Sopenharmony_ci 13338c2ecf20Sopenharmony_ci return devm_snd_soc_register_component(&i2c->dev, 13348c2ecf20Sopenharmony_ci &soc_component_dev_rt5660, 13358c2ecf20Sopenharmony_ci rt5660_dai, ARRAY_SIZE(rt5660_dai)); 13368c2ecf20Sopenharmony_ci} 13378c2ecf20Sopenharmony_ci 13388c2ecf20Sopenharmony_cistatic struct i2c_driver rt5660_i2c_driver = { 13398c2ecf20Sopenharmony_ci .driver = { 13408c2ecf20Sopenharmony_ci .name = "rt5660", 13418c2ecf20Sopenharmony_ci .acpi_match_table = ACPI_PTR(rt5660_acpi_match), 13428c2ecf20Sopenharmony_ci .of_match_table = of_match_ptr(rt5660_of_match), 13438c2ecf20Sopenharmony_ci }, 13448c2ecf20Sopenharmony_ci .probe = rt5660_i2c_probe, 13458c2ecf20Sopenharmony_ci .id_table = rt5660_i2c_id, 13468c2ecf20Sopenharmony_ci}; 13478c2ecf20Sopenharmony_cimodule_i2c_driver(rt5660_i2c_driver); 13488c2ecf20Sopenharmony_ci 13498c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("ASoC RT5660 driver"); 13508c2ecf20Sopenharmony_ciMODULE_AUTHOR("Oder Chiou <oder_chiou@realtek.com>"); 13518c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 1352