18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * ak4671.c -- audio driver for AK4671 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2009 Samsung Electronics Co.Ltd 68c2ecf20Sopenharmony_ci * Author: Joonyoung Shim <jy0922.shim@samsung.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/module.h> 108c2ecf20Sopenharmony_ci#include <linux/init.h> 118c2ecf20Sopenharmony_ci#include <linux/i2c.h> 128c2ecf20Sopenharmony_ci#include <linux/delay.h> 138c2ecf20Sopenharmony_ci#include <linux/regmap.h> 148c2ecf20Sopenharmony_ci#include <linux/slab.h> 158c2ecf20Sopenharmony_ci#include <sound/soc.h> 168c2ecf20Sopenharmony_ci#include <sound/initval.h> 178c2ecf20Sopenharmony_ci#include <sound/tlv.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#include "ak4671.h" 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* ak4671 register cache & default register settings */ 238c2ecf20Sopenharmony_cistatic const struct reg_default ak4671_reg_defaults[] = { 248c2ecf20Sopenharmony_ci { 0x00, 0x00 }, /* AK4671_AD_DA_POWER_MANAGEMENT (0x00) */ 258c2ecf20Sopenharmony_ci { 0x01, 0xf6 }, /* AK4671_PLL_MODE_SELECT0 (0x01) */ 268c2ecf20Sopenharmony_ci { 0x02, 0x00 }, /* AK4671_PLL_MODE_SELECT1 (0x02) */ 278c2ecf20Sopenharmony_ci { 0x03, 0x02 }, /* AK4671_FORMAT_SELECT (0x03) */ 288c2ecf20Sopenharmony_ci { 0x04, 0x00 }, /* AK4671_MIC_SIGNAL_SELECT (0x04) */ 298c2ecf20Sopenharmony_ci { 0x05, 0x55 }, /* AK4671_MIC_AMP_GAIN (0x05) */ 308c2ecf20Sopenharmony_ci { 0x06, 0x00 }, /* AK4671_MIXING_POWER_MANAGEMENT0 (0x06) */ 318c2ecf20Sopenharmony_ci { 0x07, 0x00 }, /* AK4671_MIXING_POWER_MANAGEMENT1 (0x07) */ 328c2ecf20Sopenharmony_ci { 0x08, 0xb5 }, /* AK4671_OUTPUT_VOLUME_CONTROL (0x08) */ 338c2ecf20Sopenharmony_ci { 0x09, 0x00 }, /* AK4671_LOUT1_SIGNAL_SELECT (0x09) */ 348c2ecf20Sopenharmony_ci { 0x0a, 0x00 }, /* AK4671_ROUT1_SIGNAL_SELECT (0x0a) */ 358c2ecf20Sopenharmony_ci { 0x0b, 0x00 }, /* AK4671_LOUT2_SIGNAL_SELECT (0x0b) */ 368c2ecf20Sopenharmony_ci { 0x0c, 0x00 }, /* AK4671_ROUT2_SIGNAL_SELECT (0x0c) */ 378c2ecf20Sopenharmony_ci { 0x0d, 0x00 }, /* AK4671_LOUT3_SIGNAL_SELECT (0x0d) */ 388c2ecf20Sopenharmony_ci { 0x0e, 0x00 }, /* AK4671_ROUT3_SIGNAL_SELECT (0x0e) */ 398c2ecf20Sopenharmony_ci { 0x0f, 0x00 }, /* AK4671_LOUT1_POWER_MANAGERMENT (0x0f) */ 408c2ecf20Sopenharmony_ci { 0x10, 0x00 }, /* AK4671_LOUT2_POWER_MANAGERMENT (0x10) */ 418c2ecf20Sopenharmony_ci { 0x11, 0x80 }, /* AK4671_LOUT3_POWER_MANAGERMENT (0x11) */ 428c2ecf20Sopenharmony_ci { 0x12, 0x91 }, /* AK4671_LCH_INPUT_VOLUME_CONTROL (0x12) */ 438c2ecf20Sopenharmony_ci { 0x13, 0x91 }, /* AK4671_RCH_INPUT_VOLUME_CONTROL (0x13) */ 448c2ecf20Sopenharmony_ci { 0x14, 0xe1 }, /* AK4671_ALC_REFERENCE_SELECT (0x14) */ 458c2ecf20Sopenharmony_ci { 0x15, 0x00 }, /* AK4671_DIGITAL_MIXING_CONTROL (0x15) */ 468c2ecf20Sopenharmony_ci { 0x16, 0x00 }, /* AK4671_ALC_TIMER_SELECT (0x16) */ 478c2ecf20Sopenharmony_ci { 0x17, 0x00 }, /* AK4671_ALC_MODE_CONTROL (0x17) */ 488c2ecf20Sopenharmony_ci { 0x18, 0x02 }, /* AK4671_MODE_CONTROL1 (0x18) */ 498c2ecf20Sopenharmony_ci { 0x19, 0x01 }, /* AK4671_MODE_CONTROL2 (0x19) */ 508c2ecf20Sopenharmony_ci { 0x1a, 0x18 }, /* AK4671_LCH_OUTPUT_VOLUME_CONTROL (0x1a) */ 518c2ecf20Sopenharmony_ci { 0x1b, 0x18 }, /* AK4671_RCH_OUTPUT_VOLUME_CONTROL (0x1b) */ 528c2ecf20Sopenharmony_ci { 0x1c, 0x00 }, /* AK4671_SIDETONE_A_CONTROL (0x1c) */ 538c2ecf20Sopenharmony_ci { 0x1d, 0x02 }, /* AK4671_DIGITAL_FILTER_SELECT (0x1d) */ 548c2ecf20Sopenharmony_ci { 0x1e, 0x00 }, /* AK4671_FIL3_COEFFICIENT0 (0x1e) */ 558c2ecf20Sopenharmony_ci { 0x1f, 0x00 }, /* AK4671_FIL3_COEFFICIENT1 (0x1f) */ 568c2ecf20Sopenharmony_ci { 0x20, 0x00 }, /* AK4671_FIL3_COEFFICIENT2 (0x20) */ 578c2ecf20Sopenharmony_ci { 0x21, 0x00 }, /* AK4671_FIL3_COEFFICIENT3 (0x21) */ 588c2ecf20Sopenharmony_ci { 0x22, 0x00 }, /* AK4671_EQ_COEFFICIENT0 (0x22) */ 598c2ecf20Sopenharmony_ci { 0x23, 0x00 }, /* AK4671_EQ_COEFFICIENT1 (0x23) */ 608c2ecf20Sopenharmony_ci { 0x24, 0x00 }, /* AK4671_EQ_COEFFICIENT2 (0x24) */ 618c2ecf20Sopenharmony_ci { 0x25, 0x00 }, /* AK4671_EQ_COEFFICIENT3 (0x25) */ 628c2ecf20Sopenharmony_ci { 0x26, 0x00 }, /* AK4671_EQ_COEFFICIENT4 (0x26) */ 638c2ecf20Sopenharmony_ci { 0x27, 0x00 }, /* AK4671_EQ_COEFFICIENT5 (0x27) */ 648c2ecf20Sopenharmony_ci { 0x28, 0xa9 }, /* AK4671_FIL1_COEFFICIENT0 (0x28) */ 658c2ecf20Sopenharmony_ci { 0x29, 0x1f }, /* AK4671_FIL1_COEFFICIENT1 (0x29) */ 668c2ecf20Sopenharmony_ci { 0x2a, 0xad }, /* AK4671_FIL1_COEFFICIENT2 (0x2a) */ 678c2ecf20Sopenharmony_ci { 0x2b, 0x20 }, /* AK4671_FIL1_COEFFICIENT3 (0x2b) */ 688c2ecf20Sopenharmony_ci { 0x2c, 0x00 }, /* AK4671_FIL2_COEFFICIENT0 (0x2c) */ 698c2ecf20Sopenharmony_ci { 0x2d, 0x00 }, /* AK4671_FIL2_COEFFICIENT1 (0x2d) */ 708c2ecf20Sopenharmony_ci { 0x2e, 0x00 }, /* AK4671_FIL2_COEFFICIENT2 (0x2e) */ 718c2ecf20Sopenharmony_ci { 0x2f, 0x00 }, /* AK4671_FIL2_COEFFICIENT3 (0x2f) */ 728c2ecf20Sopenharmony_ci { 0x30, 0x00 }, /* AK4671_DIGITAL_FILTER_SELECT2 (0x30) */ 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci { 0x32, 0x00 }, /* AK4671_E1_COEFFICIENT0 (0x32) */ 758c2ecf20Sopenharmony_ci { 0x33, 0x00 }, /* AK4671_E1_COEFFICIENT1 (0x33) */ 768c2ecf20Sopenharmony_ci { 0x34, 0x00 }, /* AK4671_E1_COEFFICIENT2 (0x34) */ 778c2ecf20Sopenharmony_ci { 0x35, 0x00 }, /* AK4671_E1_COEFFICIENT3 (0x35) */ 788c2ecf20Sopenharmony_ci { 0x36, 0x00 }, /* AK4671_E1_COEFFICIENT4 (0x36) */ 798c2ecf20Sopenharmony_ci { 0x37, 0x00 }, /* AK4671_E1_COEFFICIENT5 (0x37) */ 808c2ecf20Sopenharmony_ci { 0x38, 0x00 }, /* AK4671_E2_COEFFICIENT0 (0x38) */ 818c2ecf20Sopenharmony_ci { 0x39, 0x00 }, /* AK4671_E2_COEFFICIENT1 (0x39) */ 828c2ecf20Sopenharmony_ci { 0x3a, 0x00 }, /* AK4671_E2_COEFFICIENT2 (0x3a) */ 838c2ecf20Sopenharmony_ci { 0x3b, 0x00 }, /* AK4671_E2_COEFFICIENT3 (0x3b) */ 848c2ecf20Sopenharmony_ci { 0x3c, 0x00 }, /* AK4671_E2_COEFFICIENT4 (0x3c) */ 858c2ecf20Sopenharmony_ci { 0x3d, 0x00 }, /* AK4671_E2_COEFFICIENT5 (0x3d) */ 868c2ecf20Sopenharmony_ci { 0x3e, 0x00 }, /* AK4671_E3_COEFFICIENT0 (0x3e) */ 878c2ecf20Sopenharmony_ci { 0x3f, 0x00 }, /* AK4671_E3_COEFFICIENT1 (0x3f) */ 888c2ecf20Sopenharmony_ci { 0x40, 0x00 }, /* AK4671_E3_COEFFICIENT2 (0x40) */ 898c2ecf20Sopenharmony_ci { 0x41, 0x00 }, /* AK4671_E3_COEFFICIENT3 (0x41) */ 908c2ecf20Sopenharmony_ci { 0x42, 0x00 }, /* AK4671_E3_COEFFICIENT4 (0x42) */ 918c2ecf20Sopenharmony_ci { 0x43, 0x00 }, /* AK4671_E3_COEFFICIENT5 (0x43) */ 928c2ecf20Sopenharmony_ci { 0x44, 0x00 }, /* AK4671_E4_COEFFICIENT0 (0x44) */ 938c2ecf20Sopenharmony_ci { 0x45, 0x00 }, /* AK4671_E4_COEFFICIENT1 (0x45) */ 948c2ecf20Sopenharmony_ci { 0x46, 0x00 }, /* AK4671_E4_COEFFICIENT2 (0x46) */ 958c2ecf20Sopenharmony_ci { 0x47, 0x00 }, /* AK4671_E4_COEFFICIENT3 (0x47) */ 968c2ecf20Sopenharmony_ci { 0x48, 0x00 }, /* AK4671_E4_COEFFICIENT4 (0x48) */ 978c2ecf20Sopenharmony_ci { 0x49, 0x00 }, /* AK4671_E4_COEFFICIENT5 (0x49) */ 988c2ecf20Sopenharmony_ci { 0x4a, 0x00 }, /* AK4671_E5_COEFFICIENT0 (0x4a) */ 998c2ecf20Sopenharmony_ci { 0x4b, 0x00 }, /* AK4671_E5_COEFFICIENT1 (0x4b) */ 1008c2ecf20Sopenharmony_ci { 0x4c, 0x00 }, /* AK4671_E5_COEFFICIENT2 (0x4c) */ 1018c2ecf20Sopenharmony_ci { 0x4d, 0x00 }, /* AK4671_E5_COEFFICIENT3 (0x4d) */ 1028c2ecf20Sopenharmony_ci { 0x4e, 0x00 }, /* AK4671_E5_COEFFICIENT4 (0x4e) */ 1038c2ecf20Sopenharmony_ci { 0x4f, 0x00 }, /* AK4671_E5_COEFFICIENT5 (0x4f) */ 1048c2ecf20Sopenharmony_ci { 0x50, 0x88 }, /* AK4671_EQ_CONTROL_250HZ_100HZ (0x50) */ 1058c2ecf20Sopenharmony_ci { 0x51, 0x88 }, /* AK4671_EQ_CONTROL_3500HZ_1KHZ (0x51) */ 1068c2ecf20Sopenharmony_ci { 0x52, 0x08 }, /* AK4671_EQ_CONTRO_10KHZ (0x52) */ 1078c2ecf20Sopenharmony_ci { 0x53, 0x00 }, /* AK4671_PCM_IF_CONTROL0 (0x53) */ 1088c2ecf20Sopenharmony_ci { 0x54, 0x00 }, /* AK4671_PCM_IF_CONTROL1 (0x54) */ 1098c2ecf20Sopenharmony_ci { 0x55, 0x00 }, /* AK4671_PCM_IF_CONTROL2 (0x55) */ 1108c2ecf20Sopenharmony_ci { 0x56, 0x18 }, /* AK4671_DIGITAL_VOLUME_B_CONTROL (0x56) */ 1118c2ecf20Sopenharmony_ci { 0x57, 0x18 }, /* AK4671_DIGITAL_VOLUME_C_CONTROL (0x57) */ 1128c2ecf20Sopenharmony_ci { 0x58, 0x00 }, /* AK4671_SIDETONE_VOLUME_CONTROL (0x58) */ 1138c2ecf20Sopenharmony_ci { 0x59, 0x00 }, /* AK4671_DIGITAL_MIXING_CONTROL2 (0x59) */ 1148c2ecf20Sopenharmony_ci { 0x5a, 0x00 }, /* AK4671_SAR_ADC_CONTROL (0x5a) */ 1158c2ecf20Sopenharmony_ci}; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci/* 1188c2ecf20Sopenharmony_ci * LOUT1/ROUT1 output volume control: 1198c2ecf20Sopenharmony_ci * from -24 to 6 dB in 6 dB steps (mute instead of -30 dB) 1208c2ecf20Sopenharmony_ci */ 1218c2ecf20Sopenharmony_cistatic DECLARE_TLV_DB_SCALE(out1_tlv, -3000, 600, 1); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci/* 1248c2ecf20Sopenharmony_ci * LOUT2/ROUT2 output volume control: 1258c2ecf20Sopenharmony_ci * from -33 to 6 dB in 3 dB steps (mute instead of -33 dB) 1268c2ecf20Sopenharmony_ci */ 1278c2ecf20Sopenharmony_cistatic DECLARE_TLV_DB_SCALE(out2_tlv, -3300, 300, 1); 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci/* 1308c2ecf20Sopenharmony_ci * LOUT3/ROUT3 output volume control: 1318c2ecf20Sopenharmony_ci * from -6 to 3 dB in 3 dB steps 1328c2ecf20Sopenharmony_ci */ 1338c2ecf20Sopenharmony_cistatic DECLARE_TLV_DB_SCALE(out3_tlv, -600, 300, 0); 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci/* 1368c2ecf20Sopenharmony_ci * Mic amp gain control: 1378c2ecf20Sopenharmony_ci * from -15 to 30 dB in 3 dB steps 1388c2ecf20Sopenharmony_ci * REVISIT: The actual min value(0x01) is -12 dB and the reg value 0x00 is not 1398c2ecf20Sopenharmony_ci * available 1408c2ecf20Sopenharmony_ci */ 1418c2ecf20Sopenharmony_cistatic DECLARE_TLV_DB_SCALE(mic_amp_tlv, -1500, 300, 0); 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new ak4671_snd_controls[] = { 1448c2ecf20Sopenharmony_ci /* Common playback gain controls */ 1458c2ecf20Sopenharmony_ci SOC_SINGLE_TLV("Line Output1 Playback Volume", 1468c2ecf20Sopenharmony_ci AK4671_OUTPUT_VOLUME_CONTROL, 0, 0x6, 0, out1_tlv), 1478c2ecf20Sopenharmony_ci SOC_SINGLE_TLV("Headphone Output2 Playback Volume", 1488c2ecf20Sopenharmony_ci AK4671_OUTPUT_VOLUME_CONTROL, 4, 0xd, 0, out2_tlv), 1498c2ecf20Sopenharmony_ci SOC_SINGLE_TLV("Line Output3 Playback Volume", 1508c2ecf20Sopenharmony_ci AK4671_LOUT3_POWER_MANAGERMENT, 6, 0x3, 0, out3_tlv), 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci /* Common capture gain controls */ 1538c2ecf20Sopenharmony_ci SOC_DOUBLE_TLV("Mic Amp Capture Volume", 1548c2ecf20Sopenharmony_ci AK4671_MIC_AMP_GAIN, 0, 4, 0xf, 0, mic_amp_tlv), 1558c2ecf20Sopenharmony_ci}; 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci/* event handlers */ 1588c2ecf20Sopenharmony_cistatic int ak4671_out2_event(struct snd_soc_dapm_widget *w, 1598c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 1608c2ecf20Sopenharmony_ci{ 1618c2ecf20Sopenharmony_ci struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci switch (event) { 1648c2ecf20Sopenharmony_ci case SND_SOC_DAPM_POST_PMU: 1658c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, AK4671_LOUT2_POWER_MANAGERMENT, 1668c2ecf20Sopenharmony_ci AK4671_MUTEN, AK4671_MUTEN); 1678c2ecf20Sopenharmony_ci break; 1688c2ecf20Sopenharmony_ci case SND_SOC_DAPM_PRE_PMD: 1698c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, AK4671_LOUT2_POWER_MANAGERMENT, 1708c2ecf20Sopenharmony_ci AK4671_MUTEN, 0); 1718c2ecf20Sopenharmony_ci break; 1728c2ecf20Sopenharmony_ci } 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci return 0; 1758c2ecf20Sopenharmony_ci} 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci/* Output Mixers */ 1788c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new ak4671_lout1_mixer_controls[] = { 1798c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DACL", AK4671_LOUT1_SIGNAL_SELECT, 0, 1, 0), 1808c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LINL1", AK4671_LOUT1_SIGNAL_SELECT, 1, 1, 0), 1818c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LINL2", AK4671_LOUT1_SIGNAL_SELECT, 2, 1, 0), 1828c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LINL3", AK4671_LOUT1_SIGNAL_SELECT, 3, 1, 0), 1838c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LINL4", AK4671_LOUT1_SIGNAL_SELECT, 4, 1, 0), 1848c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LOOPL", AK4671_LOUT1_SIGNAL_SELECT, 5, 1, 0), 1858c2ecf20Sopenharmony_ci}; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new ak4671_rout1_mixer_controls[] = { 1888c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DACR", AK4671_ROUT1_SIGNAL_SELECT, 0, 1, 0), 1898c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("RINR1", AK4671_ROUT1_SIGNAL_SELECT, 1, 1, 0), 1908c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("RINR2", AK4671_ROUT1_SIGNAL_SELECT, 2, 1, 0), 1918c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("RINR3", AK4671_ROUT1_SIGNAL_SELECT, 3, 1, 0), 1928c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("RINR4", AK4671_ROUT1_SIGNAL_SELECT, 4, 1, 0), 1938c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LOOPR", AK4671_ROUT1_SIGNAL_SELECT, 5, 1, 0), 1948c2ecf20Sopenharmony_ci}; 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new ak4671_lout2_mixer_controls[] = { 1978c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DACHL", AK4671_LOUT2_SIGNAL_SELECT, 0, 1, 0), 1988c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LINH1", AK4671_LOUT2_SIGNAL_SELECT, 1, 1, 0), 1998c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LINH2", AK4671_LOUT2_SIGNAL_SELECT, 2, 1, 0), 2008c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LINH3", AK4671_LOUT2_SIGNAL_SELECT, 3, 1, 0), 2018c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LINH4", AK4671_LOUT2_SIGNAL_SELECT, 4, 1, 0), 2028c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LOOPHL", AK4671_LOUT2_SIGNAL_SELECT, 5, 1, 0), 2038c2ecf20Sopenharmony_ci}; 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new ak4671_rout2_mixer_controls[] = { 2068c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DACHR", AK4671_ROUT2_SIGNAL_SELECT, 0, 1, 0), 2078c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("RINH1", AK4671_ROUT2_SIGNAL_SELECT, 1, 1, 0), 2088c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("RINH2", AK4671_ROUT2_SIGNAL_SELECT, 2, 1, 0), 2098c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("RINH3", AK4671_ROUT2_SIGNAL_SELECT, 3, 1, 0), 2108c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("RINH4", AK4671_ROUT2_SIGNAL_SELECT, 4, 1, 0), 2118c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LOOPHR", AK4671_ROUT2_SIGNAL_SELECT, 5, 1, 0), 2128c2ecf20Sopenharmony_ci}; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new ak4671_lout3_mixer_controls[] = { 2158c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DACSL", AK4671_LOUT3_SIGNAL_SELECT, 0, 1, 0), 2168c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LINS1", AK4671_LOUT3_SIGNAL_SELECT, 1, 1, 0), 2178c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LINS2", AK4671_LOUT3_SIGNAL_SELECT, 2, 1, 0), 2188c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LINS3", AK4671_LOUT3_SIGNAL_SELECT, 3, 1, 0), 2198c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LINS4", AK4671_LOUT3_SIGNAL_SELECT, 4, 1, 0), 2208c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LOOPSL", AK4671_LOUT3_SIGNAL_SELECT, 5, 1, 0), 2218c2ecf20Sopenharmony_ci}; 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new ak4671_rout3_mixer_controls[] = { 2248c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DACSR", AK4671_ROUT3_SIGNAL_SELECT, 0, 1, 0), 2258c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("RINS1", AK4671_ROUT3_SIGNAL_SELECT, 1, 1, 0), 2268c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("RINS2", AK4671_ROUT3_SIGNAL_SELECT, 2, 1, 0), 2278c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("RINS3", AK4671_ROUT3_SIGNAL_SELECT, 3, 1, 0), 2288c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("RINS4", AK4671_ROUT3_SIGNAL_SELECT, 4, 1, 0), 2298c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("LOOPSR", AK4671_ROUT3_SIGNAL_SELECT, 5, 1, 0), 2308c2ecf20Sopenharmony_ci}; 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci/* Input MUXs */ 2338c2ecf20Sopenharmony_cistatic const char *ak4671_lin_mux_texts[] = 2348c2ecf20Sopenharmony_ci {"LIN1", "LIN2", "LIN3", "LIN4"}; 2358c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(ak4671_lin_mux_enum, 2368c2ecf20Sopenharmony_ci AK4671_MIC_SIGNAL_SELECT, 0, 2378c2ecf20Sopenharmony_ci ak4671_lin_mux_texts); 2388c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new ak4671_lin_mux_control = 2398c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Route", ak4671_lin_mux_enum); 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_cistatic const char *ak4671_rin_mux_texts[] = 2428c2ecf20Sopenharmony_ci {"RIN1", "RIN2", "RIN3", "RIN4"}; 2438c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(ak4671_rin_mux_enum, 2448c2ecf20Sopenharmony_ci AK4671_MIC_SIGNAL_SELECT, 2, 2458c2ecf20Sopenharmony_ci ak4671_rin_mux_texts); 2468c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new ak4671_rin_mux_control = 2478c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Route", ak4671_rin_mux_enum); 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget ak4671_dapm_widgets[] = { 2508c2ecf20Sopenharmony_ci /* Inputs */ 2518c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("LIN1"), 2528c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("RIN1"), 2538c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("LIN2"), 2548c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("RIN2"), 2558c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("LIN3"), 2568c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("RIN3"), 2578c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("LIN4"), 2588c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("RIN4"), 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci /* Outputs */ 2618c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("LOUT1"), 2628c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("ROUT1"), 2638c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("LOUT2"), 2648c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("ROUT2"), 2658c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("LOUT3"), 2668c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("ROUT3"), 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci /* DAC */ 2698c2ecf20Sopenharmony_ci SND_SOC_DAPM_DAC("DAC Left", "Left HiFi Playback", 2708c2ecf20Sopenharmony_ci AK4671_AD_DA_POWER_MANAGEMENT, 6, 0), 2718c2ecf20Sopenharmony_ci SND_SOC_DAPM_DAC("DAC Right", "Right HiFi Playback", 2728c2ecf20Sopenharmony_ci AK4671_AD_DA_POWER_MANAGEMENT, 7, 0), 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci /* ADC */ 2758c2ecf20Sopenharmony_ci SND_SOC_DAPM_ADC("ADC Left", "Left HiFi Capture", 2768c2ecf20Sopenharmony_ci AK4671_AD_DA_POWER_MANAGEMENT, 4, 0), 2778c2ecf20Sopenharmony_ci SND_SOC_DAPM_ADC("ADC Right", "Right HiFi Capture", 2788c2ecf20Sopenharmony_ci AK4671_AD_DA_POWER_MANAGEMENT, 5, 0), 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci /* PGA */ 2818c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("LOUT2 Mix Amp", 2828c2ecf20Sopenharmony_ci AK4671_LOUT2_POWER_MANAGERMENT, 5, 0, NULL, 0), 2838c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("ROUT2 Mix Amp", 2848c2ecf20Sopenharmony_ci AK4671_LOUT2_POWER_MANAGERMENT, 6, 0, NULL, 0), 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("LIN1 Mixing Circuit", 2878c2ecf20Sopenharmony_ci AK4671_MIXING_POWER_MANAGEMENT1, 0, 0, NULL, 0), 2888c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("RIN1 Mixing Circuit", 2898c2ecf20Sopenharmony_ci AK4671_MIXING_POWER_MANAGEMENT1, 1, 0, NULL, 0), 2908c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("LIN2 Mixing Circuit", 2918c2ecf20Sopenharmony_ci AK4671_MIXING_POWER_MANAGEMENT1, 2, 0, NULL, 0), 2928c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("RIN2 Mixing Circuit", 2938c2ecf20Sopenharmony_ci AK4671_MIXING_POWER_MANAGEMENT1, 3, 0, NULL, 0), 2948c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("LIN3 Mixing Circuit", 2958c2ecf20Sopenharmony_ci AK4671_MIXING_POWER_MANAGEMENT1, 4, 0, NULL, 0), 2968c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("RIN3 Mixing Circuit", 2978c2ecf20Sopenharmony_ci AK4671_MIXING_POWER_MANAGEMENT1, 5, 0, NULL, 0), 2988c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("LIN4 Mixing Circuit", 2998c2ecf20Sopenharmony_ci AK4671_MIXING_POWER_MANAGEMENT1, 6, 0, NULL, 0), 3008c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("RIN4 Mixing Circuit", 3018c2ecf20Sopenharmony_ci AK4671_MIXING_POWER_MANAGEMENT1, 7, 0, NULL, 0), 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci /* Output Mixers */ 3048c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("LOUT1 Mixer", AK4671_LOUT1_POWER_MANAGERMENT, 0, 0, 3058c2ecf20Sopenharmony_ci &ak4671_lout1_mixer_controls[0], 3068c2ecf20Sopenharmony_ci ARRAY_SIZE(ak4671_lout1_mixer_controls)), 3078c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("ROUT1 Mixer", AK4671_LOUT1_POWER_MANAGERMENT, 1, 0, 3088c2ecf20Sopenharmony_ci &ak4671_rout1_mixer_controls[0], 3098c2ecf20Sopenharmony_ci ARRAY_SIZE(ak4671_rout1_mixer_controls)), 3108c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER_E("LOUT2 Mixer", AK4671_LOUT2_POWER_MANAGERMENT, 3118c2ecf20Sopenharmony_ci 0, 0, &ak4671_lout2_mixer_controls[0], 3128c2ecf20Sopenharmony_ci ARRAY_SIZE(ak4671_lout2_mixer_controls), 3138c2ecf20Sopenharmony_ci ak4671_out2_event, 3148c2ecf20Sopenharmony_ci SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_PRE_PMD), 3158c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER_E("ROUT2 Mixer", AK4671_LOUT2_POWER_MANAGERMENT, 3168c2ecf20Sopenharmony_ci 1, 0, &ak4671_rout2_mixer_controls[0], 3178c2ecf20Sopenharmony_ci ARRAY_SIZE(ak4671_rout2_mixer_controls), 3188c2ecf20Sopenharmony_ci ak4671_out2_event, 3198c2ecf20Sopenharmony_ci SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_PRE_PMD), 3208c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("LOUT3 Mixer", AK4671_LOUT3_POWER_MANAGERMENT, 0, 0, 3218c2ecf20Sopenharmony_ci &ak4671_lout3_mixer_controls[0], 3228c2ecf20Sopenharmony_ci ARRAY_SIZE(ak4671_lout3_mixer_controls)), 3238c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("ROUT3 Mixer", AK4671_LOUT3_POWER_MANAGERMENT, 1, 0, 3248c2ecf20Sopenharmony_ci &ak4671_rout3_mixer_controls[0], 3258c2ecf20Sopenharmony_ci ARRAY_SIZE(ak4671_rout3_mixer_controls)), 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci /* Input MUXs */ 3288c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("LIN MUX", AK4671_AD_DA_POWER_MANAGEMENT, 2, 0, 3298c2ecf20Sopenharmony_ci &ak4671_lin_mux_control), 3308c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("RIN MUX", AK4671_AD_DA_POWER_MANAGEMENT, 3, 0, 3318c2ecf20Sopenharmony_ci &ak4671_rin_mux_control), 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci /* Mic Power */ 3348c2ecf20Sopenharmony_ci SND_SOC_DAPM_MICBIAS("Mic Bias", AK4671_AD_DA_POWER_MANAGEMENT, 1, 0), 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci /* Supply */ 3378c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("PMPLL", AK4671_PLL_MODE_SELECT1, 0, 0, NULL, 0), 3388c2ecf20Sopenharmony_ci}; 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route ak4671_intercon[] = { 3418c2ecf20Sopenharmony_ci {"DAC Left", NULL, "PMPLL"}, 3428c2ecf20Sopenharmony_ci {"DAC Right", NULL, "PMPLL"}, 3438c2ecf20Sopenharmony_ci {"ADC Left", NULL, "PMPLL"}, 3448c2ecf20Sopenharmony_ci {"ADC Right", NULL, "PMPLL"}, 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci /* Outputs */ 3478c2ecf20Sopenharmony_ci {"LOUT1", NULL, "LOUT1 Mixer"}, 3488c2ecf20Sopenharmony_ci {"ROUT1", NULL, "ROUT1 Mixer"}, 3498c2ecf20Sopenharmony_ci {"LOUT2", NULL, "LOUT2 Mix Amp"}, 3508c2ecf20Sopenharmony_ci {"ROUT2", NULL, "ROUT2 Mix Amp"}, 3518c2ecf20Sopenharmony_ci {"LOUT3", NULL, "LOUT3 Mixer"}, 3528c2ecf20Sopenharmony_ci {"ROUT3", NULL, "ROUT3 Mixer"}, 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ci {"LOUT1 Mixer", "DACL", "DAC Left"}, 3558c2ecf20Sopenharmony_ci {"ROUT1 Mixer", "DACR", "DAC Right"}, 3568c2ecf20Sopenharmony_ci {"LOUT2 Mixer", "DACHL", "DAC Left"}, 3578c2ecf20Sopenharmony_ci {"ROUT2 Mixer", "DACHR", "DAC Right"}, 3588c2ecf20Sopenharmony_ci {"LOUT2 Mix Amp", NULL, "LOUT2 Mixer"}, 3598c2ecf20Sopenharmony_ci {"ROUT2 Mix Amp", NULL, "ROUT2 Mixer"}, 3608c2ecf20Sopenharmony_ci {"LOUT3 Mixer", "DACSL", "DAC Left"}, 3618c2ecf20Sopenharmony_ci {"ROUT3 Mixer", "DACSR", "DAC Right"}, 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci /* Inputs */ 3648c2ecf20Sopenharmony_ci {"LIN MUX", "LIN1", "LIN1"}, 3658c2ecf20Sopenharmony_ci {"LIN MUX", "LIN2", "LIN2"}, 3668c2ecf20Sopenharmony_ci {"LIN MUX", "LIN3", "LIN3"}, 3678c2ecf20Sopenharmony_ci {"LIN MUX", "LIN4", "LIN4"}, 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci {"RIN MUX", "RIN1", "RIN1"}, 3708c2ecf20Sopenharmony_ci {"RIN MUX", "RIN2", "RIN2"}, 3718c2ecf20Sopenharmony_ci {"RIN MUX", "RIN3", "RIN3"}, 3728c2ecf20Sopenharmony_ci {"RIN MUX", "RIN4", "RIN4"}, 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci {"LIN1", NULL, "Mic Bias"}, 3758c2ecf20Sopenharmony_ci {"RIN1", NULL, "Mic Bias"}, 3768c2ecf20Sopenharmony_ci {"LIN2", NULL, "Mic Bias"}, 3778c2ecf20Sopenharmony_ci {"RIN2", NULL, "Mic Bias"}, 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci {"ADC Left", NULL, "LIN MUX"}, 3808c2ecf20Sopenharmony_ci {"ADC Right", NULL, "RIN MUX"}, 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_ci /* Analog Loops */ 3838c2ecf20Sopenharmony_ci {"LIN1 Mixing Circuit", NULL, "LIN1"}, 3848c2ecf20Sopenharmony_ci {"RIN1 Mixing Circuit", NULL, "RIN1"}, 3858c2ecf20Sopenharmony_ci {"LIN2 Mixing Circuit", NULL, "LIN2"}, 3868c2ecf20Sopenharmony_ci {"RIN2 Mixing Circuit", NULL, "RIN2"}, 3878c2ecf20Sopenharmony_ci {"LIN3 Mixing Circuit", NULL, "LIN3"}, 3888c2ecf20Sopenharmony_ci {"RIN3 Mixing Circuit", NULL, "RIN3"}, 3898c2ecf20Sopenharmony_ci {"LIN4 Mixing Circuit", NULL, "LIN4"}, 3908c2ecf20Sopenharmony_ci {"RIN4 Mixing Circuit", NULL, "RIN4"}, 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci {"LOUT1 Mixer", "LINL1", "LIN1 Mixing Circuit"}, 3938c2ecf20Sopenharmony_ci {"ROUT1 Mixer", "RINR1", "RIN1 Mixing Circuit"}, 3948c2ecf20Sopenharmony_ci {"LOUT2 Mixer", "LINH1", "LIN1 Mixing Circuit"}, 3958c2ecf20Sopenharmony_ci {"ROUT2 Mixer", "RINH1", "RIN1 Mixing Circuit"}, 3968c2ecf20Sopenharmony_ci {"LOUT3 Mixer", "LINS1", "LIN1 Mixing Circuit"}, 3978c2ecf20Sopenharmony_ci {"ROUT3 Mixer", "RINS1", "RIN1 Mixing Circuit"}, 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci {"LOUT1 Mixer", "LINL2", "LIN2 Mixing Circuit"}, 4008c2ecf20Sopenharmony_ci {"ROUT1 Mixer", "RINR2", "RIN2 Mixing Circuit"}, 4018c2ecf20Sopenharmony_ci {"LOUT2 Mixer", "LINH2", "LIN2 Mixing Circuit"}, 4028c2ecf20Sopenharmony_ci {"ROUT2 Mixer", "RINH2", "RIN2 Mixing Circuit"}, 4038c2ecf20Sopenharmony_ci {"LOUT3 Mixer", "LINS2", "LIN2 Mixing Circuit"}, 4048c2ecf20Sopenharmony_ci {"ROUT3 Mixer", "RINS2", "RIN2 Mixing Circuit"}, 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci {"LOUT1 Mixer", "LINL3", "LIN3 Mixing Circuit"}, 4078c2ecf20Sopenharmony_ci {"ROUT1 Mixer", "RINR3", "RIN3 Mixing Circuit"}, 4088c2ecf20Sopenharmony_ci {"LOUT2 Mixer", "LINH3", "LIN3 Mixing Circuit"}, 4098c2ecf20Sopenharmony_ci {"ROUT2 Mixer", "RINH3", "RIN3 Mixing Circuit"}, 4108c2ecf20Sopenharmony_ci {"LOUT3 Mixer", "LINS3", "LIN3 Mixing Circuit"}, 4118c2ecf20Sopenharmony_ci {"ROUT3 Mixer", "RINS3", "RIN3 Mixing Circuit"}, 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci {"LOUT1 Mixer", "LINL4", "LIN4 Mixing Circuit"}, 4148c2ecf20Sopenharmony_ci {"ROUT1 Mixer", "RINR4", "RIN4 Mixing Circuit"}, 4158c2ecf20Sopenharmony_ci {"LOUT2 Mixer", "LINH4", "LIN4 Mixing Circuit"}, 4168c2ecf20Sopenharmony_ci {"ROUT2 Mixer", "RINH4", "RIN4 Mixing Circuit"}, 4178c2ecf20Sopenharmony_ci {"LOUT3 Mixer", "LINS4", "LIN4 Mixing Circuit"}, 4188c2ecf20Sopenharmony_ci {"ROUT3 Mixer", "RINS4", "RIN4 Mixing Circuit"}, 4198c2ecf20Sopenharmony_ci}; 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_cistatic int ak4671_hw_params(struct snd_pcm_substream *substream, 4228c2ecf20Sopenharmony_ci struct snd_pcm_hw_params *params, 4238c2ecf20Sopenharmony_ci struct snd_soc_dai *dai) 4248c2ecf20Sopenharmony_ci{ 4258c2ecf20Sopenharmony_ci struct snd_soc_component *component = dai->component; 4268c2ecf20Sopenharmony_ci u8 fs; 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci fs = snd_soc_component_read(component, AK4671_PLL_MODE_SELECT0); 4298c2ecf20Sopenharmony_ci fs &= ~AK4671_FS; 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci switch (params_rate(params)) { 4328c2ecf20Sopenharmony_ci case 8000: 4338c2ecf20Sopenharmony_ci fs |= AK4671_FS_8KHZ; 4348c2ecf20Sopenharmony_ci break; 4358c2ecf20Sopenharmony_ci case 12000: 4368c2ecf20Sopenharmony_ci fs |= AK4671_FS_12KHZ; 4378c2ecf20Sopenharmony_ci break; 4388c2ecf20Sopenharmony_ci case 16000: 4398c2ecf20Sopenharmony_ci fs |= AK4671_FS_16KHZ; 4408c2ecf20Sopenharmony_ci break; 4418c2ecf20Sopenharmony_ci case 24000: 4428c2ecf20Sopenharmony_ci fs |= AK4671_FS_24KHZ; 4438c2ecf20Sopenharmony_ci break; 4448c2ecf20Sopenharmony_ci case 11025: 4458c2ecf20Sopenharmony_ci fs |= AK4671_FS_11_025KHZ; 4468c2ecf20Sopenharmony_ci break; 4478c2ecf20Sopenharmony_ci case 22050: 4488c2ecf20Sopenharmony_ci fs |= AK4671_FS_22_05KHZ; 4498c2ecf20Sopenharmony_ci break; 4508c2ecf20Sopenharmony_ci case 32000: 4518c2ecf20Sopenharmony_ci fs |= AK4671_FS_32KHZ; 4528c2ecf20Sopenharmony_ci break; 4538c2ecf20Sopenharmony_ci case 44100: 4548c2ecf20Sopenharmony_ci fs |= AK4671_FS_44_1KHZ; 4558c2ecf20Sopenharmony_ci break; 4568c2ecf20Sopenharmony_ci case 48000: 4578c2ecf20Sopenharmony_ci fs |= AK4671_FS_48KHZ; 4588c2ecf20Sopenharmony_ci break; 4598c2ecf20Sopenharmony_ci default: 4608c2ecf20Sopenharmony_ci return -EINVAL; 4618c2ecf20Sopenharmony_ci } 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_ci snd_soc_component_write(component, AK4671_PLL_MODE_SELECT0, fs); 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ci return 0; 4668c2ecf20Sopenharmony_ci} 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_cistatic int ak4671_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, 4698c2ecf20Sopenharmony_ci unsigned int freq, int dir) 4708c2ecf20Sopenharmony_ci{ 4718c2ecf20Sopenharmony_ci struct snd_soc_component *component = dai->component; 4728c2ecf20Sopenharmony_ci u8 pll; 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci pll = snd_soc_component_read(component, AK4671_PLL_MODE_SELECT0); 4758c2ecf20Sopenharmony_ci pll &= ~AK4671_PLL; 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_ci switch (freq) { 4788c2ecf20Sopenharmony_ci case 11289600: 4798c2ecf20Sopenharmony_ci pll |= AK4671_PLL_11_2896MHZ; 4808c2ecf20Sopenharmony_ci break; 4818c2ecf20Sopenharmony_ci case 12000000: 4828c2ecf20Sopenharmony_ci pll |= AK4671_PLL_12MHZ; 4838c2ecf20Sopenharmony_ci break; 4848c2ecf20Sopenharmony_ci case 12288000: 4858c2ecf20Sopenharmony_ci pll |= AK4671_PLL_12_288MHZ; 4868c2ecf20Sopenharmony_ci break; 4878c2ecf20Sopenharmony_ci case 13000000: 4888c2ecf20Sopenharmony_ci pll |= AK4671_PLL_13MHZ; 4898c2ecf20Sopenharmony_ci break; 4908c2ecf20Sopenharmony_ci case 13500000: 4918c2ecf20Sopenharmony_ci pll |= AK4671_PLL_13_5MHZ; 4928c2ecf20Sopenharmony_ci break; 4938c2ecf20Sopenharmony_ci case 19200000: 4948c2ecf20Sopenharmony_ci pll |= AK4671_PLL_19_2MHZ; 4958c2ecf20Sopenharmony_ci break; 4968c2ecf20Sopenharmony_ci case 24000000: 4978c2ecf20Sopenharmony_ci pll |= AK4671_PLL_24MHZ; 4988c2ecf20Sopenharmony_ci break; 4998c2ecf20Sopenharmony_ci case 26000000: 5008c2ecf20Sopenharmony_ci pll |= AK4671_PLL_26MHZ; 5018c2ecf20Sopenharmony_ci break; 5028c2ecf20Sopenharmony_ci case 27000000: 5038c2ecf20Sopenharmony_ci pll |= AK4671_PLL_27MHZ; 5048c2ecf20Sopenharmony_ci break; 5058c2ecf20Sopenharmony_ci default: 5068c2ecf20Sopenharmony_ci return -EINVAL; 5078c2ecf20Sopenharmony_ci } 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci snd_soc_component_write(component, AK4671_PLL_MODE_SELECT0, pll); 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_ci return 0; 5128c2ecf20Sopenharmony_ci} 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_cistatic int ak4671_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) 5158c2ecf20Sopenharmony_ci{ 5168c2ecf20Sopenharmony_ci struct snd_soc_component *component = dai->component; 5178c2ecf20Sopenharmony_ci u8 mode; 5188c2ecf20Sopenharmony_ci u8 format; 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci /* set master/slave audio interface */ 5218c2ecf20Sopenharmony_ci mode = snd_soc_component_read(component, AK4671_PLL_MODE_SELECT1); 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 5248c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_CBM_CFM: 5258c2ecf20Sopenharmony_ci mode |= AK4671_M_S; 5268c2ecf20Sopenharmony_ci break; 5278c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_CBM_CFS: 5288c2ecf20Sopenharmony_ci mode &= ~(AK4671_M_S); 5298c2ecf20Sopenharmony_ci break; 5308c2ecf20Sopenharmony_ci default: 5318c2ecf20Sopenharmony_ci return -EINVAL; 5328c2ecf20Sopenharmony_ci } 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_ci /* interface format */ 5358c2ecf20Sopenharmony_ci format = snd_soc_component_read(component, AK4671_FORMAT_SELECT); 5368c2ecf20Sopenharmony_ci format &= ~AK4671_DIF; 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 5398c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_I2S: 5408c2ecf20Sopenharmony_ci format |= AK4671_DIF_I2S_MODE; 5418c2ecf20Sopenharmony_ci break; 5428c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_LEFT_J: 5438c2ecf20Sopenharmony_ci format |= AK4671_DIF_MSB_MODE; 5448c2ecf20Sopenharmony_ci break; 5458c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_DSP_A: 5468c2ecf20Sopenharmony_ci format |= AK4671_DIF_DSP_MODE; 5478c2ecf20Sopenharmony_ci format |= AK4671_BCKP; 5488c2ecf20Sopenharmony_ci format |= AK4671_MSBS; 5498c2ecf20Sopenharmony_ci break; 5508c2ecf20Sopenharmony_ci default: 5518c2ecf20Sopenharmony_ci return -EINVAL; 5528c2ecf20Sopenharmony_ci } 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci /* set mode and format */ 5558c2ecf20Sopenharmony_ci snd_soc_component_write(component, AK4671_PLL_MODE_SELECT1, mode); 5568c2ecf20Sopenharmony_ci snd_soc_component_write(component, AK4671_FORMAT_SELECT, format); 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci return 0; 5598c2ecf20Sopenharmony_ci} 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_cistatic int ak4671_set_bias_level(struct snd_soc_component *component, 5628c2ecf20Sopenharmony_ci enum snd_soc_bias_level level) 5638c2ecf20Sopenharmony_ci{ 5648c2ecf20Sopenharmony_ci switch (level) { 5658c2ecf20Sopenharmony_ci case SND_SOC_BIAS_ON: 5668c2ecf20Sopenharmony_ci case SND_SOC_BIAS_PREPARE: 5678c2ecf20Sopenharmony_ci case SND_SOC_BIAS_STANDBY: 5688c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, AK4671_AD_DA_POWER_MANAGEMENT, 5698c2ecf20Sopenharmony_ci AK4671_PMVCM, AK4671_PMVCM); 5708c2ecf20Sopenharmony_ci break; 5718c2ecf20Sopenharmony_ci case SND_SOC_BIAS_OFF: 5728c2ecf20Sopenharmony_ci snd_soc_component_write(component, AK4671_AD_DA_POWER_MANAGEMENT, 0x00); 5738c2ecf20Sopenharmony_ci break; 5748c2ecf20Sopenharmony_ci } 5758c2ecf20Sopenharmony_ci return 0; 5768c2ecf20Sopenharmony_ci} 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ci#define AK4671_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ 5798c2ecf20Sopenharmony_ci SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\ 5808c2ecf20Sopenharmony_ci SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\ 5818c2ecf20Sopenharmony_ci SNDRV_PCM_RATE_48000) 5828c2ecf20Sopenharmony_ci 5838c2ecf20Sopenharmony_ci#define AK4671_FORMATS SNDRV_PCM_FMTBIT_S16_LE 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_cistatic const struct snd_soc_dai_ops ak4671_dai_ops = { 5868c2ecf20Sopenharmony_ci .hw_params = ak4671_hw_params, 5878c2ecf20Sopenharmony_ci .set_sysclk = ak4671_set_dai_sysclk, 5888c2ecf20Sopenharmony_ci .set_fmt = ak4671_set_dai_fmt, 5898c2ecf20Sopenharmony_ci}; 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_cistatic struct snd_soc_dai_driver ak4671_dai = { 5928c2ecf20Sopenharmony_ci .name = "ak4671-hifi", 5938c2ecf20Sopenharmony_ci .playback = { 5948c2ecf20Sopenharmony_ci .stream_name = "Playback", 5958c2ecf20Sopenharmony_ci .channels_min = 1, 5968c2ecf20Sopenharmony_ci .channels_max = 2, 5978c2ecf20Sopenharmony_ci .rates = AK4671_RATES, 5988c2ecf20Sopenharmony_ci .formats = AK4671_FORMATS,}, 5998c2ecf20Sopenharmony_ci .capture = { 6008c2ecf20Sopenharmony_ci .stream_name = "Capture", 6018c2ecf20Sopenharmony_ci .channels_min = 1, 6028c2ecf20Sopenharmony_ci .channels_max = 2, 6038c2ecf20Sopenharmony_ci .rates = AK4671_RATES, 6048c2ecf20Sopenharmony_ci .formats = AK4671_FORMATS,}, 6058c2ecf20Sopenharmony_ci .ops = &ak4671_dai_ops, 6068c2ecf20Sopenharmony_ci}; 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_cistatic const struct snd_soc_component_driver soc_component_dev_ak4671 = { 6098c2ecf20Sopenharmony_ci .set_bias_level = ak4671_set_bias_level, 6108c2ecf20Sopenharmony_ci .controls = ak4671_snd_controls, 6118c2ecf20Sopenharmony_ci .num_controls = ARRAY_SIZE(ak4671_snd_controls), 6128c2ecf20Sopenharmony_ci .dapm_widgets = ak4671_dapm_widgets, 6138c2ecf20Sopenharmony_ci .num_dapm_widgets = ARRAY_SIZE(ak4671_dapm_widgets), 6148c2ecf20Sopenharmony_ci .dapm_routes = ak4671_intercon, 6158c2ecf20Sopenharmony_ci .num_dapm_routes = ARRAY_SIZE(ak4671_intercon), 6168c2ecf20Sopenharmony_ci .idle_bias_on = 1, 6178c2ecf20Sopenharmony_ci .use_pmdown_time = 1, 6188c2ecf20Sopenharmony_ci .endianness = 1, 6198c2ecf20Sopenharmony_ci .non_legacy_dai_naming = 1, 6208c2ecf20Sopenharmony_ci}; 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_cistatic const struct regmap_config ak4671_regmap = { 6238c2ecf20Sopenharmony_ci .reg_bits = 8, 6248c2ecf20Sopenharmony_ci .val_bits = 8, 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_ci .max_register = AK4671_SAR_ADC_CONTROL, 6278c2ecf20Sopenharmony_ci .reg_defaults = ak4671_reg_defaults, 6288c2ecf20Sopenharmony_ci .num_reg_defaults = ARRAY_SIZE(ak4671_reg_defaults), 6298c2ecf20Sopenharmony_ci .cache_type = REGCACHE_RBTREE, 6308c2ecf20Sopenharmony_ci}; 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_cistatic int ak4671_i2c_probe(struct i2c_client *client, 6338c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 6348c2ecf20Sopenharmony_ci{ 6358c2ecf20Sopenharmony_ci struct regmap *regmap; 6368c2ecf20Sopenharmony_ci int ret; 6378c2ecf20Sopenharmony_ci 6388c2ecf20Sopenharmony_ci regmap = devm_regmap_init_i2c(client, &ak4671_regmap); 6398c2ecf20Sopenharmony_ci if (IS_ERR(regmap)) { 6408c2ecf20Sopenharmony_ci ret = PTR_ERR(regmap); 6418c2ecf20Sopenharmony_ci dev_err(&client->dev, "Failed to create regmap: %d\n", ret); 6428c2ecf20Sopenharmony_ci return ret; 6438c2ecf20Sopenharmony_ci } 6448c2ecf20Sopenharmony_ci 6458c2ecf20Sopenharmony_ci ret = devm_snd_soc_register_component(&client->dev, 6468c2ecf20Sopenharmony_ci &soc_component_dev_ak4671, &ak4671_dai, 1); 6478c2ecf20Sopenharmony_ci return ret; 6488c2ecf20Sopenharmony_ci} 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_cistatic const struct i2c_device_id ak4671_i2c_id[] = { 6518c2ecf20Sopenharmony_ci { "ak4671", 0 }, 6528c2ecf20Sopenharmony_ci { } 6538c2ecf20Sopenharmony_ci}; 6548c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, ak4671_i2c_id); 6558c2ecf20Sopenharmony_ci 6568c2ecf20Sopenharmony_cistatic struct i2c_driver ak4671_i2c_driver = { 6578c2ecf20Sopenharmony_ci .driver = { 6588c2ecf20Sopenharmony_ci .name = "ak4671-codec", 6598c2ecf20Sopenharmony_ci }, 6608c2ecf20Sopenharmony_ci .probe = ak4671_i2c_probe, 6618c2ecf20Sopenharmony_ci .id_table = ak4671_i2c_id, 6628c2ecf20Sopenharmony_ci}; 6638c2ecf20Sopenharmony_ci 6648c2ecf20Sopenharmony_cimodule_i2c_driver(ak4671_i2c_driver); 6658c2ecf20Sopenharmony_ci 6668c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("ASoC AK4671 codec driver"); 6678c2ecf20Sopenharmony_ciMODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); 6688c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 669