16a504a75SDimitris Papastamos /* 26a504a75SDimitris Papastamos * wm8995.c -- WM8995 ALSA SoC Audio driver 36a504a75SDimitris Papastamos * 46a504a75SDimitris Papastamos * Copyright 2010 Wolfson Microelectronics plc 56a504a75SDimitris Papastamos * 66a504a75SDimitris Papastamos * Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> 76a504a75SDimitris Papastamos * 86a504a75SDimitris Papastamos * Based on wm8994.c and wm_hubs.c by Mark Brown 96a504a75SDimitris Papastamos * 106a504a75SDimitris Papastamos * This program is free software; you can redistribute it and/or modify 116a504a75SDimitris Papastamos * it under the terms of the GNU General Public License version 2 as 126a504a75SDimitris Papastamos * published by the Free Software Foundation. 136a504a75SDimitris Papastamos */ 146a504a75SDimitris Papastamos 156a504a75SDimitris Papastamos #include <linux/module.h> 166a504a75SDimitris Papastamos #include <linux/moduleparam.h> 176a504a75SDimitris Papastamos #include <linux/init.h> 186a504a75SDimitris Papastamos #include <linux/delay.h> 196a504a75SDimitris Papastamos #include <linux/pm.h> 206a504a75SDimitris Papastamos #include <linux/i2c.h> 216a504a75SDimitris Papastamos #include <linux/spi/spi.h> 226a504a75SDimitris Papastamos #include <linux/slab.h> 236a504a75SDimitris Papastamos #include <sound/core.h> 246a504a75SDimitris Papastamos #include <sound/pcm.h> 256a504a75SDimitris Papastamos #include <sound/pcm_params.h> 266a504a75SDimitris Papastamos #include <sound/soc.h> 276a504a75SDimitris Papastamos #include <sound/soc-dapm.h> 286a504a75SDimitris Papastamos #include <sound/initval.h> 296a504a75SDimitris Papastamos #include <sound/tlv.h> 306a504a75SDimitris Papastamos 316a504a75SDimitris Papastamos #include "wm8995.h" 326a504a75SDimitris Papastamos 3303cfbdf9STakashi Iwai static const u16 wm8995_reg_defs[WM8995_MAX_REGISTER + 1] = { 346a504a75SDimitris Papastamos [0] = 0x8995, [5] = 0x0100, [16] = 0x000b, [17] = 0x000b, 356a504a75SDimitris Papastamos [24] = 0x02c0, [25] = 0x02c0, [26] = 0x02c0, [27] = 0x02c0, 366a504a75SDimitris Papastamos [28] = 0x000f, [32] = 0x0005, [33] = 0x0005, [40] = 0x0003, 376a504a75SDimitris Papastamos [41] = 0x0013, [48] = 0x0004, [56] = 0x09f8, [64] = 0x1f25, 386a504a75SDimitris Papastamos [69] = 0x0004, [82] = 0xaaaa, [84] = 0x2a2a, [146] = 0x0060, 396a504a75SDimitris Papastamos [256] = 0x0002, [257] = 0x8004, [520] = 0x0010, [528] = 0x0083, 406a504a75SDimitris Papastamos [529] = 0x0083, [548] = 0x0c80, [580] = 0x0c80, [768] = 0x4050, 416a504a75SDimitris Papastamos [769] = 0x4000, [771] = 0x0040, [772] = 0x0040, [773] = 0x0040, 426a504a75SDimitris Papastamos [774] = 0x0004, [775] = 0x0100, [784] = 0x4050, [785] = 0x4000, 436a504a75SDimitris Papastamos [787] = 0x0040, [788] = 0x0040, [789] = 0x0040, [1024] = 0x00c0, 446a504a75SDimitris Papastamos [1025] = 0x00c0, [1026] = 0x00c0, [1027] = 0x00c0, [1028] = 0x00c0, 456a504a75SDimitris Papastamos [1029] = 0x00c0, [1030] = 0x00c0, [1031] = 0x00c0, [1056] = 0x0200, 466a504a75SDimitris Papastamos [1057] = 0x0010, [1058] = 0x0200, [1059] = 0x0010, [1088] = 0x0098, 476a504a75SDimitris Papastamos [1089] = 0x0845, [1104] = 0x0098, [1105] = 0x0845, [1152] = 0x6318, 486a504a75SDimitris Papastamos [1153] = 0x6300, [1154] = 0x0fca, [1155] = 0x0400, [1156] = 0x00d8, 496a504a75SDimitris Papastamos [1157] = 0x1eb5, [1158] = 0xf145, [1159] = 0x0b75, [1160] = 0x01c5, 506a504a75SDimitris Papastamos [1161] = 0x1c58, [1162] = 0xf373, [1163] = 0x0a54, [1164] = 0x0558, 516a504a75SDimitris Papastamos [1165] = 0x168e, [1166] = 0xf829, [1167] = 0x07ad, [1168] = 0x1103, 526a504a75SDimitris Papastamos [1169] = 0x0564, [1170] = 0x0559, [1171] = 0x4000, [1184] = 0x6318, 536a504a75SDimitris Papastamos [1185] = 0x6300, [1186] = 0x0fca, [1187] = 0x0400, [1188] = 0x00d8, 546a504a75SDimitris Papastamos [1189] = 0x1eb5, [1190] = 0xf145, [1191] = 0x0b75, [1192] = 0x01c5, 556a504a75SDimitris Papastamos [1193] = 0x1c58, [1194] = 0xf373, [1195] = 0x0a54, [1196] = 0x0558, 566a504a75SDimitris Papastamos [1197] = 0x168e, [1198] = 0xf829, [1199] = 0x07ad, [1200] = 0x1103, 576a504a75SDimitris Papastamos [1201] = 0x0564, [1202] = 0x0559, [1203] = 0x4000, [1280] = 0x00c0, 586a504a75SDimitris Papastamos [1281] = 0x00c0, [1282] = 0x00c0, [1283] = 0x00c0, [1312] = 0x0200, 596a504a75SDimitris Papastamos [1313] = 0x0010, [1344] = 0x0098, [1345] = 0x0845, [1408] = 0x6318, 606a504a75SDimitris Papastamos [1409] = 0x6300, [1410] = 0x0fca, [1411] = 0x0400, [1412] = 0x00d8, 616a504a75SDimitris Papastamos [1413] = 0x1eb5, [1414] = 0xf145, [1415] = 0x0b75, [1416] = 0x01c5, 626a504a75SDimitris Papastamos [1417] = 0x1c58, [1418] = 0xf373, [1419] = 0x0a54, [1420] = 0x0558, 636a504a75SDimitris Papastamos [1421] = 0x168e, [1422] = 0xf829, [1423] = 0x07ad, [1424] = 0x1103, 646a504a75SDimitris Papastamos [1425] = 0x0564, [1426] = 0x0559, [1427] = 0x4000, [1568] = 0x0002, 656a504a75SDimitris Papastamos [1792] = 0xa100, [1793] = 0xa101, [1794] = 0xa101, [1795] = 0xa101, 666a504a75SDimitris Papastamos [1796] = 0xa101, [1797] = 0xa101, [1798] = 0xa101, [1799] = 0xa101, 676a504a75SDimitris Papastamos [1800] = 0xa101, [1801] = 0xa101, [1802] = 0xa101, [1803] = 0xa101, 686a504a75SDimitris Papastamos [1804] = 0xa101, [1805] = 0xa101, [1825] = 0x0055, [1848] = 0x3fff, 696a504a75SDimitris Papastamos [1849] = 0x1fff, [2049] = 0x0001, [2050] = 0x0069, [2056] = 0x0002, 706a504a75SDimitris Papastamos [2057] = 0x0003, [2058] = 0x0069, [12288] = 0x0001, [12289] = 0x0001, 716a504a75SDimitris Papastamos [12291] = 0x0006, [12292] = 0x0040, [12293] = 0x0001, [12294] = 0x000f, 726a504a75SDimitris Papastamos [12295] = 0x0006, [12296] = 0x0001, [12297] = 0x0003, [12298] = 0x0104, 736a504a75SDimitris Papastamos [12300] = 0x0060, [12301] = 0x0011, [12302] = 0x0401, [12304] = 0x0050, 746a504a75SDimitris Papastamos [12305] = 0x0003, [12306] = 0x0100, [12308] = 0x0051, [12309] = 0x0003, 756a504a75SDimitris Papastamos [12310] = 0x0104, [12311] = 0x000a, [12312] = 0x0060, [12313] = 0x003b, 766a504a75SDimitris Papastamos [12314] = 0x0502, [12315] = 0x0100, [12316] = 0x2fff, [12320] = 0x2fff, 776a504a75SDimitris Papastamos [12324] = 0x2fff, [12328] = 0x2fff, [12332] = 0x2fff, [12336] = 0x2fff, 786a504a75SDimitris Papastamos [12340] = 0x2fff, [12344] = 0x2fff, [12348] = 0x2fff, [12352] = 0x0001, 796a504a75SDimitris Papastamos [12353] = 0x0001, [12355] = 0x0006, [12356] = 0x0040, [12357] = 0x0001, 806a504a75SDimitris Papastamos [12358] = 0x000f, [12359] = 0x0006, [12360] = 0x0001, [12361] = 0x0003, 816a504a75SDimitris Papastamos [12362] = 0x0104, [12364] = 0x0060, [12365] = 0x0011, [12366] = 0x0401, 826a504a75SDimitris Papastamos [12368] = 0x0050, [12369] = 0x0003, [12370] = 0x0100, [12372] = 0x0060, 836a504a75SDimitris Papastamos [12373] = 0x003b, [12374] = 0x0502, [12375] = 0x0100, [12376] = 0x2fff, 846a504a75SDimitris Papastamos [12380] = 0x2fff, [12384] = 0x2fff, [12388] = 0x2fff, [12392] = 0x2fff, 856a504a75SDimitris Papastamos [12396] = 0x2fff, [12400] = 0x2fff, [12404] = 0x2fff, [12408] = 0x2fff, 866a504a75SDimitris Papastamos [12412] = 0x2fff, [12416] = 0x0001, [12417] = 0x0001, [12419] = 0x0006, 876a504a75SDimitris Papastamos [12420] = 0x0040, [12421] = 0x0001, [12422] = 0x000f, [12423] = 0x0006, 886a504a75SDimitris Papastamos [12424] = 0x0001, [12425] = 0x0003, [12426] = 0x0106, [12428] = 0x0061, 896a504a75SDimitris Papastamos [12429] = 0x0011, [12430] = 0x0401, [12432] = 0x0050, [12433] = 0x0003, 906a504a75SDimitris Papastamos [12434] = 0x0102, [12436] = 0x0051, [12437] = 0x0003, [12438] = 0x0106, 916a504a75SDimitris Papastamos [12439] = 0x000a, [12440] = 0x0061, [12441] = 0x003b, [12442] = 0x0502, 926a504a75SDimitris Papastamos [12443] = 0x0100, [12444] = 0x2fff, [12448] = 0x2fff, [12452] = 0x2fff, 936a504a75SDimitris Papastamos [12456] = 0x2fff, [12460] = 0x2fff, [12464] = 0x2fff, [12468] = 0x2fff, 946a504a75SDimitris Papastamos [12472] = 0x2fff, [12476] = 0x2fff, [12480] = 0x0001, [12481] = 0x0001, 956a504a75SDimitris Papastamos [12483] = 0x0006, [12484] = 0x0040, [12485] = 0x0001, [12486] = 0x000f, 966a504a75SDimitris Papastamos [12487] = 0x0006, [12488] = 0x0001, [12489] = 0x0003, [12490] = 0x0106, 976a504a75SDimitris Papastamos [12492] = 0x0061, [12493] = 0x0011, [12494] = 0x0401, [12496] = 0x0050, 986a504a75SDimitris Papastamos [12497] = 0x0003, [12498] = 0x0102, [12500] = 0x0061, [12501] = 0x003b, 996a504a75SDimitris Papastamos [12502] = 0x0502, [12503] = 0x0100, [12504] = 0x2fff, [12508] = 0x2fff, 1006a504a75SDimitris Papastamos [12512] = 0x2fff, [12516] = 0x2fff, [12520] = 0x2fff, [12524] = 0x2fff, 1016a504a75SDimitris Papastamos [12528] = 0x2fff, [12532] = 0x2fff, [12536] = 0x2fff, [12540] = 0x2fff, 1026a504a75SDimitris Papastamos [12544] = 0x0060, [12546] = 0x0601, [12548] = 0x0050, [12550] = 0x0100, 1036a504a75SDimitris Papastamos [12552] = 0x0001, [12554] = 0x0104, [12555] = 0x0100, [12556] = 0x2fff, 1046a504a75SDimitris Papastamos [12560] = 0x2fff, [12564] = 0x2fff, [12568] = 0x2fff, [12572] = 0x2fff, 1056a504a75SDimitris Papastamos [12576] = 0x2fff, [12580] = 0x2fff, [12584] = 0x2fff, [12588] = 0x2fff, 1066a504a75SDimitris Papastamos [12592] = 0x2fff, [12596] = 0x2fff, [12600] = 0x2fff, [12604] = 0x2fff, 1076a504a75SDimitris Papastamos [12608] = 0x0061, [12610] = 0x0601, [12612] = 0x0050, [12614] = 0x0102, 1086a504a75SDimitris Papastamos [12616] = 0x0001, [12618] = 0x0106, [12619] = 0x0100, [12620] = 0x2fff, 1096a504a75SDimitris Papastamos [12624] = 0x2fff, [12628] = 0x2fff, [12632] = 0x2fff, [12636] = 0x2fff, 1106a504a75SDimitris Papastamos [12640] = 0x2fff, [12644] = 0x2fff, [12648] = 0x2fff, [12652] = 0x2fff, 1116a504a75SDimitris Papastamos [12656] = 0x2fff, [12660] = 0x2fff, [12664] = 0x2fff, [12668] = 0x2fff, 1126a504a75SDimitris Papastamos [12672] = 0x0060, [12674] = 0x0601, [12676] = 0x0061, [12678] = 0x0601, 1136a504a75SDimitris Papastamos [12680] = 0x0050, [12682] = 0x0300, [12684] = 0x0001, [12686] = 0x0304, 1146a504a75SDimitris Papastamos [12688] = 0x0040, [12690] = 0x000f, [12692] = 0x0001, [12695] = 0x0100 1156a504a75SDimitris Papastamos }; 1166a504a75SDimitris Papastamos 1176a504a75SDimitris Papastamos struct fll_config { 1186a504a75SDimitris Papastamos int src; 1196a504a75SDimitris Papastamos int in; 1206a504a75SDimitris Papastamos int out; 1216a504a75SDimitris Papastamos }; 1226a504a75SDimitris Papastamos 1236a504a75SDimitris Papastamos struct wm8995_priv { 1246a504a75SDimitris Papastamos enum snd_soc_control_type control_type; 1256a504a75SDimitris Papastamos int sysclk[2]; 1266a504a75SDimitris Papastamos int mclk[2]; 1276a504a75SDimitris Papastamos int aifclk[2]; 1286a504a75SDimitris Papastamos struct fll_config fll[2], fll_suspend[2]; 1296a504a75SDimitris Papastamos }; 1306a504a75SDimitris Papastamos 1316a504a75SDimitris Papastamos static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1); 1326a504a75SDimitris Papastamos static const DECLARE_TLV_DB_SCALE(in1lr_pga_tlv, -1650, 150, 0); 1336a504a75SDimitris Papastamos static const DECLARE_TLV_DB_SCALE(in1l_boost_tlv, 0, 600, 0); 1346a504a75SDimitris Papastamos static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -3600, 150, 0); 1356a504a75SDimitris Papastamos 1366a504a75SDimitris Papastamos static const char *in1l_text[] = { 1376a504a75SDimitris Papastamos "Differential", "Single-ended IN1LN", "Single-ended IN1LP" 1386a504a75SDimitris Papastamos }; 1396a504a75SDimitris Papastamos 1406a504a75SDimitris Papastamos static const SOC_ENUM_SINGLE_DECL(in1l_enum, WM8995_LEFT_LINE_INPUT_CONTROL, 1416a504a75SDimitris Papastamos 2, in1l_text); 1426a504a75SDimitris Papastamos 1436a504a75SDimitris Papastamos static const char *in1r_text[] = { 1446a504a75SDimitris Papastamos "Differential", "Single-ended IN1RN", "Single-ended IN1RP" 1456a504a75SDimitris Papastamos }; 1466a504a75SDimitris Papastamos 1476a504a75SDimitris Papastamos static const SOC_ENUM_SINGLE_DECL(in1r_enum, WM8995_LEFT_LINE_INPUT_CONTROL, 1486a504a75SDimitris Papastamos 0, in1r_text); 1496a504a75SDimitris Papastamos 1506a504a75SDimitris Papastamos static const char *dmic_src_text[] = { 1516a504a75SDimitris Papastamos "DMICDAT1", "DMICDAT2", "DMICDAT3" 1526a504a75SDimitris Papastamos }; 1536a504a75SDimitris Papastamos 1546a504a75SDimitris Papastamos static const SOC_ENUM_SINGLE_DECL(dmic_src1_enum, WM8995_POWER_MANAGEMENT_5, 1556a504a75SDimitris Papastamos 8, dmic_src_text); 1566a504a75SDimitris Papastamos static const SOC_ENUM_SINGLE_DECL(dmic_src2_enum, WM8995_POWER_MANAGEMENT_5, 1576a504a75SDimitris Papastamos 6, dmic_src_text); 1586a504a75SDimitris Papastamos 1596a504a75SDimitris Papastamos static const struct snd_kcontrol_new wm8995_snd_controls[] = { 1606a504a75SDimitris Papastamos SOC_DOUBLE_R_TLV("DAC1 Volume", WM8995_DAC1_LEFT_VOLUME, 1616a504a75SDimitris Papastamos WM8995_DAC1_RIGHT_VOLUME, 0, 96, 0, digital_tlv), 1626a504a75SDimitris Papastamos SOC_DOUBLE_R("DAC1 Switch", WM8995_DAC1_LEFT_VOLUME, 1636a504a75SDimitris Papastamos WM8995_DAC1_RIGHT_VOLUME, 9, 1, 1), 1646a504a75SDimitris Papastamos 1656a504a75SDimitris Papastamos SOC_DOUBLE_R_TLV("DAC2 Volume", WM8995_DAC2_LEFT_VOLUME, 1666a504a75SDimitris Papastamos WM8995_DAC2_RIGHT_VOLUME, 0, 96, 0, digital_tlv), 1676a504a75SDimitris Papastamos SOC_DOUBLE_R("DAC2 Switch", WM8995_DAC2_LEFT_VOLUME, 1686a504a75SDimitris Papastamos WM8995_DAC2_RIGHT_VOLUME, 9, 1, 1), 1696a504a75SDimitris Papastamos 1706a504a75SDimitris Papastamos SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8995_AIF1_DAC1_LEFT_VOLUME, 1716a504a75SDimitris Papastamos WM8995_AIF1_DAC1_RIGHT_VOLUME, 0, 96, 0, digital_tlv), 1726a504a75SDimitris Papastamos SOC_DOUBLE_R_TLV("AIF1DAC2 Volume", WM8995_AIF1_DAC2_LEFT_VOLUME, 1736a504a75SDimitris Papastamos WM8995_AIF1_DAC2_RIGHT_VOLUME, 0, 96, 0, digital_tlv), 1746a504a75SDimitris Papastamos SOC_DOUBLE_R_TLV("AIF2DAC Volume", WM8995_AIF2_DAC_LEFT_VOLUME, 1756a504a75SDimitris Papastamos WM8995_AIF2_DAC_RIGHT_VOLUME, 0, 96, 0, digital_tlv), 1766a504a75SDimitris Papastamos 1776a504a75SDimitris Papastamos SOC_DOUBLE_R_TLV("IN1LR Volume", WM8995_LEFT_LINE_INPUT_1_VOLUME, 1786a504a75SDimitris Papastamos WM8995_RIGHT_LINE_INPUT_1_VOLUME, 0, 31, 0, in1lr_pga_tlv), 1796a504a75SDimitris Papastamos 1806a504a75SDimitris Papastamos SOC_SINGLE_TLV("IN1L Boost", WM8995_LEFT_LINE_INPUT_CONTROL, 1816a504a75SDimitris Papastamos 4, 3, 0, in1l_boost_tlv), 1826a504a75SDimitris Papastamos 1836a504a75SDimitris Papastamos SOC_ENUM("IN1L Mode", in1l_enum), 1846a504a75SDimitris Papastamos SOC_ENUM("IN1R Mode", in1r_enum), 1856a504a75SDimitris Papastamos 1866a504a75SDimitris Papastamos SOC_ENUM("DMIC1 SRC", dmic_src1_enum), 1876a504a75SDimitris Papastamos SOC_ENUM("DMIC2 SRC", dmic_src2_enum), 1886a504a75SDimitris Papastamos 1896a504a75SDimitris Papastamos SOC_DOUBLE_TLV("DAC1 Sidetone Volume", WM8995_DAC1_MIXER_VOLUMES, 0, 5, 1906a504a75SDimitris Papastamos 24, 0, sidetone_tlv), 1916a504a75SDimitris Papastamos SOC_DOUBLE_TLV("DAC2 Sidetone Volume", WM8995_DAC2_MIXER_VOLUMES, 0, 5, 1926a504a75SDimitris Papastamos 24, 0, sidetone_tlv), 1936a504a75SDimitris Papastamos 1946a504a75SDimitris Papastamos SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8995_AIF1_ADC1_LEFT_VOLUME, 1956a504a75SDimitris Papastamos WM8995_AIF1_ADC1_RIGHT_VOLUME, 0, 96, 0, digital_tlv), 1966a504a75SDimitris Papastamos SOC_DOUBLE_R_TLV("AIF1ADC2 Volume", WM8995_AIF1_ADC2_LEFT_VOLUME, 1976a504a75SDimitris Papastamos WM8995_AIF1_ADC2_RIGHT_VOLUME, 0, 96, 0, digital_tlv), 1986a504a75SDimitris Papastamos SOC_DOUBLE_R_TLV("AIF2ADC Volume", WM8995_AIF2_ADC_LEFT_VOLUME, 1996a504a75SDimitris Papastamos WM8995_AIF2_ADC_RIGHT_VOLUME, 0, 96, 0, digital_tlv) 2006a504a75SDimitris Papastamos }; 2016a504a75SDimitris Papastamos 2026a504a75SDimitris Papastamos static void wm8995_update_class_w(struct snd_soc_codec *codec) 2036a504a75SDimitris Papastamos { 2046a504a75SDimitris Papastamos int enable = 1; 2056a504a75SDimitris Papastamos int source = 0; /* GCC flow analysis can't track enable */ 2066a504a75SDimitris Papastamos int reg, reg_r; 2076a504a75SDimitris Papastamos 2086a504a75SDimitris Papastamos /* We also need the same setting for L/R and only one path */ 2096a504a75SDimitris Papastamos reg = snd_soc_read(codec, WM8995_DAC1_LEFT_MIXER_ROUTING); 2106a504a75SDimitris Papastamos switch (reg) { 2116a504a75SDimitris Papastamos case WM8995_AIF2DACL_TO_DAC1L: 2126a504a75SDimitris Papastamos dev_dbg(codec->dev, "Class W source AIF2DAC\n"); 2136a504a75SDimitris Papastamos source = 2 << WM8995_CP_DYN_SRC_SEL_SHIFT; 2146a504a75SDimitris Papastamos break; 2156a504a75SDimitris Papastamos case WM8995_AIF1DAC2L_TO_DAC1L: 2166a504a75SDimitris Papastamos dev_dbg(codec->dev, "Class W source AIF1DAC2\n"); 2176a504a75SDimitris Papastamos source = 1 << WM8995_CP_DYN_SRC_SEL_SHIFT; 2186a504a75SDimitris Papastamos break; 2196a504a75SDimitris Papastamos case WM8995_AIF1DAC1L_TO_DAC1L: 2206a504a75SDimitris Papastamos dev_dbg(codec->dev, "Class W source AIF1DAC1\n"); 2216a504a75SDimitris Papastamos source = 0 << WM8995_CP_DYN_SRC_SEL_SHIFT; 2226a504a75SDimitris Papastamos break; 2236a504a75SDimitris Papastamos default: 2246a504a75SDimitris Papastamos dev_dbg(codec->dev, "DAC mixer setting: %x\n", reg); 2256a504a75SDimitris Papastamos enable = 0; 2266a504a75SDimitris Papastamos break; 2276a504a75SDimitris Papastamos } 2286a504a75SDimitris Papastamos 2296a504a75SDimitris Papastamos reg_r = snd_soc_read(codec, WM8995_DAC1_RIGHT_MIXER_ROUTING); 2306a504a75SDimitris Papastamos if (reg_r != reg) { 2316a504a75SDimitris Papastamos dev_dbg(codec->dev, "Left and right DAC mixers different\n"); 2326a504a75SDimitris Papastamos enable = 0; 2336a504a75SDimitris Papastamos } 2346a504a75SDimitris Papastamos 2356a504a75SDimitris Papastamos if (enable) { 2366a504a75SDimitris Papastamos dev_dbg(codec->dev, "Class W enabled\n"); 2376a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_CLASS_W_1, 2386a504a75SDimitris Papastamos WM8995_CP_DYN_PWR_MASK | 2396a504a75SDimitris Papastamos WM8995_CP_DYN_SRC_SEL_MASK, 2406a504a75SDimitris Papastamos source | WM8995_CP_DYN_PWR); 2416a504a75SDimitris Papastamos } else { 2426a504a75SDimitris Papastamos dev_dbg(codec->dev, "Class W disabled\n"); 2436a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_CLASS_W_1, 2446a504a75SDimitris Papastamos WM8995_CP_DYN_PWR_MASK, 0); 2456a504a75SDimitris Papastamos } 2466a504a75SDimitris Papastamos } 2476a504a75SDimitris Papastamos 2486a504a75SDimitris Papastamos static int check_clk_sys(struct snd_soc_dapm_widget *source, 2496a504a75SDimitris Papastamos struct snd_soc_dapm_widget *sink) 2506a504a75SDimitris Papastamos { 2516a504a75SDimitris Papastamos unsigned int reg; 2526a504a75SDimitris Papastamos const char *clk; 2536a504a75SDimitris Papastamos 2546a504a75SDimitris Papastamos reg = snd_soc_read(source->codec, WM8995_CLOCKING_1); 2556a504a75SDimitris Papastamos /* Check what we're currently using for CLK_SYS */ 2566a504a75SDimitris Papastamos if (reg & WM8995_SYSCLK_SRC) 2576a504a75SDimitris Papastamos clk = "AIF2CLK"; 2586a504a75SDimitris Papastamos else 2596a504a75SDimitris Papastamos clk = "AIF1CLK"; 2606a504a75SDimitris Papastamos return !strcmp(source->name, clk); 2616a504a75SDimitris Papastamos } 2626a504a75SDimitris Papastamos 2636a504a75SDimitris Papastamos static int wm8995_put_class_w(struct snd_kcontrol *kcontrol, 2646a504a75SDimitris Papastamos struct snd_ctl_elem_value *ucontrol) 2656a504a75SDimitris Papastamos { 2666a504a75SDimitris Papastamos struct snd_soc_dapm_widget *w; 2676a504a75SDimitris Papastamos struct snd_soc_codec *codec; 2686a504a75SDimitris Papastamos int ret; 2696a504a75SDimitris Papastamos 2706a504a75SDimitris Papastamos w = snd_kcontrol_chip(kcontrol); 2716a504a75SDimitris Papastamos codec = w->codec; 2726a504a75SDimitris Papastamos ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol); 2736a504a75SDimitris Papastamos wm8995_update_class_w(codec); 2746a504a75SDimitris Papastamos return ret; 2756a504a75SDimitris Papastamos } 2766a504a75SDimitris Papastamos 2776a504a75SDimitris Papastamos static int hp_supply_event(struct snd_soc_dapm_widget *w, 2786a504a75SDimitris Papastamos struct snd_kcontrol *kcontrol, int event) 2796a504a75SDimitris Papastamos { 2806a504a75SDimitris Papastamos struct snd_soc_codec *codec; 2816a504a75SDimitris Papastamos struct wm8995_priv *wm8995; 2826a504a75SDimitris Papastamos 2836a504a75SDimitris Papastamos codec = w->codec; 2846a504a75SDimitris Papastamos wm8995 = snd_soc_codec_get_drvdata(codec); 2856a504a75SDimitris Papastamos 2866a504a75SDimitris Papastamos switch (event) { 2876a504a75SDimitris Papastamos case SND_SOC_DAPM_PRE_PMU: 2886a504a75SDimitris Papastamos /* Enable the headphone amp */ 2896a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1, 2906a504a75SDimitris Papastamos WM8995_HPOUT1L_ENA_MASK | 2916a504a75SDimitris Papastamos WM8995_HPOUT1R_ENA_MASK, 2926a504a75SDimitris Papastamos WM8995_HPOUT1L_ENA | 2936a504a75SDimitris Papastamos WM8995_HPOUT1R_ENA); 2946a504a75SDimitris Papastamos 2956a504a75SDimitris Papastamos /* Enable the second stage */ 2966a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_ANALOGUE_HP_1, 2976a504a75SDimitris Papastamos WM8995_HPOUT1L_DLY_MASK | 2986a504a75SDimitris Papastamos WM8995_HPOUT1R_DLY_MASK, 2996a504a75SDimitris Papastamos WM8995_HPOUT1L_DLY | 3006a504a75SDimitris Papastamos WM8995_HPOUT1R_DLY); 3016a504a75SDimitris Papastamos break; 3026a504a75SDimitris Papastamos case SND_SOC_DAPM_PRE_PMD: 3036a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_CHARGE_PUMP_1, 3046a504a75SDimitris Papastamos WM8995_CP_ENA_MASK, 0); 3056a504a75SDimitris Papastamos break; 3066a504a75SDimitris Papastamos } 3076a504a75SDimitris Papastamos 3086a504a75SDimitris Papastamos return 0; 3096a504a75SDimitris Papastamos } 3106a504a75SDimitris Papastamos 3116a504a75SDimitris Papastamos static void dc_servo_cmd(struct snd_soc_codec *codec, 3126a504a75SDimitris Papastamos unsigned int reg, unsigned int val, unsigned int mask) 3136a504a75SDimitris Papastamos { 3146a504a75SDimitris Papastamos int timeout = 10; 3156a504a75SDimitris Papastamos 3166a504a75SDimitris Papastamos dev_dbg(codec->dev, "%s: reg = %#x, val = %#x, mask = %#x\n", 3176a504a75SDimitris Papastamos __func__, reg, val, mask); 3186a504a75SDimitris Papastamos 3196a504a75SDimitris Papastamos snd_soc_write(codec, reg, val); 3206a504a75SDimitris Papastamos while (timeout--) { 3216a504a75SDimitris Papastamos msleep(10); 3226a504a75SDimitris Papastamos val = snd_soc_read(codec, WM8995_DC_SERVO_READBACK_0); 3236a504a75SDimitris Papastamos if ((val & mask) == mask) 3246a504a75SDimitris Papastamos return; 3256a504a75SDimitris Papastamos } 3266a504a75SDimitris Papastamos 3276a504a75SDimitris Papastamos dev_err(codec->dev, "Timed out waiting for DC Servo\n"); 3286a504a75SDimitris Papastamos } 3296a504a75SDimitris Papastamos 3306a504a75SDimitris Papastamos static int hp_event(struct snd_soc_dapm_widget *w, 3316a504a75SDimitris Papastamos struct snd_kcontrol *kcontrol, int event) 3326a504a75SDimitris Papastamos { 3336a504a75SDimitris Papastamos struct snd_soc_codec *codec; 3346a504a75SDimitris Papastamos unsigned int reg; 3356a504a75SDimitris Papastamos 3366a504a75SDimitris Papastamos codec = w->codec; 3376a504a75SDimitris Papastamos reg = snd_soc_read(codec, WM8995_ANALOGUE_HP_1); 3386a504a75SDimitris Papastamos 3396a504a75SDimitris Papastamos switch (event) { 3406a504a75SDimitris Papastamos case SND_SOC_DAPM_POST_PMU: 3416a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_CHARGE_PUMP_1, 3426a504a75SDimitris Papastamos WM8995_CP_ENA_MASK, WM8995_CP_ENA); 3436a504a75SDimitris Papastamos 3446a504a75SDimitris Papastamos msleep(5); 3456a504a75SDimitris Papastamos 3466a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1, 3476a504a75SDimitris Papastamos WM8995_HPOUT1L_ENA_MASK | 3486a504a75SDimitris Papastamos WM8995_HPOUT1R_ENA_MASK, 3496a504a75SDimitris Papastamos WM8995_HPOUT1L_ENA | WM8995_HPOUT1R_ENA); 3506a504a75SDimitris Papastamos 3516a504a75SDimitris Papastamos udelay(20); 3526a504a75SDimitris Papastamos 3536a504a75SDimitris Papastamos reg |= WM8995_HPOUT1L_DLY | WM8995_HPOUT1R_DLY; 3546a504a75SDimitris Papastamos snd_soc_write(codec, WM8995_ANALOGUE_HP_1, reg); 3556a504a75SDimitris Papastamos 3566a504a75SDimitris Papastamos snd_soc_write(codec, WM8995_DC_SERVO_1, WM8995_DCS_ENA_CHAN_0 | 3576a504a75SDimitris Papastamos WM8995_DCS_ENA_CHAN_1); 3586a504a75SDimitris Papastamos 3596a504a75SDimitris Papastamos dc_servo_cmd(codec, WM8995_DC_SERVO_2, 3606a504a75SDimitris Papastamos WM8995_DCS_TRIG_STARTUP_0 | 3616a504a75SDimitris Papastamos WM8995_DCS_TRIG_STARTUP_1, 3626a504a75SDimitris Papastamos WM8995_DCS_TRIG_DAC_WR_0 | 3636a504a75SDimitris Papastamos WM8995_DCS_TRIG_DAC_WR_1); 3646a504a75SDimitris Papastamos 3656a504a75SDimitris Papastamos reg |= WM8995_HPOUT1R_OUTP | WM8995_HPOUT1R_RMV_SHORT | 3666a504a75SDimitris Papastamos WM8995_HPOUT1L_OUTP | WM8995_HPOUT1L_RMV_SHORT; 3676a504a75SDimitris Papastamos snd_soc_write(codec, WM8995_ANALOGUE_HP_1, reg); 3686a504a75SDimitris Papastamos 3696a504a75SDimitris Papastamos break; 3706a504a75SDimitris Papastamos case SND_SOC_DAPM_PRE_PMD: 3716a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_ANALOGUE_HP_1, 3726a504a75SDimitris Papastamos WM8995_HPOUT1L_OUTP_MASK | 3736a504a75SDimitris Papastamos WM8995_HPOUT1R_OUTP_MASK | 3746a504a75SDimitris Papastamos WM8995_HPOUT1L_RMV_SHORT_MASK | 3756a504a75SDimitris Papastamos WM8995_HPOUT1R_RMV_SHORT_MASK, 0); 3766a504a75SDimitris Papastamos 3776a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_ANALOGUE_HP_1, 3786a504a75SDimitris Papastamos WM8995_HPOUT1L_DLY_MASK | 3796a504a75SDimitris Papastamos WM8995_HPOUT1R_DLY_MASK, 0); 3806a504a75SDimitris Papastamos 3816a504a75SDimitris Papastamos snd_soc_write(codec, WM8995_DC_SERVO_1, 0); 3826a504a75SDimitris Papastamos 3836a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1, 3846a504a75SDimitris Papastamos WM8995_HPOUT1L_ENA_MASK | 3856a504a75SDimitris Papastamos WM8995_HPOUT1R_ENA_MASK, 3866a504a75SDimitris Papastamos 0); 3876a504a75SDimitris Papastamos break; 3886a504a75SDimitris Papastamos } 3896a504a75SDimitris Papastamos 3906a504a75SDimitris Papastamos return 0; 3916a504a75SDimitris Papastamos } 3926a504a75SDimitris Papastamos 3936a504a75SDimitris Papastamos static int configure_aif_clock(struct snd_soc_codec *codec, int aif) 3946a504a75SDimitris Papastamos { 3956a504a75SDimitris Papastamos struct wm8995_priv *wm8995; 3966a504a75SDimitris Papastamos int rate; 3976a504a75SDimitris Papastamos int reg1 = 0; 3986a504a75SDimitris Papastamos int offset; 3996a504a75SDimitris Papastamos 4006a504a75SDimitris Papastamos wm8995 = snd_soc_codec_get_drvdata(codec); 4016a504a75SDimitris Papastamos 4026a504a75SDimitris Papastamos if (aif) 4036a504a75SDimitris Papastamos offset = 4; 4046a504a75SDimitris Papastamos else 4056a504a75SDimitris Papastamos offset = 0; 4066a504a75SDimitris Papastamos 4076a504a75SDimitris Papastamos switch (wm8995->sysclk[aif]) { 4086a504a75SDimitris Papastamos case WM8995_SYSCLK_MCLK1: 4096a504a75SDimitris Papastamos rate = wm8995->mclk[0]; 4106a504a75SDimitris Papastamos break; 4116a504a75SDimitris Papastamos case WM8995_SYSCLK_MCLK2: 4126a504a75SDimitris Papastamos reg1 |= 0x8; 4136a504a75SDimitris Papastamos rate = wm8995->mclk[1]; 4146a504a75SDimitris Papastamos break; 4156a504a75SDimitris Papastamos case WM8995_SYSCLK_FLL1: 4166a504a75SDimitris Papastamos reg1 |= 0x10; 4176a504a75SDimitris Papastamos rate = wm8995->fll[0].out; 4186a504a75SDimitris Papastamos break; 4196a504a75SDimitris Papastamos case WM8995_SYSCLK_FLL2: 4206a504a75SDimitris Papastamos reg1 |= 0x18; 4216a504a75SDimitris Papastamos rate = wm8995->fll[1].out; 4226a504a75SDimitris Papastamos break; 4236a504a75SDimitris Papastamos default: 4246a504a75SDimitris Papastamos return -EINVAL; 4256a504a75SDimitris Papastamos } 4266a504a75SDimitris Papastamos 4276a504a75SDimitris Papastamos if (rate >= 13500000) { 4286a504a75SDimitris Papastamos rate /= 2; 4296a504a75SDimitris Papastamos reg1 |= WM8995_AIF1CLK_DIV; 4306a504a75SDimitris Papastamos 4316a504a75SDimitris Papastamos dev_dbg(codec->dev, "Dividing AIF%d clock to %dHz\n", 4326a504a75SDimitris Papastamos aif + 1, rate); 4336a504a75SDimitris Papastamos } 4346a504a75SDimitris Papastamos 4356a504a75SDimitris Papastamos wm8995->aifclk[aif] = rate; 4366a504a75SDimitris Papastamos 4376a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_AIF1_CLOCKING_1 + offset, 4386a504a75SDimitris Papastamos WM8995_AIF1CLK_SRC_MASK | WM8995_AIF1CLK_DIV_MASK, 4396a504a75SDimitris Papastamos reg1); 4406a504a75SDimitris Papastamos return 0; 4416a504a75SDimitris Papastamos } 4426a504a75SDimitris Papastamos 4436a504a75SDimitris Papastamos static int configure_clock(struct snd_soc_codec *codec) 4446a504a75SDimitris Papastamos { 4456a504a75SDimitris Papastamos struct wm8995_priv *wm8995; 4466a504a75SDimitris Papastamos int old, new; 4476a504a75SDimitris Papastamos 4486a504a75SDimitris Papastamos wm8995 = snd_soc_codec_get_drvdata(codec); 4496a504a75SDimitris Papastamos 4506a504a75SDimitris Papastamos /* Bring up the AIF clocks first */ 4516a504a75SDimitris Papastamos configure_aif_clock(codec, 0); 4526a504a75SDimitris Papastamos configure_aif_clock(codec, 1); 4536a504a75SDimitris Papastamos 4546a504a75SDimitris Papastamos /* 4556a504a75SDimitris Papastamos * Then switch CLK_SYS over to the higher of them; a change 4566a504a75SDimitris Papastamos * can only happen as a result of a clocking change which can 4576a504a75SDimitris Papastamos * only be made outside of DAPM so we can safely redo the 4586a504a75SDimitris Papastamos * clocking. 4596a504a75SDimitris Papastamos */ 4606a504a75SDimitris Papastamos 4616a504a75SDimitris Papastamos /* If they're equal it doesn't matter which is used */ 4626a504a75SDimitris Papastamos if (wm8995->aifclk[0] == wm8995->aifclk[1]) 4636a504a75SDimitris Papastamos return 0; 4646a504a75SDimitris Papastamos 4656a504a75SDimitris Papastamos if (wm8995->aifclk[0] < wm8995->aifclk[1]) 4666a504a75SDimitris Papastamos new = WM8995_SYSCLK_SRC; 4676a504a75SDimitris Papastamos else 4686a504a75SDimitris Papastamos new = 0; 4696a504a75SDimitris Papastamos 4706a504a75SDimitris Papastamos old = snd_soc_read(codec, WM8995_CLOCKING_1) & WM8995_SYSCLK_SRC; 4716a504a75SDimitris Papastamos 4726a504a75SDimitris Papastamos /* If there's no change then we're done. */ 4736a504a75SDimitris Papastamos if (old == new) 4746a504a75SDimitris Papastamos return 0; 4756a504a75SDimitris Papastamos 4766a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_CLOCKING_1, 4776a504a75SDimitris Papastamos WM8995_SYSCLK_SRC_MASK, new); 4786a504a75SDimitris Papastamos 4796a504a75SDimitris Papastamos snd_soc_dapm_sync(&codec->dapm); 4806a504a75SDimitris Papastamos 4816a504a75SDimitris Papastamos return 0; 4826a504a75SDimitris Papastamos } 4836a504a75SDimitris Papastamos 4846a504a75SDimitris Papastamos static int clk_sys_event(struct snd_soc_dapm_widget *w, 4856a504a75SDimitris Papastamos struct snd_kcontrol *kcontrol, int event) 4866a504a75SDimitris Papastamos { 4876a504a75SDimitris Papastamos struct snd_soc_codec *codec; 4886a504a75SDimitris Papastamos 4896a504a75SDimitris Papastamos codec = w->codec; 4906a504a75SDimitris Papastamos 4916a504a75SDimitris Papastamos switch (event) { 4926a504a75SDimitris Papastamos case SND_SOC_DAPM_PRE_PMU: 4936a504a75SDimitris Papastamos return configure_clock(codec); 4946a504a75SDimitris Papastamos 4956a504a75SDimitris Papastamos case SND_SOC_DAPM_POST_PMD: 4966a504a75SDimitris Papastamos configure_clock(codec); 4976a504a75SDimitris Papastamos break; 4986a504a75SDimitris Papastamos } 4996a504a75SDimitris Papastamos 5006a504a75SDimitris Papastamos return 0; 5016a504a75SDimitris Papastamos } 5026a504a75SDimitris Papastamos 5036a504a75SDimitris Papastamos static const char *sidetone_text[] = { 5046a504a75SDimitris Papastamos "ADC/DMIC1", "DMIC2", 5056a504a75SDimitris Papastamos }; 5066a504a75SDimitris Papastamos 5076a504a75SDimitris Papastamos static const struct soc_enum sidetone1_enum = 5086a504a75SDimitris Papastamos SOC_ENUM_SINGLE(WM8995_SIDETONE, 0, 2, sidetone_text); 5096a504a75SDimitris Papastamos 5106a504a75SDimitris Papastamos static const struct snd_kcontrol_new sidetone1_mux = 5116a504a75SDimitris Papastamos SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum); 5126a504a75SDimitris Papastamos 5136a504a75SDimitris Papastamos static const struct soc_enum sidetone2_enum = 5146a504a75SDimitris Papastamos SOC_ENUM_SINGLE(WM8995_SIDETONE, 1, 2, sidetone_text); 5156a504a75SDimitris Papastamos 5166a504a75SDimitris Papastamos static const struct snd_kcontrol_new sidetone2_mux = 5176a504a75SDimitris Papastamos SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum); 5186a504a75SDimitris Papastamos 5196a504a75SDimitris Papastamos static const struct snd_kcontrol_new aif1adc1l_mix[] = { 5206a504a75SDimitris Papastamos SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING, 5216a504a75SDimitris Papastamos 1, 1, 0), 5226a504a75SDimitris Papastamos SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING, 5236a504a75SDimitris Papastamos 0, 1, 0), 5246a504a75SDimitris Papastamos }; 5256a504a75SDimitris Papastamos 5266a504a75SDimitris Papastamos static const struct snd_kcontrol_new aif1adc1r_mix[] = { 5276a504a75SDimitris Papastamos SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING, 5286a504a75SDimitris Papastamos 1, 1, 0), 5296a504a75SDimitris Papastamos SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING, 5306a504a75SDimitris Papastamos 0, 1, 0), 5316a504a75SDimitris Papastamos }; 5326a504a75SDimitris Papastamos 5336a504a75SDimitris Papastamos static const struct snd_kcontrol_new aif1adc2l_mix[] = { 5346a504a75SDimitris Papastamos SOC_DAPM_SINGLE("DMIC Switch", WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING, 5356a504a75SDimitris Papastamos 1, 1, 0), 5366a504a75SDimitris Papastamos SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING, 5376a504a75SDimitris Papastamos 0, 1, 0), 5386a504a75SDimitris Papastamos }; 5396a504a75SDimitris Papastamos 5406a504a75SDimitris Papastamos static const struct snd_kcontrol_new aif1adc2r_mix[] = { 5416a504a75SDimitris Papastamos SOC_DAPM_SINGLE("DMIC Switch", WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING, 5426a504a75SDimitris Papastamos 1, 1, 0), 5436a504a75SDimitris Papastamos SOC_DAPM_SINGLE("AIF2 Switch", WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING, 5446a504a75SDimitris Papastamos 0, 1, 0), 5456a504a75SDimitris Papastamos }; 5466a504a75SDimitris Papastamos 5476a504a75SDimitris Papastamos static const struct snd_kcontrol_new dac1l_mix[] = { 5486a504a75SDimitris Papastamos WM8995_CLASS_W_SWITCH("Right Sidetone Switch", WM8995_DAC1_LEFT_MIXER_ROUTING, 5496a504a75SDimitris Papastamos 5, 1, 0), 5506a504a75SDimitris Papastamos WM8995_CLASS_W_SWITCH("Left Sidetone Switch", WM8995_DAC1_LEFT_MIXER_ROUTING, 5516a504a75SDimitris Papastamos 4, 1, 0), 5526a504a75SDimitris Papastamos WM8995_CLASS_W_SWITCH("AIF2 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING, 5536a504a75SDimitris Papastamos 2, 1, 0), 5546a504a75SDimitris Papastamos WM8995_CLASS_W_SWITCH("AIF1.2 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING, 5556a504a75SDimitris Papastamos 1, 1, 0), 5566a504a75SDimitris Papastamos WM8995_CLASS_W_SWITCH("AIF1.1 Switch", WM8995_DAC1_LEFT_MIXER_ROUTING, 5576a504a75SDimitris Papastamos 0, 1, 0), 5586a504a75SDimitris Papastamos }; 5596a504a75SDimitris Papastamos 5606a504a75SDimitris Papastamos static const struct snd_kcontrol_new dac1r_mix[] = { 5616a504a75SDimitris Papastamos WM8995_CLASS_W_SWITCH("Right Sidetone Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING, 5626a504a75SDimitris Papastamos 5, 1, 0), 5636a504a75SDimitris Papastamos WM8995_CLASS_W_SWITCH("Left Sidetone Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING, 5646a504a75SDimitris Papastamos 4, 1, 0), 5656a504a75SDimitris Papastamos WM8995_CLASS_W_SWITCH("AIF2 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING, 5666a504a75SDimitris Papastamos 2, 1, 0), 5676a504a75SDimitris Papastamos WM8995_CLASS_W_SWITCH("AIF1.2 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING, 5686a504a75SDimitris Papastamos 1, 1, 0), 5696a504a75SDimitris Papastamos WM8995_CLASS_W_SWITCH("AIF1.1 Switch", WM8995_DAC1_RIGHT_MIXER_ROUTING, 5706a504a75SDimitris Papastamos 0, 1, 0), 5716a504a75SDimitris Papastamos }; 5726a504a75SDimitris Papastamos 5736a504a75SDimitris Papastamos static const struct snd_kcontrol_new aif2dac2l_mix[] = { 5746a504a75SDimitris Papastamos SOC_DAPM_SINGLE("Right Sidetone Switch", WM8995_DAC2_LEFT_MIXER_ROUTING, 5756a504a75SDimitris Papastamos 5, 1, 0), 5766a504a75SDimitris Papastamos SOC_DAPM_SINGLE("Left Sidetone Switch", WM8995_DAC2_LEFT_MIXER_ROUTING, 5776a504a75SDimitris Papastamos 4, 1, 0), 5786a504a75SDimitris Papastamos SOC_DAPM_SINGLE("AIF2 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING, 5796a504a75SDimitris Papastamos 2, 1, 0), 5806a504a75SDimitris Papastamos SOC_DAPM_SINGLE("AIF1.2 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING, 5816a504a75SDimitris Papastamos 1, 1, 0), 5826a504a75SDimitris Papastamos SOC_DAPM_SINGLE("AIF1.1 Switch", WM8995_DAC2_LEFT_MIXER_ROUTING, 5836a504a75SDimitris Papastamos 0, 1, 0), 5846a504a75SDimitris Papastamos }; 5856a504a75SDimitris Papastamos 5866a504a75SDimitris Papastamos static const struct snd_kcontrol_new aif2dac2r_mix[] = { 5876a504a75SDimitris Papastamos SOC_DAPM_SINGLE("Right Sidetone Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING, 5886a504a75SDimitris Papastamos 5, 1, 0), 5896a504a75SDimitris Papastamos SOC_DAPM_SINGLE("Left Sidetone Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING, 5906a504a75SDimitris Papastamos 4, 1, 0), 5916a504a75SDimitris Papastamos SOC_DAPM_SINGLE("AIF2 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING, 5926a504a75SDimitris Papastamos 2, 1, 0), 5936a504a75SDimitris Papastamos SOC_DAPM_SINGLE("AIF1.2 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING, 5946a504a75SDimitris Papastamos 1, 1, 0), 5956a504a75SDimitris Papastamos SOC_DAPM_SINGLE("AIF1.1 Switch", WM8995_DAC2_RIGHT_MIXER_ROUTING, 5966a504a75SDimitris Papastamos 0, 1, 0), 5976a504a75SDimitris Papastamos }; 5986a504a75SDimitris Papastamos 5996a504a75SDimitris Papastamos static const struct snd_kcontrol_new in1l_pga = 6006a504a75SDimitris Papastamos SOC_DAPM_SINGLE("IN1L Switch", WM8995_POWER_MANAGEMENT_2, 5, 1, 0); 6016a504a75SDimitris Papastamos 6026a504a75SDimitris Papastamos static const struct snd_kcontrol_new in1r_pga = 6036a504a75SDimitris Papastamos SOC_DAPM_SINGLE("IN1R Switch", WM8995_POWER_MANAGEMENT_2, 4, 1, 0); 6046a504a75SDimitris Papastamos 6056a504a75SDimitris Papastamos static const char *adc_mux_text[] = { 6066a504a75SDimitris Papastamos "ADC", 6076a504a75SDimitris Papastamos "DMIC", 6086a504a75SDimitris Papastamos }; 6096a504a75SDimitris Papastamos 6106a504a75SDimitris Papastamos static const struct soc_enum adc_enum = 6116a504a75SDimitris Papastamos SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text); 6126a504a75SDimitris Papastamos 6136a504a75SDimitris Papastamos static const struct snd_kcontrol_new adcl_mux = 6146a504a75SDimitris Papastamos SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum); 6156a504a75SDimitris Papastamos 6166a504a75SDimitris Papastamos static const struct snd_kcontrol_new adcr_mux = 6176a504a75SDimitris Papastamos SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum); 6186a504a75SDimitris Papastamos 6196a504a75SDimitris Papastamos static const char *spk_src_text[] = { 6206a504a75SDimitris Papastamos "DAC1L", "DAC1R", "DAC2L", "DAC2R" 6216a504a75SDimitris Papastamos }; 6226a504a75SDimitris Papastamos 6236a504a75SDimitris Papastamos static const SOC_ENUM_SINGLE_DECL(spk1l_src_enum, WM8995_LEFT_PDM_SPEAKER_1, 6246a504a75SDimitris Papastamos 0, spk_src_text); 6256a504a75SDimitris Papastamos static const SOC_ENUM_SINGLE_DECL(spk1r_src_enum, WM8995_RIGHT_PDM_SPEAKER_1, 6266a504a75SDimitris Papastamos 0, spk_src_text); 6276a504a75SDimitris Papastamos static const SOC_ENUM_SINGLE_DECL(spk2l_src_enum, WM8995_LEFT_PDM_SPEAKER_2, 6286a504a75SDimitris Papastamos 0, spk_src_text); 6296a504a75SDimitris Papastamos static const SOC_ENUM_SINGLE_DECL(spk2r_src_enum, WM8995_RIGHT_PDM_SPEAKER_2, 6306a504a75SDimitris Papastamos 0, spk_src_text); 6316a504a75SDimitris Papastamos 6326a504a75SDimitris Papastamos static const struct snd_kcontrol_new spk1l_mux = 6336a504a75SDimitris Papastamos SOC_DAPM_ENUM("SPK1L SRC", spk1l_src_enum); 6346a504a75SDimitris Papastamos static const struct snd_kcontrol_new spk1r_mux = 6356a504a75SDimitris Papastamos SOC_DAPM_ENUM("SPK1R SRC", spk1r_src_enum); 6366a504a75SDimitris Papastamos static const struct snd_kcontrol_new spk2l_mux = 6376a504a75SDimitris Papastamos SOC_DAPM_ENUM("SPK2L SRC", spk2l_src_enum); 6386a504a75SDimitris Papastamos static const struct snd_kcontrol_new spk2r_mux = 6396a504a75SDimitris Papastamos SOC_DAPM_ENUM("SPK2R SRC", spk2r_src_enum); 6406a504a75SDimitris Papastamos 6416a504a75SDimitris Papastamos static const struct snd_soc_dapm_widget wm8995_dapm_widgets[] = { 6426a504a75SDimitris Papastamos SND_SOC_DAPM_INPUT("DMIC1DAT"), 6436a504a75SDimitris Papastamos SND_SOC_DAPM_INPUT("DMIC2DAT"), 6446a504a75SDimitris Papastamos 6456a504a75SDimitris Papastamos SND_SOC_DAPM_INPUT("IN1L"), 6466a504a75SDimitris Papastamos SND_SOC_DAPM_INPUT("IN1R"), 6476a504a75SDimitris Papastamos 6486a504a75SDimitris Papastamos SND_SOC_DAPM_MIXER("IN1L PGA", SND_SOC_NOPM, 0, 0, 6496a504a75SDimitris Papastamos &in1l_pga, 1), 6506a504a75SDimitris Papastamos SND_SOC_DAPM_MIXER("IN1R PGA", SND_SOC_NOPM, 0, 0, 6516a504a75SDimitris Papastamos &in1r_pga, 1), 6526a504a75SDimitris Papastamos 6536a504a75SDimitris Papastamos SND_SOC_DAPM_MICBIAS("MICBIAS1", WM8995_POWER_MANAGEMENT_1, 8, 0), 6546a504a75SDimitris Papastamos SND_SOC_DAPM_MICBIAS("MICBIAS2", WM8995_POWER_MANAGEMENT_1, 9, 0), 6556a504a75SDimitris Papastamos 6566a504a75SDimitris Papastamos SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8995_AIF1_CLOCKING_1, 0, 0, NULL, 0), 6576a504a75SDimitris Papastamos SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8995_AIF2_CLOCKING_1, 0, 0, NULL, 0), 6586a504a75SDimitris Papastamos SND_SOC_DAPM_SUPPLY("DSP1CLK", WM8995_CLOCKING_1, 3, 0, NULL, 0), 6596a504a75SDimitris Papastamos SND_SOC_DAPM_SUPPLY("DSP2CLK", WM8995_CLOCKING_1, 2, 0, NULL, 0), 6606a504a75SDimitris Papastamos SND_SOC_DAPM_SUPPLY("SYSDSPCLK", WM8995_CLOCKING_1, 1, 0, NULL, 0), 6616a504a75SDimitris Papastamos SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event, 6626a504a75SDimitris Papastamos SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), 6636a504a75SDimitris Papastamos 6646a504a75SDimitris Papastamos SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", "AIF1 Capture", 0, 6656a504a75SDimitris Papastamos WM8995_POWER_MANAGEMENT_3, 9, 0), 6666a504a75SDimitris Papastamos SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", "AIF1 Capture", 0, 6676a504a75SDimitris Papastamos WM8995_POWER_MANAGEMENT_3, 8, 0), 6686a504a75SDimitris Papastamos SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", "AIF1 Capture", 0, 6696a504a75SDimitris Papastamos SND_SOC_NOPM, 0, 0), 6706a504a75SDimitris Papastamos SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", "AIF1 Capture", 6716a504a75SDimitris Papastamos 0, WM8995_POWER_MANAGEMENT_3, 11, 0), 6726a504a75SDimitris Papastamos SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", "AIF1 Capture", 6736a504a75SDimitris Papastamos 0, WM8995_POWER_MANAGEMENT_3, 10, 0), 6746a504a75SDimitris Papastamos 6756a504a75SDimitris Papastamos SND_SOC_DAPM_VIRT_MUX("ADCL Mux", SND_SOC_NOPM, 1, 0, 6766a504a75SDimitris Papastamos &adcl_mux), 6776a504a75SDimitris Papastamos SND_SOC_DAPM_VIRT_MUX("ADCR Mux", SND_SOC_NOPM, 0, 0, 6786a504a75SDimitris Papastamos &adcr_mux), 6796a504a75SDimitris Papastamos 6806a504a75SDimitris Papastamos SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8995_POWER_MANAGEMENT_3, 5, 0), 6816a504a75SDimitris Papastamos SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8995_POWER_MANAGEMENT_3, 4, 0), 6826a504a75SDimitris Papastamos SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8995_POWER_MANAGEMENT_3, 3, 0), 6836a504a75SDimitris Papastamos SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8995_POWER_MANAGEMENT_3, 2, 0), 6846a504a75SDimitris Papastamos 6856a504a75SDimitris Papastamos SND_SOC_DAPM_ADC("ADCL", NULL, WM8995_POWER_MANAGEMENT_3, 1, 0), 6866a504a75SDimitris Papastamos SND_SOC_DAPM_ADC("ADCR", NULL, WM8995_POWER_MANAGEMENT_3, 0, 0), 6876a504a75SDimitris Papastamos 6886a504a75SDimitris Papastamos SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0, 6896a504a75SDimitris Papastamos aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)), 6906a504a75SDimitris Papastamos SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0, 6916a504a75SDimitris Papastamos aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)), 6926a504a75SDimitris Papastamos SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0, 6936a504a75SDimitris Papastamos aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)), 6946a504a75SDimitris Papastamos SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0, 6956a504a75SDimitris Papastamos aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)), 6966a504a75SDimitris Papastamos 6976a504a75SDimitris Papastamos SND_SOC_DAPM_AIF_IN("AIF1DAC1L", NULL, 0, WM8995_POWER_MANAGEMENT_4, 6986a504a75SDimitris Papastamos 9, 0), 6996a504a75SDimitris Papastamos SND_SOC_DAPM_AIF_IN("AIF1DAC1R", NULL, 0, WM8995_POWER_MANAGEMENT_4, 7006a504a75SDimitris Papastamos 8, 0), 7016a504a75SDimitris Papastamos SND_SOC_DAPM_AIF_IN("AIF1DACDAT", "AIF1 Playback", 0, SND_SOC_NOPM, 7026a504a75SDimitris Papastamos 0, 0), 7036a504a75SDimitris Papastamos 7046a504a75SDimitris Papastamos SND_SOC_DAPM_AIF_IN("AIF1DAC2L", NULL, 0, WM8995_POWER_MANAGEMENT_4, 7056a504a75SDimitris Papastamos 11, 0), 7066a504a75SDimitris Papastamos SND_SOC_DAPM_AIF_IN("AIF1DAC2R", NULL, 0, WM8995_POWER_MANAGEMENT_4, 7076a504a75SDimitris Papastamos 10, 0), 7086a504a75SDimitris Papastamos 7096a504a75SDimitris Papastamos SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0, 7106a504a75SDimitris Papastamos aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)), 7116a504a75SDimitris Papastamos SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0, 7126a504a75SDimitris Papastamos aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)), 7136a504a75SDimitris Papastamos 7146a504a75SDimitris Papastamos SND_SOC_DAPM_DAC("DAC2L", NULL, WM8995_POWER_MANAGEMENT_4, 3, 0), 7156a504a75SDimitris Papastamos SND_SOC_DAPM_DAC("DAC2R", NULL, WM8995_POWER_MANAGEMENT_4, 2, 0), 7166a504a75SDimitris Papastamos SND_SOC_DAPM_DAC("DAC1L", NULL, WM8995_POWER_MANAGEMENT_4, 1, 0), 7176a504a75SDimitris Papastamos SND_SOC_DAPM_DAC("DAC1R", NULL, WM8995_POWER_MANAGEMENT_4, 0, 0), 7186a504a75SDimitris Papastamos 7196a504a75SDimitris Papastamos SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0, dac1l_mix, 7206a504a75SDimitris Papastamos ARRAY_SIZE(dac1l_mix)), 7216a504a75SDimitris Papastamos SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0, dac1r_mix, 7226a504a75SDimitris Papastamos ARRAY_SIZE(dac1r_mix)), 7236a504a75SDimitris Papastamos 7246a504a75SDimitris Papastamos SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux), 7256a504a75SDimitris Papastamos SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux), 7266a504a75SDimitris Papastamos 7276a504a75SDimitris Papastamos SND_SOC_DAPM_PGA_E("Headphone PGA", SND_SOC_NOPM, 0, 0, NULL, 0, 7286a504a75SDimitris Papastamos hp_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), 7296a504a75SDimitris Papastamos 7306a504a75SDimitris Papastamos SND_SOC_DAPM_SUPPLY("Headphone Supply", SND_SOC_NOPM, 0, 0, 7316a504a75SDimitris Papastamos hp_supply_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), 7326a504a75SDimitris Papastamos 7336a504a75SDimitris Papastamos SND_SOC_DAPM_MUX("SPK1L Driver", WM8995_LEFT_PDM_SPEAKER_1, 7346a504a75SDimitris Papastamos 4, 0, &spk1l_mux), 7356a504a75SDimitris Papastamos SND_SOC_DAPM_MUX("SPK1R Driver", WM8995_RIGHT_PDM_SPEAKER_1, 7366a504a75SDimitris Papastamos 4, 0, &spk1r_mux), 7376a504a75SDimitris Papastamos SND_SOC_DAPM_MUX("SPK2L Driver", WM8995_LEFT_PDM_SPEAKER_2, 7386a504a75SDimitris Papastamos 4, 0, &spk2l_mux), 7396a504a75SDimitris Papastamos SND_SOC_DAPM_MUX("SPK2R Driver", WM8995_RIGHT_PDM_SPEAKER_2, 7406a504a75SDimitris Papastamos 4, 0, &spk2r_mux), 7416a504a75SDimitris Papastamos 7426a504a75SDimitris Papastamos SND_SOC_DAPM_SUPPLY("LDO2", WM8995_POWER_MANAGEMENT_2, 1, 0, NULL, 0), 7436a504a75SDimitris Papastamos 7446a504a75SDimitris Papastamos SND_SOC_DAPM_OUTPUT("HP1L"), 7456a504a75SDimitris Papastamos SND_SOC_DAPM_OUTPUT("HP1R"), 7466a504a75SDimitris Papastamos SND_SOC_DAPM_OUTPUT("SPK1L"), 7476a504a75SDimitris Papastamos SND_SOC_DAPM_OUTPUT("SPK1R"), 7486a504a75SDimitris Papastamos SND_SOC_DAPM_OUTPUT("SPK2L"), 7496a504a75SDimitris Papastamos SND_SOC_DAPM_OUTPUT("SPK2R") 7506a504a75SDimitris Papastamos }; 7516a504a75SDimitris Papastamos 7526a504a75SDimitris Papastamos static const struct snd_soc_dapm_route wm8995_intercon[] = { 7536a504a75SDimitris Papastamos { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys }, 7546a504a75SDimitris Papastamos { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys }, 7556a504a75SDimitris Papastamos 7566a504a75SDimitris Papastamos { "DSP1CLK", NULL, "CLK_SYS" }, 7576a504a75SDimitris Papastamos { "DSP2CLK", NULL, "CLK_SYS" }, 7586a504a75SDimitris Papastamos { "SYSDSPCLK", NULL, "CLK_SYS" }, 7596a504a75SDimitris Papastamos 7606a504a75SDimitris Papastamos { "AIF1ADC1L", NULL, "AIF1CLK" }, 7616a504a75SDimitris Papastamos { "AIF1ADC1L", NULL, "DSP1CLK" }, 7626a504a75SDimitris Papastamos { "AIF1ADC1R", NULL, "AIF1CLK" }, 7636a504a75SDimitris Papastamos { "AIF1ADC1R", NULL, "DSP1CLK" }, 7646a504a75SDimitris Papastamos { "AIF1ADC1R", NULL, "SYSDSPCLK" }, 7656a504a75SDimitris Papastamos 7666a504a75SDimitris Papastamos { "AIF1ADC2L", NULL, "AIF1CLK" }, 7676a504a75SDimitris Papastamos { "AIF1ADC2L", NULL, "DSP1CLK" }, 7686a504a75SDimitris Papastamos { "AIF1ADC2R", NULL, "AIF1CLK" }, 7696a504a75SDimitris Papastamos { "AIF1ADC2R", NULL, "DSP1CLK" }, 7706a504a75SDimitris Papastamos { "AIF1ADC2R", NULL, "SYSDSPCLK" }, 7716a504a75SDimitris Papastamos 7726a504a75SDimitris Papastamos { "DMIC1L", NULL, "DMIC1DAT" }, 7736a504a75SDimitris Papastamos { "DMIC1L", NULL, "CLK_SYS" }, 7746a504a75SDimitris Papastamos { "DMIC1R", NULL, "DMIC1DAT" }, 7756a504a75SDimitris Papastamos { "DMIC1R", NULL, "CLK_SYS" }, 7766a504a75SDimitris Papastamos { "DMIC2L", NULL, "DMIC2DAT" }, 7776a504a75SDimitris Papastamos { "DMIC2L", NULL, "CLK_SYS" }, 7786a504a75SDimitris Papastamos { "DMIC2R", NULL, "DMIC2DAT" }, 7796a504a75SDimitris Papastamos { "DMIC2R", NULL, "CLK_SYS" }, 7806a504a75SDimitris Papastamos 7816a504a75SDimitris Papastamos { "ADCL", NULL, "AIF1CLK" }, 7826a504a75SDimitris Papastamos { "ADCL", NULL, "DSP1CLK" }, 7836a504a75SDimitris Papastamos { "ADCL", NULL, "SYSDSPCLK" }, 7846a504a75SDimitris Papastamos 7856a504a75SDimitris Papastamos { "ADCR", NULL, "AIF1CLK" }, 7866a504a75SDimitris Papastamos { "ADCR", NULL, "DSP1CLK" }, 7876a504a75SDimitris Papastamos { "ADCR", NULL, "SYSDSPCLK" }, 7886a504a75SDimitris Papastamos 7896a504a75SDimitris Papastamos { "IN1L PGA", "IN1L Switch", "IN1L" }, 7906a504a75SDimitris Papastamos { "IN1R PGA", "IN1R Switch", "IN1R" }, 7916a504a75SDimitris Papastamos { "IN1L PGA", NULL, "LDO2" }, 7926a504a75SDimitris Papastamos { "IN1R PGA", NULL, "LDO2" }, 7936a504a75SDimitris Papastamos 7946a504a75SDimitris Papastamos { "ADCL", NULL, "IN1L PGA" }, 7956a504a75SDimitris Papastamos { "ADCR", NULL, "IN1R PGA" }, 7966a504a75SDimitris Papastamos 7976a504a75SDimitris Papastamos { "ADCL Mux", "ADC", "ADCL" }, 7986a504a75SDimitris Papastamos { "ADCL Mux", "DMIC", "DMIC1L" }, 7996a504a75SDimitris Papastamos { "ADCR Mux", "ADC", "ADCR" }, 8006a504a75SDimitris Papastamos { "ADCR Mux", "DMIC", "DMIC1R" }, 8016a504a75SDimitris Papastamos 8026a504a75SDimitris Papastamos /* AIF1 outputs */ 8036a504a75SDimitris Papastamos { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" }, 8046a504a75SDimitris Papastamos { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" }, 8056a504a75SDimitris Papastamos 8066a504a75SDimitris Papastamos { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" }, 8076a504a75SDimitris Papastamos { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" }, 8086a504a75SDimitris Papastamos 8096a504a75SDimitris Papastamos { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" }, 8106a504a75SDimitris Papastamos { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" }, 8116a504a75SDimitris Papastamos 8126a504a75SDimitris Papastamos { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" }, 8136a504a75SDimitris Papastamos { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" }, 8146a504a75SDimitris Papastamos 8156a504a75SDimitris Papastamos /* Sidetone */ 8166a504a75SDimitris Papastamos { "Left Sidetone", "ADC/DMIC1", "AIF1ADC1L" }, 8176a504a75SDimitris Papastamos { "Left Sidetone", "DMIC2", "AIF1ADC2L" }, 8186a504a75SDimitris Papastamos { "Right Sidetone", "ADC/DMIC1", "AIF1ADC1R" }, 8196a504a75SDimitris Papastamos { "Right Sidetone", "DMIC2", "AIF1ADC2R" }, 8206a504a75SDimitris Papastamos 8216a504a75SDimitris Papastamos { "AIF1DAC1L", NULL, "AIF1CLK" }, 8226a504a75SDimitris Papastamos { "AIF1DAC1L", NULL, "DSP1CLK" }, 8236a504a75SDimitris Papastamos { "AIF1DAC1R", NULL, "AIF1CLK" }, 8246a504a75SDimitris Papastamos { "AIF1DAC1R", NULL, "DSP1CLK" }, 8256a504a75SDimitris Papastamos { "AIF1DAC1R", NULL, "SYSDSPCLK" }, 8266a504a75SDimitris Papastamos 8276a504a75SDimitris Papastamos { "AIF1DAC2L", NULL, "AIF1CLK" }, 8286a504a75SDimitris Papastamos { "AIF1DAC2L", NULL, "DSP1CLK" }, 8296a504a75SDimitris Papastamos { "AIF1DAC2R", NULL, "AIF1CLK" }, 8306a504a75SDimitris Papastamos { "AIF1DAC2R", NULL, "DSP1CLK" }, 8316a504a75SDimitris Papastamos { "AIF1DAC2R", NULL, "SYSDSPCLK" }, 8326a504a75SDimitris Papastamos 8336a504a75SDimitris Papastamos { "DAC1L", NULL, "AIF1CLK" }, 8346a504a75SDimitris Papastamos { "DAC1L", NULL, "DSP1CLK" }, 8356a504a75SDimitris Papastamos { "DAC1L", NULL, "SYSDSPCLK" }, 8366a504a75SDimitris Papastamos 8376a504a75SDimitris Papastamos { "DAC1R", NULL, "AIF1CLK" }, 8386a504a75SDimitris Papastamos { "DAC1R", NULL, "DSP1CLK" }, 8396a504a75SDimitris Papastamos { "DAC1R", NULL, "SYSDSPCLK" }, 8406a504a75SDimitris Papastamos 8416a504a75SDimitris Papastamos { "AIF1DAC1L", NULL, "AIF1DACDAT" }, 8426a504a75SDimitris Papastamos { "AIF1DAC1R", NULL, "AIF1DACDAT" }, 8436a504a75SDimitris Papastamos { "AIF1DAC2L", NULL, "AIF1DACDAT" }, 8446a504a75SDimitris Papastamos { "AIF1DAC2R", NULL, "AIF1DACDAT" }, 8456a504a75SDimitris Papastamos 8466a504a75SDimitris Papastamos /* DAC1 inputs */ 8476a504a75SDimitris Papastamos { "DAC1L", NULL, "DAC1L Mixer" }, 8486a504a75SDimitris Papastamos { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" }, 8496a504a75SDimitris Papastamos { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" }, 8506a504a75SDimitris Papastamos { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" }, 8516a504a75SDimitris Papastamos { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" }, 8526a504a75SDimitris Papastamos 8536a504a75SDimitris Papastamos { "DAC1R", NULL, "DAC1R Mixer" }, 8546a504a75SDimitris Papastamos { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" }, 8556a504a75SDimitris Papastamos { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" }, 8566a504a75SDimitris Papastamos { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" }, 8576a504a75SDimitris Papastamos { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" }, 8586a504a75SDimitris Papastamos 8596a504a75SDimitris Papastamos /* DAC2/AIF2 outputs */ 8606a504a75SDimitris Papastamos { "DAC2L", NULL, "AIF2DAC2L Mixer" }, 8616a504a75SDimitris Papastamos { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" }, 8626a504a75SDimitris Papastamos { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" }, 8636a504a75SDimitris Papastamos 8646a504a75SDimitris Papastamos { "DAC2R", NULL, "AIF2DAC2R Mixer" }, 8656a504a75SDimitris Papastamos { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" }, 8666a504a75SDimitris Papastamos { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" }, 8676a504a75SDimitris Papastamos 8686a504a75SDimitris Papastamos /* Output stages */ 8696a504a75SDimitris Papastamos { "Headphone PGA", NULL, "DAC1L" }, 8706a504a75SDimitris Papastamos { "Headphone PGA", NULL, "DAC1R" }, 8716a504a75SDimitris Papastamos 8726a504a75SDimitris Papastamos { "Headphone PGA", NULL, "DAC2L" }, 8736a504a75SDimitris Papastamos { "Headphone PGA", NULL, "DAC2R" }, 8746a504a75SDimitris Papastamos 8756a504a75SDimitris Papastamos { "Headphone PGA", NULL, "Headphone Supply" }, 8766a504a75SDimitris Papastamos { "Headphone PGA", NULL, "CLK_SYS" }, 8776a504a75SDimitris Papastamos { "Headphone PGA", NULL, "LDO2" }, 8786a504a75SDimitris Papastamos 8796a504a75SDimitris Papastamos { "HP1L", NULL, "Headphone PGA" }, 8806a504a75SDimitris Papastamos { "HP1R", NULL, "Headphone PGA" }, 8816a504a75SDimitris Papastamos 8826a504a75SDimitris Papastamos { "SPK1L Driver", "DAC1L", "DAC1L" }, 8836a504a75SDimitris Papastamos { "SPK1L Driver", "DAC1R", "DAC1R" }, 8846a504a75SDimitris Papastamos { "SPK1L Driver", "DAC2L", "DAC2L" }, 8856a504a75SDimitris Papastamos { "SPK1L Driver", "DAC2R", "DAC2R" }, 8866a504a75SDimitris Papastamos { "SPK1L Driver", NULL, "CLK_SYS" }, 8876a504a75SDimitris Papastamos 8886a504a75SDimitris Papastamos { "SPK1R Driver", "DAC1L", "DAC1L" }, 8896a504a75SDimitris Papastamos { "SPK1R Driver", "DAC1R", "DAC1R" }, 8906a504a75SDimitris Papastamos { "SPK1R Driver", "DAC2L", "DAC2L" }, 8916a504a75SDimitris Papastamos { "SPK1R Driver", "DAC2R", "DAC2R" }, 8926a504a75SDimitris Papastamos { "SPK1R Driver", NULL, "CLK_SYS" }, 8936a504a75SDimitris Papastamos 8946a504a75SDimitris Papastamos { "SPK2L Driver", "DAC1L", "DAC1L" }, 8956a504a75SDimitris Papastamos { "SPK2L Driver", "DAC1R", "DAC1R" }, 8966a504a75SDimitris Papastamos { "SPK2L Driver", "DAC2L", "DAC2L" }, 8976a504a75SDimitris Papastamos { "SPK2L Driver", "DAC2R", "DAC2R" }, 8986a504a75SDimitris Papastamos { "SPK2L Driver", NULL, "CLK_SYS" }, 8996a504a75SDimitris Papastamos 9006a504a75SDimitris Papastamos { "SPK2R Driver", "DAC1L", "DAC1L" }, 9016a504a75SDimitris Papastamos { "SPK2R Driver", "DAC1R", "DAC1R" }, 9026a504a75SDimitris Papastamos { "SPK2R Driver", "DAC2L", "DAC2L" }, 9036a504a75SDimitris Papastamos { "SPK2R Driver", "DAC2R", "DAC2R" }, 9046a504a75SDimitris Papastamos { "SPK2R Driver", NULL, "CLK_SYS" }, 9056a504a75SDimitris Papastamos 9066a504a75SDimitris Papastamos { "SPK1L", NULL, "SPK1L Driver" }, 9076a504a75SDimitris Papastamos { "SPK1R", NULL, "SPK1R Driver" }, 9086a504a75SDimitris Papastamos { "SPK2L", NULL, "SPK2L Driver" }, 9096a504a75SDimitris Papastamos { "SPK2R", NULL, "SPK2R Driver" } 9106a504a75SDimitris Papastamos }; 9116a504a75SDimitris Papastamos 9126a504a75SDimitris Papastamos static int wm8995_volatile(unsigned int reg) 9136a504a75SDimitris Papastamos { 9146a504a75SDimitris Papastamos /* out of bounds registers are generally considered 9156a504a75SDimitris Papastamos * volatile to support register banks that are partially 9166a504a75SDimitris Papastamos * owned by something else for e.g. a DSP 9176a504a75SDimitris Papastamos */ 9186a504a75SDimitris Papastamos if (reg > WM8995_MAX_CACHED_REGISTER) 9196a504a75SDimitris Papastamos return 1; 9206a504a75SDimitris Papastamos 9216a504a75SDimitris Papastamos switch (reg) { 9226a504a75SDimitris Papastamos case WM8995_SOFTWARE_RESET: 9236a504a75SDimitris Papastamos case WM8995_DC_SERVO_READBACK_0: 9246a504a75SDimitris Papastamos case WM8995_INTERRUPT_STATUS_1: 9256a504a75SDimitris Papastamos case WM8995_INTERRUPT_STATUS_2: 9266a504a75SDimitris Papastamos case WM8995_INTERRUPT_STATUS_1_MASK: 9276a504a75SDimitris Papastamos case WM8995_INTERRUPT_STATUS_2_MASK: 9286a504a75SDimitris Papastamos case WM8995_INTERRUPT_CONTROL: 9296a504a75SDimitris Papastamos case WM8995_ACCESSORY_DETECT_MODE1: 9306a504a75SDimitris Papastamos case WM8995_ACCESSORY_DETECT_MODE2: 9316a504a75SDimitris Papastamos case WM8995_HEADPHONE_DETECT1: 9326a504a75SDimitris Papastamos case WM8995_HEADPHONE_DETECT2: 9336a504a75SDimitris Papastamos return 1; 9346a504a75SDimitris Papastamos } 9356a504a75SDimitris Papastamos 9366a504a75SDimitris Papastamos return 0; 9376a504a75SDimitris Papastamos } 9386a504a75SDimitris Papastamos 9396a504a75SDimitris Papastamos static int wm8995_aif_mute(struct snd_soc_dai *dai, int mute) 9406a504a75SDimitris Papastamos { 9416a504a75SDimitris Papastamos struct snd_soc_codec *codec = dai->codec; 9426a504a75SDimitris Papastamos int mute_reg; 9436a504a75SDimitris Papastamos 9446a504a75SDimitris Papastamos switch (dai->id) { 9456a504a75SDimitris Papastamos case 0: 9466a504a75SDimitris Papastamos mute_reg = WM8995_AIF1_DAC1_FILTERS_1; 9476a504a75SDimitris Papastamos break; 9486a504a75SDimitris Papastamos case 1: 9496a504a75SDimitris Papastamos mute_reg = WM8995_AIF2_DAC_FILTERS_1; 9506a504a75SDimitris Papastamos break; 9516a504a75SDimitris Papastamos default: 9526a504a75SDimitris Papastamos return -EINVAL; 9536a504a75SDimitris Papastamos } 9546a504a75SDimitris Papastamos 9556a504a75SDimitris Papastamos snd_soc_update_bits(codec, mute_reg, WM8995_AIF1DAC1_MUTE_MASK, 9566a504a75SDimitris Papastamos !!mute << WM8995_AIF1DAC1_MUTE_SHIFT); 9576a504a75SDimitris Papastamos return 0; 9586a504a75SDimitris Papastamos } 9596a504a75SDimitris Papastamos 9606a504a75SDimitris Papastamos static int wm8995_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) 9616a504a75SDimitris Papastamos { 9626a504a75SDimitris Papastamos struct snd_soc_codec *codec; 9636a504a75SDimitris Papastamos int master; 9646a504a75SDimitris Papastamos int aif; 9656a504a75SDimitris Papastamos 9666a504a75SDimitris Papastamos codec = dai->codec; 9676a504a75SDimitris Papastamos 9686a504a75SDimitris Papastamos master = 0; 9696a504a75SDimitris Papastamos switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 9706a504a75SDimitris Papastamos case SND_SOC_DAIFMT_CBS_CFS: 9716a504a75SDimitris Papastamos break; 9726a504a75SDimitris Papastamos case SND_SOC_DAIFMT_CBM_CFM: 9736a504a75SDimitris Papastamos master = WM8995_AIF1_MSTR; 9746a504a75SDimitris Papastamos break; 9756a504a75SDimitris Papastamos default: 9766a504a75SDimitris Papastamos dev_err(dai->dev, "Unknown master/slave configuration\n"); 9776a504a75SDimitris Papastamos return -EINVAL; 9786a504a75SDimitris Papastamos } 9796a504a75SDimitris Papastamos 9806a504a75SDimitris Papastamos aif = 0; 9816a504a75SDimitris Papastamos switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 9826a504a75SDimitris Papastamos case SND_SOC_DAIFMT_DSP_B: 9836a504a75SDimitris Papastamos aif |= WM8995_AIF1_LRCLK_INV; 9846a504a75SDimitris Papastamos case SND_SOC_DAIFMT_DSP_A: 9856a504a75SDimitris Papastamos aif |= (0x3 << WM8995_AIF1_FMT_SHIFT); 9866a504a75SDimitris Papastamos break; 9876a504a75SDimitris Papastamos case SND_SOC_DAIFMT_I2S: 9886a504a75SDimitris Papastamos aif |= (0x2 << WM8995_AIF1_FMT_SHIFT); 9896a504a75SDimitris Papastamos break; 9906a504a75SDimitris Papastamos case SND_SOC_DAIFMT_RIGHT_J: 9916a504a75SDimitris Papastamos break; 9926a504a75SDimitris Papastamos case SND_SOC_DAIFMT_LEFT_J: 9936a504a75SDimitris Papastamos aif |= (0x1 << WM8995_AIF1_FMT_SHIFT); 9946a504a75SDimitris Papastamos break; 9956a504a75SDimitris Papastamos default: 9966a504a75SDimitris Papastamos dev_err(dai->dev, "Unknown dai format\n"); 9976a504a75SDimitris Papastamos return -EINVAL; 9986a504a75SDimitris Papastamos } 9996a504a75SDimitris Papastamos 10006a504a75SDimitris Papastamos switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 10016a504a75SDimitris Papastamos case SND_SOC_DAIFMT_DSP_A: 10026a504a75SDimitris Papastamos case SND_SOC_DAIFMT_DSP_B: 10036a504a75SDimitris Papastamos /* frame inversion not valid for DSP modes */ 10046a504a75SDimitris Papastamos switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 10056a504a75SDimitris Papastamos case SND_SOC_DAIFMT_NB_NF: 10066a504a75SDimitris Papastamos break; 10076a504a75SDimitris Papastamos case SND_SOC_DAIFMT_IB_NF: 10086a504a75SDimitris Papastamos aif |= WM8995_AIF1_BCLK_INV; 10096a504a75SDimitris Papastamos break; 10106a504a75SDimitris Papastamos default: 10116a504a75SDimitris Papastamos return -EINVAL; 10126a504a75SDimitris Papastamos } 10136a504a75SDimitris Papastamos break; 10146a504a75SDimitris Papastamos 10156a504a75SDimitris Papastamos case SND_SOC_DAIFMT_I2S: 10166a504a75SDimitris Papastamos case SND_SOC_DAIFMT_RIGHT_J: 10176a504a75SDimitris Papastamos case SND_SOC_DAIFMT_LEFT_J: 10186a504a75SDimitris Papastamos switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 10196a504a75SDimitris Papastamos case SND_SOC_DAIFMT_NB_NF: 10206a504a75SDimitris Papastamos break; 10216a504a75SDimitris Papastamos case SND_SOC_DAIFMT_IB_IF: 10226a504a75SDimitris Papastamos aif |= WM8995_AIF1_BCLK_INV | WM8995_AIF1_LRCLK_INV; 10236a504a75SDimitris Papastamos break; 10246a504a75SDimitris Papastamos case SND_SOC_DAIFMT_IB_NF: 10256a504a75SDimitris Papastamos aif |= WM8995_AIF1_BCLK_INV; 10266a504a75SDimitris Papastamos break; 10276a504a75SDimitris Papastamos case SND_SOC_DAIFMT_NB_IF: 10286a504a75SDimitris Papastamos aif |= WM8995_AIF1_LRCLK_INV; 10296a504a75SDimitris Papastamos break; 10306a504a75SDimitris Papastamos default: 10316a504a75SDimitris Papastamos return -EINVAL; 10326a504a75SDimitris Papastamos } 10336a504a75SDimitris Papastamos break; 10346a504a75SDimitris Papastamos default: 10356a504a75SDimitris Papastamos return -EINVAL; 10366a504a75SDimitris Papastamos } 10376a504a75SDimitris Papastamos 10386a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_AIF1_CONTROL_1, 10396a504a75SDimitris Papastamos WM8995_AIF1_BCLK_INV_MASK | 10406a504a75SDimitris Papastamos WM8995_AIF1_LRCLK_INV_MASK | 10416a504a75SDimitris Papastamos WM8995_AIF1_FMT_MASK, aif); 10426a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_AIF1_MASTER_SLAVE, 10436a504a75SDimitris Papastamos WM8995_AIF1_MSTR_MASK, master); 10446a504a75SDimitris Papastamos return 0; 10456a504a75SDimitris Papastamos } 10466a504a75SDimitris Papastamos 10476a504a75SDimitris Papastamos static const int srs[] = { 10486a504a75SDimitris Papastamos 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 10496a504a75SDimitris Papastamos 48000, 88200, 96000 10506a504a75SDimitris Papastamos }; 10516a504a75SDimitris Papastamos 10526a504a75SDimitris Papastamos static const int fs_ratios[] = { 10536a504a75SDimitris Papastamos -1 /* reserved */, 10546a504a75SDimitris Papastamos 128, 192, 256, 384, 512, 768, 1024, 1408, 1536 10556a504a75SDimitris Papastamos }; 10566a504a75SDimitris Papastamos 10576a504a75SDimitris Papastamos static const int bclk_divs[] = { 10586a504a75SDimitris Papastamos 10, 15, 20, 30, 40, 55, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480 10596a504a75SDimitris Papastamos }; 10606a504a75SDimitris Papastamos 10616a504a75SDimitris Papastamos static int wm8995_hw_params(struct snd_pcm_substream *substream, 10626a504a75SDimitris Papastamos struct snd_pcm_hw_params *params, 10636a504a75SDimitris Papastamos struct snd_soc_dai *dai) 10646a504a75SDimitris Papastamos { 10656a504a75SDimitris Papastamos struct snd_soc_codec *codec; 10666a504a75SDimitris Papastamos struct wm8995_priv *wm8995; 10676a504a75SDimitris Papastamos int aif1_reg; 10686a504a75SDimitris Papastamos int bclk_reg; 10696a504a75SDimitris Papastamos int lrclk_reg; 10706a504a75SDimitris Papastamos int rate_reg; 10716a504a75SDimitris Papastamos int bclk_rate; 10726a504a75SDimitris Papastamos int aif1; 10736a504a75SDimitris Papastamos int lrclk, bclk; 10746a504a75SDimitris Papastamos int i, rate_val, best, best_val, cur_val; 10756a504a75SDimitris Papastamos 10766a504a75SDimitris Papastamos codec = dai->codec; 10776a504a75SDimitris Papastamos wm8995 = snd_soc_codec_get_drvdata(codec); 10786a504a75SDimitris Papastamos 10796a504a75SDimitris Papastamos switch (dai->id) { 10806a504a75SDimitris Papastamos case 0: 10816a504a75SDimitris Papastamos aif1_reg = WM8995_AIF1_CONTROL_1; 10826a504a75SDimitris Papastamos bclk_reg = WM8995_AIF1_BCLK; 10836a504a75SDimitris Papastamos rate_reg = WM8995_AIF1_RATE; 10846a504a75SDimitris Papastamos if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK /* || 10856a504a75SDimitris Papastamos wm8995->lrclk_shared[0] */) { 10866a504a75SDimitris Papastamos lrclk_reg = WM8995_AIF1DAC_LRCLK; 10876a504a75SDimitris Papastamos } else { 10886a504a75SDimitris Papastamos lrclk_reg = WM8995_AIF1ADC_LRCLK; 10896a504a75SDimitris Papastamos dev_dbg(codec->dev, "AIF1 using split LRCLK\n"); 10906a504a75SDimitris Papastamos } 10916a504a75SDimitris Papastamos break; 10926a504a75SDimitris Papastamos case 1: 10936a504a75SDimitris Papastamos aif1_reg = WM8995_AIF2_CONTROL_1; 10946a504a75SDimitris Papastamos bclk_reg = WM8995_AIF2_BCLK; 10956a504a75SDimitris Papastamos rate_reg = WM8995_AIF2_RATE; 10966a504a75SDimitris Papastamos if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK /* || 10976a504a75SDimitris Papastamos wm8995->lrclk_shared[1] */) { 10986a504a75SDimitris Papastamos lrclk_reg = WM8995_AIF2DAC_LRCLK; 10996a504a75SDimitris Papastamos } else { 11006a504a75SDimitris Papastamos lrclk_reg = WM8995_AIF2ADC_LRCLK; 11016a504a75SDimitris Papastamos dev_dbg(codec->dev, "AIF2 using split LRCLK\n"); 11026a504a75SDimitris Papastamos } 11036a504a75SDimitris Papastamos break; 11046a504a75SDimitris Papastamos default: 11056a504a75SDimitris Papastamos return -EINVAL; 11066a504a75SDimitris Papastamos } 11076a504a75SDimitris Papastamos 11086a504a75SDimitris Papastamos bclk_rate = snd_soc_params_to_bclk(params); 11096a504a75SDimitris Papastamos if (bclk_rate < 0) 11106a504a75SDimitris Papastamos return bclk_rate; 11116a504a75SDimitris Papastamos 11126a504a75SDimitris Papastamos aif1 = 0; 11136a504a75SDimitris Papastamos switch (params_format(params)) { 11146a504a75SDimitris Papastamos case SNDRV_PCM_FORMAT_S16_LE: 11156a504a75SDimitris Papastamos break; 11166a504a75SDimitris Papastamos case SNDRV_PCM_FORMAT_S20_3LE: 11176a504a75SDimitris Papastamos aif1 |= (0x1 << WM8995_AIF1_WL_SHIFT); 11186a504a75SDimitris Papastamos break; 11196a504a75SDimitris Papastamos case SNDRV_PCM_FORMAT_S24_LE: 11206a504a75SDimitris Papastamos aif1 |= (0x2 << WM8995_AIF1_WL_SHIFT); 11216a504a75SDimitris Papastamos break; 11226a504a75SDimitris Papastamos case SNDRV_PCM_FORMAT_S32_LE: 11236a504a75SDimitris Papastamos aif1 |= (0x3 << WM8995_AIF1_WL_SHIFT); 11246a504a75SDimitris Papastamos break; 11256a504a75SDimitris Papastamos default: 11266a504a75SDimitris Papastamos dev_err(dai->dev, "Unsupported word length %u\n", 11276a504a75SDimitris Papastamos params_format(params)); 11286a504a75SDimitris Papastamos return -EINVAL; 11296a504a75SDimitris Papastamos } 11306a504a75SDimitris Papastamos 11316a504a75SDimitris Papastamos /* try to find a suitable sample rate */ 11326a504a75SDimitris Papastamos for (i = 0; i < ARRAY_SIZE(srs); ++i) 11336a504a75SDimitris Papastamos if (srs[i] == params_rate(params)) 11346a504a75SDimitris Papastamos break; 11356a504a75SDimitris Papastamos if (i == ARRAY_SIZE(srs)) { 11366a504a75SDimitris Papastamos dev_err(dai->dev, "Sample rate %d is not supported\n", 11376a504a75SDimitris Papastamos params_rate(params)); 11386a504a75SDimitris Papastamos return -EINVAL; 11396a504a75SDimitris Papastamos } 11406a504a75SDimitris Papastamos rate_val = i << WM8995_AIF1_SR_SHIFT; 11416a504a75SDimitris Papastamos 11426a504a75SDimitris Papastamos dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i]); 11436a504a75SDimitris Papastamos dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n", 11446a504a75SDimitris Papastamos dai->id + 1, wm8995->aifclk[dai->id], bclk_rate); 11456a504a75SDimitris Papastamos 11466a504a75SDimitris Papastamos /* AIFCLK/fs ratio; look for a close match in either direction */ 11476a504a75SDimitris Papastamos best = 1; 11486a504a75SDimitris Papastamos best_val = abs((fs_ratios[1] * params_rate(params)) 11496a504a75SDimitris Papastamos - wm8995->aifclk[dai->id]); 11506a504a75SDimitris Papastamos for (i = 2; i < ARRAY_SIZE(fs_ratios); i++) { 11516a504a75SDimitris Papastamos cur_val = abs((fs_ratios[i] * params_rate(params)) 11526a504a75SDimitris Papastamos - wm8995->aifclk[dai->id]); 11536a504a75SDimitris Papastamos if (cur_val >= best_val) 11546a504a75SDimitris Papastamos continue; 11556a504a75SDimitris Papastamos best = i; 11566a504a75SDimitris Papastamos best_val = cur_val; 11576a504a75SDimitris Papastamos } 11586a504a75SDimitris Papastamos rate_val |= best; 11596a504a75SDimitris Papastamos 11606a504a75SDimitris Papastamos dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n", 11616a504a75SDimitris Papastamos dai->id + 1, fs_ratios[best]); 11626a504a75SDimitris Papastamos 11636a504a75SDimitris Papastamos /* 11646a504a75SDimitris Papastamos * We may not get quite the right frequency if using 11656a504a75SDimitris Papastamos * approximate clocks so look for the closest match that is 11666a504a75SDimitris Papastamos * higher than the target (we need to ensure that there enough 11676a504a75SDimitris Papastamos * BCLKs to clock out the samples). 11686a504a75SDimitris Papastamos */ 11696a504a75SDimitris Papastamos best = 0; 11706a504a75SDimitris Papastamos bclk = 0; 11716a504a75SDimitris Papastamos for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) { 11726a504a75SDimitris Papastamos cur_val = (wm8995->aifclk[dai->id] * 10 / bclk_divs[i]) - bclk_rate; 11736a504a75SDimitris Papastamos if (cur_val < 0) /* BCLK table is sorted */ 11746a504a75SDimitris Papastamos break; 11756a504a75SDimitris Papastamos best = i; 11766a504a75SDimitris Papastamos } 11776a504a75SDimitris Papastamos bclk |= best << WM8995_AIF1_BCLK_DIV_SHIFT; 11786a504a75SDimitris Papastamos 11796a504a75SDimitris Papastamos bclk_rate = wm8995->aifclk[dai->id] * 10 / bclk_divs[best]; 11806a504a75SDimitris Papastamos dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n", 11816a504a75SDimitris Papastamos bclk_divs[best], bclk_rate); 11826a504a75SDimitris Papastamos 11836a504a75SDimitris Papastamos lrclk = bclk_rate / params_rate(params); 11846a504a75SDimitris Papastamos dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n", 11856a504a75SDimitris Papastamos lrclk, bclk_rate / lrclk); 11866a504a75SDimitris Papastamos 11876a504a75SDimitris Papastamos snd_soc_update_bits(codec, aif1_reg, 11886a504a75SDimitris Papastamos WM8995_AIF1_WL_MASK, aif1); 11896a504a75SDimitris Papastamos snd_soc_update_bits(codec, bclk_reg, 11906a504a75SDimitris Papastamos WM8995_AIF1_BCLK_DIV_MASK, bclk); 11916a504a75SDimitris Papastamos snd_soc_update_bits(codec, lrclk_reg, 11926a504a75SDimitris Papastamos WM8995_AIF1DAC_RATE_MASK, lrclk); 11936a504a75SDimitris Papastamos snd_soc_update_bits(codec, rate_reg, 11946a504a75SDimitris Papastamos WM8995_AIF1_SR_MASK | 11956a504a75SDimitris Papastamos WM8995_AIF1CLK_RATE_MASK, rate_val); 11966a504a75SDimitris Papastamos return 0; 11976a504a75SDimitris Papastamos } 11986a504a75SDimitris Papastamos 11996a504a75SDimitris Papastamos static int wm8995_set_tristate(struct snd_soc_dai *codec_dai, int tristate) 12006a504a75SDimitris Papastamos { 12016a504a75SDimitris Papastamos struct snd_soc_codec *codec = codec_dai->codec; 12026a504a75SDimitris Papastamos int reg, val, mask; 12036a504a75SDimitris Papastamos 12046a504a75SDimitris Papastamos switch (codec_dai->id) { 12056a504a75SDimitris Papastamos case 0: 12066a504a75SDimitris Papastamos reg = WM8995_AIF1_MASTER_SLAVE; 12076a504a75SDimitris Papastamos mask = WM8995_AIF1_TRI; 12086a504a75SDimitris Papastamos break; 12096a504a75SDimitris Papastamos case 1: 12106a504a75SDimitris Papastamos reg = WM8995_AIF2_MASTER_SLAVE; 12116a504a75SDimitris Papastamos mask = WM8995_AIF2_TRI; 12126a504a75SDimitris Papastamos break; 12136a504a75SDimitris Papastamos case 2: 12146a504a75SDimitris Papastamos reg = WM8995_POWER_MANAGEMENT_5; 12156a504a75SDimitris Papastamos mask = WM8995_AIF3_TRI; 12166a504a75SDimitris Papastamos break; 12176a504a75SDimitris Papastamos default: 12186a504a75SDimitris Papastamos return -EINVAL; 12196a504a75SDimitris Papastamos } 12206a504a75SDimitris Papastamos 12216a504a75SDimitris Papastamos if (tristate) 12226a504a75SDimitris Papastamos val = mask; 12236a504a75SDimitris Papastamos else 12246a504a75SDimitris Papastamos val = 0; 12256a504a75SDimitris Papastamos 1226a2828792SDimitris Papastamos return snd_soc_update_bits(codec, reg, mask, val); 12276a504a75SDimitris Papastamos } 12286a504a75SDimitris Papastamos 12296a504a75SDimitris Papastamos /* The size in bits of the FLL divide multiplied by 10 12306a504a75SDimitris Papastamos * to allow rounding later */ 12316a504a75SDimitris Papastamos #define FIXED_FLL_SIZE ((1 << 16) * 10) 12326a504a75SDimitris Papastamos 12336a504a75SDimitris Papastamos struct fll_div { 12346a504a75SDimitris Papastamos u16 outdiv; 12356a504a75SDimitris Papastamos u16 n; 12366a504a75SDimitris Papastamos u16 k; 12376a504a75SDimitris Papastamos u16 clk_ref_div; 12386a504a75SDimitris Papastamos u16 fll_fratio; 12396a504a75SDimitris Papastamos }; 12406a504a75SDimitris Papastamos 12416a504a75SDimitris Papastamos static int wm8995_get_fll_config(struct fll_div *fll, 12426a504a75SDimitris Papastamos int freq_in, int freq_out) 12436a504a75SDimitris Papastamos { 12446a504a75SDimitris Papastamos u64 Kpart; 12456a504a75SDimitris Papastamos unsigned int K, Ndiv, Nmod; 12466a504a75SDimitris Papastamos 12476a504a75SDimitris Papastamos pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out); 12486a504a75SDimitris Papastamos 12496a504a75SDimitris Papastamos /* Scale the input frequency down to <= 13.5MHz */ 12506a504a75SDimitris Papastamos fll->clk_ref_div = 0; 12516a504a75SDimitris Papastamos while (freq_in > 13500000) { 12526a504a75SDimitris Papastamos fll->clk_ref_div++; 12536a504a75SDimitris Papastamos freq_in /= 2; 12546a504a75SDimitris Papastamos 12556a504a75SDimitris Papastamos if (fll->clk_ref_div > 3) 12566a504a75SDimitris Papastamos return -EINVAL; 12576a504a75SDimitris Papastamos } 12586a504a75SDimitris Papastamos pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in); 12596a504a75SDimitris Papastamos 12606a504a75SDimitris Papastamos /* Scale the output to give 90MHz<=Fvco<=100MHz */ 12616a504a75SDimitris Papastamos fll->outdiv = 3; 12626a504a75SDimitris Papastamos while (freq_out * (fll->outdiv + 1) < 90000000) { 12636a504a75SDimitris Papastamos fll->outdiv++; 12646a504a75SDimitris Papastamos if (fll->outdiv > 63) 12656a504a75SDimitris Papastamos return -EINVAL; 12666a504a75SDimitris Papastamos } 12676a504a75SDimitris Papastamos freq_out *= fll->outdiv + 1; 12686a504a75SDimitris Papastamos pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out); 12696a504a75SDimitris Papastamos 12706a504a75SDimitris Papastamos if (freq_in > 1000000) { 12716a504a75SDimitris Papastamos fll->fll_fratio = 0; 12726a504a75SDimitris Papastamos } else if (freq_in > 256000) { 12736a504a75SDimitris Papastamos fll->fll_fratio = 1; 12746a504a75SDimitris Papastamos freq_in *= 2; 12756a504a75SDimitris Papastamos } else if (freq_in > 128000) { 12766a504a75SDimitris Papastamos fll->fll_fratio = 2; 12776a504a75SDimitris Papastamos freq_in *= 4; 12786a504a75SDimitris Papastamos } else if (freq_in > 64000) { 12796a504a75SDimitris Papastamos fll->fll_fratio = 3; 12806a504a75SDimitris Papastamos freq_in *= 8; 12816a504a75SDimitris Papastamos } else { 12826a504a75SDimitris Papastamos fll->fll_fratio = 4; 12836a504a75SDimitris Papastamos freq_in *= 16; 12846a504a75SDimitris Papastamos } 12856a504a75SDimitris Papastamos pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in); 12866a504a75SDimitris Papastamos 12876a504a75SDimitris Papastamos /* Now, calculate N.K */ 12886a504a75SDimitris Papastamos Ndiv = freq_out / freq_in; 12896a504a75SDimitris Papastamos 12906a504a75SDimitris Papastamos fll->n = Ndiv; 12916a504a75SDimitris Papastamos Nmod = freq_out % freq_in; 12926a504a75SDimitris Papastamos pr_debug("Nmod=%d\n", Nmod); 12936a504a75SDimitris Papastamos 12946a504a75SDimitris Papastamos /* Calculate fractional part - scale up so we can round. */ 12956a504a75SDimitris Papastamos Kpart = FIXED_FLL_SIZE * (long long)Nmod; 12966a504a75SDimitris Papastamos 12976a504a75SDimitris Papastamos do_div(Kpart, freq_in); 12986a504a75SDimitris Papastamos 12996a504a75SDimitris Papastamos K = Kpart & 0xFFFFFFFF; 13006a504a75SDimitris Papastamos 13016a504a75SDimitris Papastamos if ((K % 10) >= 5) 13026a504a75SDimitris Papastamos K += 5; 13036a504a75SDimitris Papastamos 13046a504a75SDimitris Papastamos /* Move down to proper range now rounding is done */ 13056a504a75SDimitris Papastamos fll->k = K / 10; 13066a504a75SDimitris Papastamos 13076a504a75SDimitris Papastamos pr_debug("N=%x K=%x\n", fll->n, fll->k); 13086a504a75SDimitris Papastamos 13096a504a75SDimitris Papastamos return 0; 13106a504a75SDimitris Papastamos } 13116a504a75SDimitris Papastamos 13126a504a75SDimitris Papastamos static int wm8995_set_fll(struct snd_soc_dai *dai, int id, 13136a504a75SDimitris Papastamos int src, unsigned int freq_in, 13146a504a75SDimitris Papastamos unsigned int freq_out) 13156a504a75SDimitris Papastamos { 13166a504a75SDimitris Papastamos struct snd_soc_codec *codec; 13176a504a75SDimitris Papastamos struct wm8995_priv *wm8995; 13186a504a75SDimitris Papastamos int reg_offset, ret; 13196a504a75SDimitris Papastamos struct fll_div fll; 13206a504a75SDimitris Papastamos u16 reg, aif1, aif2; 13216a504a75SDimitris Papastamos 13226a504a75SDimitris Papastamos codec = dai->codec; 13236a504a75SDimitris Papastamos wm8995 = snd_soc_codec_get_drvdata(codec); 13246a504a75SDimitris Papastamos 13256a504a75SDimitris Papastamos aif1 = snd_soc_read(codec, WM8995_AIF1_CLOCKING_1) 13266a504a75SDimitris Papastamos & WM8995_AIF1CLK_ENA; 13276a504a75SDimitris Papastamos 13286a504a75SDimitris Papastamos aif2 = snd_soc_read(codec, WM8995_AIF2_CLOCKING_1) 13296a504a75SDimitris Papastamos & WM8995_AIF2CLK_ENA; 13306a504a75SDimitris Papastamos 13316a504a75SDimitris Papastamos switch (id) { 13326a504a75SDimitris Papastamos case WM8995_FLL1: 13336a504a75SDimitris Papastamos reg_offset = 0; 13346a504a75SDimitris Papastamos id = 0; 13356a504a75SDimitris Papastamos break; 13366a504a75SDimitris Papastamos case WM8995_FLL2: 13376a504a75SDimitris Papastamos reg_offset = 0x20; 13386a504a75SDimitris Papastamos id = 1; 13396a504a75SDimitris Papastamos break; 13406a504a75SDimitris Papastamos default: 13416a504a75SDimitris Papastamos return -EINVAL; 13426a504a75SDimitris Papastamos } 13436a504a75SDimitris Papastamos 13446a504a75SDimitris Papastamos switch (src) { 13456a504a75SDimitris Papastamos case 0: 13466a504a75SDimitris Papastamos /* Allow no source specification when stopping */ 13476a504a75SDimitris Papastamos if (freq_out) 13486a504a75SDimitris Papastamos return -EINVAL; 13496a504a75SDimitris Papastamos break; 13506a504a75SDimitris Papastamos case WM8995_FLL_SRC_MCLK1: 13516a504a75SDimitris Papastamos case WM8995_FLL_SRC_MCLK2: 13526a504a75SDimitris Papastamos case WM8995_FLL_SRC_LRCLK: 13536a504a75SDimitris Papastamos case WM8995_FLL_SRC_BCLK: 13546a504a75SDimitris Papastamos break; 13556a504a75SDimitris Papastamos default: 13566a504a75SDimitris Papastamos return -EINVAL; 13576a504a75SDimitris Papastamos } 13586a504a75SDimitris Papastamos 13596a504a75SDimitris Papastamos /* Are we changing anything? */ 13606a504a75SDimitris Papastamos if (wm8995->fll[id].src == src && 13616a504a75SDimitris Papastamos wm8995->fll[id].in == freq_in && wm8995->fll[id].out == freq_out) 13626a504a75SDimitris Papastamos return 0; 13636a504a75SDimitris Papastamos 13646a504a75SDimitris Papastamos /* If we're stopping the FLL redo the old config - no 13656a504a75SDimitris Papastamos * registers will actually be written but we avoid GCC flow 13666a504a75SDimitris Papastamos * analysis bugs spewing warnings. 13676a504a75SDimitris Papastamos */ 13686a504a75SDimitris Papastamos if (freq_out) 13696a504a75SDimitris Papastamos ret = wm8995_get_fll_config(&fll, freq_in, freq_out); 13706a504a75SDimitris Papastamos else 13716a504a75SDimitris Papastamos ret = wm8995_get_fll_config(&fll, wm8995->fll[id].in, 13726a504a75SDimitris Papastamos wm8995->fll[id].out); 13736a504a75SDimitris Papastamos if (ret < 0) 13746a504a75SDimitris Papastamos return ret; 13756a504a75SDimitris Papastamos 13766a504a75SDimitris Papastamos /* Gate the AIF clocks while we reclock */ 13776a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_AIF1_CLOCKING_1, 13786a504a75SDimitris Papastamos WM8995_AIF1CLK_ENA_MASK, 0); 13796a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_AIF2_CLOCKING_1, 13806a504a75SDimitris Papastamos WM8995_AIF2CLK_ENA_MASK, 0); 13816a504a75SDimitris Papastamos 13826a504a75SDimitris Papastamos /* We always need to disable the FLL while reconfiguring */ 13836a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_1 + reg_offset, 13846a504a75SDimitris Papastamos WM8995_FLL1_ENA_MASK, 0); 13856a504a75SDimitris Papastamos 13866a504a75SDimitris Papastamos reg = (fll.outdiv << WM8995_FLL1_OUTDIV_SHIFT) | 13876a504a75SDimitris Papastamos (fll.fll_fratio << WM8995_FLL1_FRATIO_SHIFT); 13886a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_2 + reg_offset, 13896a504a75SDimitris Papastamos WM8995_FLL1_OUTDIV_MASK | 13906a504a75SDimitris Papastamos WM8995_FLL1_FRATIO_MASK, reg); 13916a504a75SDimitris Papastamos 13926a504a75SDimitris Papastamos snd_soc_write(codec, WM8995_FLL1_CONTROL_3 + reg_offset, fll.k); 13936a504a75SDimitris Papastamos 13946a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_4 + reg_offset, 13956a504a75SDimitris Papastamos WM8995_FLL1_N_MASK, 13966a504a75SDimitris Papastamos fll.n << WM8995_FLL1_N_SHIFT); 13976a504a75SDimitris Papastamos 13986a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_5 + reg_offset, 13996a504a75SDimitris Papastamos WM8995_FLL1_REFCLK_DIV_MASK | 14006a504a75SDimitris Papastamos WM8995_FLL1_REFCLK_SRC_MASK, 14016a504a75SDimitris Papastamos (fll.clk_ref_div << WM8995_FLL1_REFCLK_DIV_SHIFT) | 14026a504a75SDimitris Papastamos (src - 1)); 14036a504a75SDimitris Papastamos 14046a504a75SDimitris Papastamos if (freq_out) 14056a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_FLL1_CONTROL_1 + reg_offset, 14066a504a75SDimitris Papastamos WM8995_FLL1_ENA_MASK, WM8995_FLL1_ENA); 14076a504a75SDimitris Papastamos 14086a504a75SDimitris Papastamos wm8995->fll[id].in = freq_in; 14096a504a75SDimitris Papastamos wm8995->fll[id].out = freq_out; 14106a504a75SDimitris Papastamos wm8995->fll[id].src = src; 14116a504a75SDimitris Papastamos 14126a504a75SDimitris Papastamos /* Enable any gated AIF clocks */ 14136a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_AIF1_CLOCKING_1, 14146a504a75SDimitris Papastamos WM8995_AIF1CLK_ENA_MASK, aif1); 14156a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_AIF2_CLOCKING_1, 14166a504a75SDimitris Papastamos WM8995_AIF2CLK_ENA_MASK, aif2); 14176a504a75SDimitris Papastamos 14186a504a75SDimitris Papastamos configure_clock(codec); 14196a504a75SDimitris Papastamos 14206a504a75SDimitris Papastamos return 0; 14216a504a75SDimitris Papastamos } 14226a504a75SDimitris Papastamos 14236a504a75SDimitris Papastamos static int wm8995_set_dai_sysclk(struct snd_soc_dai *dai, 14246a504a75SDimitris Papastamos int clk_id, unsigned int freq, int dir) 14256a504a75SDimitris Papastamos { 14266a504a75SDimitris Papastamos struct snd_soc_codec *codec; 14276a504a75SDimitris Papastamos struct wm8995_priv *wm8995; 14286a504a75SDimitris Papastamos 14296a504a75SDimitris Papastamos codec = dai->codec; 14306a504a75SDimitris Papastamos wm8995 = snd_soc_codec_get_drvdata(codec); 14316a504a75SDimitris Papastamos 14326a504a75SDimitris Papastamos switch (dai->id) { 14336a504a75SDimitris Papastamos case 0: 14346a504a75SDimitris Papastamos case 1: 14356a504a75SDimitris Papastamos break; 14366a504a75SDimitris Papastamos default: 14376a504a75SDimitris Papastamos /* AIF3 shares clocking with AIF1/2 */ 14386a504a75SDimitris Papastamos return -EINVAL; 14396a504a75SDimitris Papastamos } 14406a504a75SDimitris Papastamos 14416a504a75SDimitris Papastamos switch (clk_id) { 14426a504a75SDimitris Papastamos case WM8995_SYSCLK_MCLK1: 14436a504a75SDimitris Papastamos wm8995->sysclk[dai->id] = WM8995_SYSCLK_MCLK1; 14446a504a75SDimitris Papastamos wm8995->mclk[0] = freq; 14456a504a75SDimitris Papastamos dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n", 14466a504a75SDimitris Papastamos dai->id + 1, freq); 14476a504a75SDimitris Papastamos break; 14486a504a75SDimitris Papastamos case WM8995_SYSCLK_MCLK2: 14496a504a75SDimitris Papastamos wm8995->sysclk[dai->id] = WM8995_SYSCLK_MCLK1; 14506a504a75SDimitris Papastamos wm8995->mclk[1] = freq; 14516a504a75SDimitris Papastamos dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n", 14526a504a75SDimitris Papastamos dai->id + 1, freq); 14536a504a75SDimitris Papastamos break; 14546a504a75SDimitris Papastamos case WM8995_SYSCLK_FLL1: 14556a504a75SDimitris Papastamos wm8995->sysclk[dai->id] = WM8995_SYSCLK_FLL1; 14566a504a75SDimitris Papastamos dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id + 1); 14576a504a75SDimitris Papastamos break; 14586a504a75SDimitris Papastamos case WM8995_SYSCLK_FLL2: 14596a504a75SDimitris Papastamos wm8995->sysclk[dai->id] = WM8995_SYSCLK_FLL2; 14606a504a75SDimitris Papastamos dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id + 1); 14616a504a75SDimitris Papastamos break; 14626a504a75SDimitris Papastamos case WM8995_SYSCLK_OPCLK: 14636a504a75SDimitris Papastamos default: 14646a504a75SDimitris Papastamos dev_err(dai->dev, "Unknown clock source %d\n", clk_id); 14656a504a75SDimitris Papastamos return -EINVAL; 14666a504a75SDimitris Papastamos } 14676a504a75SDimitris Papastamos 14686a504a75SDimitris Papastamos configure_clock(codec); 14696a504a75SDimitris Papastamos 14706a504a75SDimitris Papastamos return 0; 14716a504a75SDimitris Papastamos } 14726a504a75SDimitris Papastamos 14736a504a75SDimitris Papastamos static int wm8995_set_bias_level(struct snd_soc_codec *codec, 14746a504a75SDimitris Papastamos enum snd_soc_bias_level level) 14756a504a75SDimitris Papastamos { 14766a504a75SDimitris Papastamos struct wm8995_priv *wm8995; 14776a504a75SDimitris Papastamos int ret; 14786a504a75SDimitris Papastamos 14796a504a75SDimitris Papastamos wm8995 = snd_soc_codec_get_drvdata(codec); 14806a504a75SDimitris Papastamos switch (level) { 14816a504a75SDimitris Papastamos case SND_SOC_BIAS_ON: 14826a504a75SDimitris Papastamos case SND_SOC_BIAS_PREPARE: 14836a504a75SDimitris Papastamos break; 14846a504a75SDimitris Papastamos case SND_SOC_BIAS_STANDBY: 14856a504a75SDimitris Papastamos if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 14866a504a75SDimitris Papastamos ret = snd_soc_cache_sync(codec); 14876a504a75SDimitris Papastamos if (ret) { 14886a504a75SDimitris Papastamos dev_err(codec->dev, 14896a504a75SDimitris Papastamos "Failed to sync cache: %d\n", ret); 14906a504a75SDimitris Papastamos return ret; 14916a504a75SDimitris Papastamos } 14926a504a75SDimitris Papastamos 14936a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1, 14946a504a75SDimitris Papastamos WM8995_BG_ENA_MASK, WM8995_BG_ENA); 14956a504a75SDimitris Papastamos 14966a504a75SDimitris Papastamos } 14976a504a75SDimitris Papastamos break; 14986a504a75SDimitris Papastamos case SND_SOC_BIAS_OFF: 14996a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_POWER_MANAGEMENT_1, 15006a504a75SDimitris Papastamos WM8995_BG_ENA_MASK, 0); 15016a504a75SDimitris Papastamos break; 15026a504a75SDimitris Papastamos } 15036a504a75SDimitris Papastamos 15046a504a75SDimitris Papastamos codec->dapm.bias_level = level; 15056a504a75SDimitris Papastamos return 0; 15066a504a75SDimitris Papastamos } 15076a504a75SDimitris Papastamos 15086a504a75SDimitris Papastamos #ifdef CONFIG_PM 15096a504a75SDimitris Papastamos static int wm8995_suspend(struct snd_soc_codec *codec, pm_message_t state) 15106a504a75SDimitris Papastamos { 15116a504a75SDimitris Papastamos wm8995_set_bias_level(codec, SND_SOC_BIAS_OFF); 15126a504a75SDimitris Papastamos return 0; 15136a504a75SDimitris Papastamos } 15146a504a75SDimitris Papastamos 15156a504a75SDimitris Papastamos static int wm8995_resume(struct snd_soc_codec *codec) 15166a504a75SDimitris Papastamos { 15176a504a75SDimitris Papastamos wm8995_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 15186a504a75SDimitris Papastamos return 0; 15196a504a75SDimitris Papastamos } 15206a504a75SDimitris Papastamos #else 15216a504a75SDimitris Papastamos #define wm8995_suspend NULL 15226a504a75SDimitris Papastamos #define wm8995_resume NULL 15236a504a75SDimitris Papastamos #endif 15246a504a75SDimitris Papastamos 15256a504a75SDimitris Papastamos static int wm8995_remove(struct snd_soc_codec *codec) 15266a504a75SDimitris Papastamos { 15276a504a75SDimitris Papastamos struct wm8995_priv *wm8995; 15286a504a75SDimitris Papastamos struct i2c_client *i2c; 15296a504a75SDimitris Papastamos 15306a504a75SDimitris Papastamos i2c = container_of(codec->dev, struct i2c_client, dev); 15316a504a75SDimitris Papastamos wm8995 = snd_soc_codec_get_drvdata(codec); 15326a504a75SDimitris Papastamos wm8995_set_bias_level(codec, SND_SOC_BIAS_OFF); 15336a504a75SDimitris Papastamos return 0; 15346a504a75SDimitris Papastamos } 15356a504a75SDimitris Papastamos 15366a504a75SDimitris Papastamos static int wm8995_probe(struct snd_soc_codec *codec) 15376a504a75SDimitris Papastamos { 15386a504a75SDimitris Papastamos struct wm8995_priv *wm8995; 15396a504a75SDimitris Papastamos int ret; 15406a504a75SDimitris Papastamos 15416a504a75SDimitris Papastamos codec->dapm.idle_bias_off = 1; 15426a504a75SDimitris Papastamos wm8995 = snd_soc_codec_get_drvdata(codec); 15436a504a75SDimitris Papastamos 15446a504a75SDimitris Papastamos ret = snd_soc_codec_set_cache_io(codec, 16, 16, wm8995->control_type); 15456a504a75SDimitris Papastamos if (ret < 0) { 15466a504a75SDimitris Papastamos dev_err(codec->dev, "Failed to set cache i/o: %d\n", ret); 15476a504a75SDimitris Papastamos return ret; 15486a504a75SDimitris Papastamos } 15496a504a75SDimitris Papastamos 15506a504a75SDimitris Papastamos ret = snd_soc_read(codec, WM8995_SOFTWARE_RESET); 15516a504a75SDimitris Papastamos if (ret < 0) { 15526a504a75SDimitris Papastamos dev_err(codec->dev, "Failed to read device ID: %d\n", ret); 15536a504a75SDimitris Papastamos return ret; 15546a504a75SDimitris Papastamos } 15556a504a75SDimitris Papastamos 15566a504a75SDimitris Papastamos if (ret != 0x8995) { 15576a504a75SDimitris Papastamos dev_err(codec->dev, "Invalid device ID: %#x\n", ret); 15586a504a75SDimitris Papastamos return -EINVAL; 15596a504a75SDimitris Papastamos } 15606a504a75SDimitris Papastamos 15616a504a75SDimitris Papastamos ret = snd_soc_write(codec, WM8995_SOFTWARE_RESET, 0); 15626a504a75SDimitris Papastamos if (ret < 0) { 15636a504a75SDimitris Papastamos dev_err(codec->dev, "Failed to issue reset: %d\n", ret); 15646a504a75SDimitris Papastamos return ret; 15656a504a75SDimitris Papastamos } 15666a504a75SDimitris Papastamos 15676a504a75SDimitris Papastamos wm8995_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 15686a504a75SDimitris Papastamos 15696a504a75SDimitris Papastamos /* Latch volume updates (right only; we always do left then right). */ 15706a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_AIF1_DAC1_RIGHT_VOLUME, 15716a504a75SDimitris Papastamos WM8995_AIF1DAC1_VU_MASK, WM8995_AIF1DAC1_VU); 15726a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_AIF1_DAC2_RIGHT_VOLUME, 15736a504a75SDimitris Papastamos WM8995_AIF1DAC2_VU_MASK, WM8995_AIF1DAC2_VU); 15746a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_AIF2_DAC_RIGHT_VOLUME, 15756a504a75SDimitris Papastamos WM8995_AIF2DAC_VU_MASK, WM8995_AIF2DAC_VU); 15766a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_AIF1_ADC1_RIGHT_VOLUME, 15776a504a75SDimitris Papastamos WM8995_AIF1ADC1_VU_MASK, WM8995_AIF1ADC1_VU); 15786a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_AIF1_ADC2_RIGHT_VOLUME, 15796a504a75SDimitris Papastamos WM8995_AIF1ADC2_VU_MASK, WM8995_AIF1ADC2_VU); 15806a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_AIF2_ADC_RIGHT_VOLUME, 15816a504a75SDimitris Papastamos WM8995_AIF2ADC_VU_MASK, WM8995_AIF1ADC2_VU); 15826a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_DAC1_RIGHT_VOLUME, 15836a504a75SDimitris Papastamos WM8995_DAC1_VU_MASK, WM8995_DAC1_VU); 15846a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_DAC2_RIGHT_VOLUME, 15856a504a75SDimitris Papastamos WM8995_DAC2_VU_MASK, WM8995_DAC2_VU); 15866a504a75SDimitris Papastamos snd_soc_update_bits(codec, WM8995_RIGHT_LINE_INPUT_1_VOLUME, 15876a504a75SDimitris Papastamos WM8995_IN1_VU_MASK, WM8995_IN1_VU); 15886a504a75SDimitris Papastamos 15896a504a75SDimitris Papastamos wm8995_update_class_w(codec); 15906a504a75SDimitris Papastamos 15916a504a75SDimitris Papastamos snd_soc_add_controls(codec, wm8995_snd_controls, 15926a504a75SDimitris Papastamos ARRAY_SIZE(wm8995_snd_controls)); 15936a504a75SDimitris Papastamos snd_soc_dapm_new_controls(&codec->dapm, wm8995_dapm_widgets, 15946a504a75SDimitris Papastamos ARRAY_SIZE(wm8995_dapm_widgets)); 15956a504a75SDimitris Papastamos snd_soc_dapm_add_routes(&codec->dapm, wm8995_intercon, 15966a504a75SDimitris Papastamos ARRAY_SIZE(wm8995_intercon)); 15976a504a75SDimitris Papastamos 15986a504a75SDimitris Papastamos return 0; 15996a504a75SDimitris Papastamos } 16006a504a75SDimitris Papastamos 16016a504a75SDimitris Papastamos #define WM8995_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 16026a504a75SDimitris Papastamos SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) 16036a504a75SDimitris Papastamos 16046a504a75SDimitris Papastamos static struct snd_soc_dai_ops wm8995_aif1_dai_ops = { 16056a504a75SDimitris Papastamos .set_sysclk = wm8995_set_dai_sysclk, 16066a504a75SDimitris Papastamos .set_fmt = wm8995_set_dai_fmt, 16076a504a75SDimitris Papastamos .hw_params = wm8995_hw_params, 16086a504a75SDimitris Papastamos .digital_mute = wm8995_aif_mute, 16096a504a75SDimitris Papastamos .set_pll = wm8995_set_fll, 16106a504a75SDimitris Papastamos .set_tristate = wm8995_set_tristate, 16116a504a75SDimitris Papastamos }; 16126a504a75SDimitris Papastamos 16136a504a75SDimitris Papastamos static struct snd_soc_dai_ops wm8995_aif2_dai_ops = { 16146a504a75SDimitris Papastamos .set_sysclk = wm8995_set_dai_sysclk, 16156a504a75SDimitris Papastamos .set_fmt = wm8995_set_dai_fmt, 16166a504a75SDimitris Papastamos .hw_params = wm8995_hw_params, 16176a504a75SDimitris Papastamos .digital_mute = wm8995_aif_mute, 16186a504a75SDimitris Papastamos .set_pll = wm8995_set_fll, 16196a504a75SDimitris Papastamos .set_tristate = wm8995_set_tristate, 16206a504a75SDimitris Papastamos }; 16216a504a75SDimitris Papastamos 16226a504a75SDimitris Papastamos static struct snd_soc_dai_ops wm8995_aif3_dai_ops = { 16236a504a75SDimitris Papastamos .set_tristate = wm8995_set_tristate, 16246a504a75SDimitris Papastamos }; 16256a504a75SDimitris Papastamos 16266a504a75SDimitris Papastamos static struct snd_soc_dai_driver wm8995_dai[] = { 16276a504a75SDimitris Papastamos { 16286a504a75SDimitris Papastamos .name = "wm8995-aif1", 16296a504a75SDimitris Papastamos .playback = { 16306a504a75SDimitris Papastamos .stream_name = "AIF1 Playback", 16316a504a75SDimitris Papastamos .channels_min = 2, 16326a504a75SDimitris Papastamos .channels_max = 2, 16336a504a75SDimitris Papastamos .rates = SNDRV_PCM_RATE_8000_96000, 16346a504a75SDimitris Papastamos .formats = WM8995_FORMATS 16356a504a75SDimitris Papastamos }, 16366a504a75SDimitris Papastamos .capture = { 16376a504a75SDimitris Papastamos .stream_name = "AIF1 Capture", 16386a504a75SDimitris Papastamos .channels_min = 2, 16396a504a75SDimitris Papastamos .channels_max = 2, 16406a504a75SDimitris Papastamos .rates = SNDRV_PCM_RATE_8000_48000, 16416a504a75SDimitris Papastamos .formats = WM8995_FORMATS 16426a504a75SDimitris Papastamos }, 16436a504a75SDimitris Papastamos .ops = &wm8995_aif1_dai_ops 16446a504a75SDimitris Papastamos }, 16456a504a75SDimitris Papastamos { 16466a504a75SDimitris Papastamos .name = "wm8995-aif2", 16476a504a75SDimitris Papastamos .playback = { 16486a504a75SDimitris Papastamos .stream_name = "AIF2 Playback", 16496a504a75SDimitris Papastamos .channels_min = 2, 16506a504a75SDimitris Papastamos .channels_max = 2, 16516a504a75SDimitris Papastamos .rates = SNDRV_PCM_RATE_8000_96000, 16526a504a75SDimitris Papastamos .formats = WM8995_FORMATS 16536a504a75SDimitris Papastamos }, 16546a504a75SDimitris Papastamos .capture = { 16556a504a75SDimitris Papastamos .stream_name = "AIF2 Capture", 16566a504a75SDimitris Papastamos .channels_min = 2, 16576a504a75SDimitris Papastamos .channels_max = 2, 16586a504a75SDimitris Papastamos .rates = SNDRV_PCM_RATE_8000_48000, 16596a504a75SDimitris Papastamos .formats = WM8995_FORMATS 16606a504a75SDimitris Papastamos }, 16616a504a75SDimitris Papastamos .ops = &wm8995_aif2_dai_ops 16626a504a75SDimitris Papastamos }, 16636a504a75SDimitris Papastamos { 16646a504a75SDimitris Papastamos .name = "wm8995-aif3", 16656a504a75SDimitris Papastamos .playback = { 16666a504a75SDimitris Papastamos .stream_name = "AIF3 Playback", 16676a504a75SDimitris Papastamos .channels_min = 2, 16686a504a75SDimitris Papastamos .channels_max = 2, 16696a504a75SDimitris Papastamos .rates = SNDRV_PCM_RATE_8000_96000, 16706a504a75SDimitris Papastamos .formats = WM8995_FORMATS 16716a504a75SDimitris Papastamos }, 16726a504a75SDimitris Papastamos .capture = { 16736a504a75SDimitris Papastamos .stream_name = "AIF3 Capture", 16746a504a75SDimitris Papastamos .channels_min = 2, 16756a504a75SDimitris Papastamos .channels_max = 2, 16766a504a75SDimitris Papastamos .rates = SNDRV_PCM_RATE_8000_48000, 16776a504a75SDimitris Papastamos .formats = WM8995_FORMATS 16786a504a75SDimitris Papastamos }, 16796a504a75SDimitris Papastamos .ops = &wm8995_aif3_dai_ops 16806a504a75SDimitris Papastamos } 16816a504a75SDimitris Papastamos }; 16826a504a75SDimitris Papastamos 16836a504a75SDimitris Papastamos static struct snd_soc_codec_driver soc_codec_dev_wm8995 = { 16846a504a75SDimitris Papastamos .probe = wm8995_probe, 16856a504a75SDimitris Papastamos .remove = wm8995_remove, 16866a504a75SDimitris Papastamos .suspend = wm8995_suspend, 16876a504a75SDimitris Papastamos .resume = wm8995_resume, 16886a504a75SDimitris Papastamos .set_bias_level = wm8995_set_bias_level, 16896a504a75SDimitris Papastamos .reg_cache_size = ARRAY_SIZE(wm8995_reg_defs), 16906a504a75SDimitris Papastamos .reg_word_size = sizeof(u16), 16916a504a75SDimitris Papastamos .reg_cache_default = wm8995_reg_defs, 16926a504a75SDimitris Papastamos .volatile_register = wm8995_volatile, 16936a504a75SDimitris Papastamos .compress_type = SND_SOC_RBTREE_COMPRESSION 16946a504a75SDimitris Papastamos }; 16956a504a75SDimitris Papastamos 16966a504a75SDimitris Papastamos #if defined(CONFIG_SPI_MASTER) 16976a504a75SDimitris Papastamos static int __devinit wm8995_spi_probe(struct spi_device *spi) 16986a504a75SDimitris Papastamos { 16996a504a75SDimitris Papastamos struct wm8995_priv *wm8995; 17006a504a75SDimitris Papastamos int ret; 17016a504a75SDimitris Papastamos 17026a504a75SDimitris Papastamos wm8995 = kzalloc(sizeof *wm8995, GFP_KERNEL); 17036a504a75SDimitris Papastamos if (!wm8995) 17046a504a75SDimitris Papastamos return -ENOMEM; 17056a504a75SDimitris Papastamos 17066a504a75SDimitris Papastamos wm8995->control_type = SND_SOC_SPI; 17076a504a75SDimitris Papastamos spi_set_drvdata(spi, wm8995); 17086a504a75SDimitris Papastamos 17096a504a75SDimitris Papastamos ret = snd_soc_register_codec(&spi->dev, 17106a504a75SDimitris Papastamos &soc_codec_dev_wm8995, wm8995_dai, 17116a504a75SDimitris Papastamos ARRAY_SIZE(wm8995_dai)); 17126a504a75SDimitris Papastamos if (ret < 0) 17136a504a75SDimitris Papastamos kfree(wm8995); 17146a504a75SDimitris Papastamos return ret; 17156a504a75SDimitris Papastamos } 17166a504a75SDimitris Papastamos 17176a504a75SDimitris Papastamos static int __devexit wm8995_spi_remove(struct spi_device *spi) 17186a504a75SDimitris Papastamos { 17196a504a75SDimitris Papastamos snd_soc_unregister_codec(&spi->dev); 17206a504a75SDimitris Papastamos kfree(spi_get_drvdata(spi)); 17216a504a75SDimitris Papastamos return 0; 17226a504a75SDimitris Papastamos } 17236a504a75SDimitris Papastamos 17246a504a75SDimitris Papastamos static struct spi_driver wm8995_spi_driver = { 17256a504a75SDimitris Papastamos .driver = { 17266a504a75SDimitris Papastamos .name = "wm8995", 17276a504a75SDimitris Papastamos .owner = THIS_MODULE, 17286a504a75SDimitris Papastamos }, 17296a504a75SDimitris Papastamos .probe = wm8995_spi_probe, 17306a504a75SDimitris Papastamos .remove = __devexit_p(wm8995_spi_remove) 17316a504a75SDimitris Papastamos }; 17326a504a75SDimitris Papastamos #endif 17336a504a75SDimitris Papastamos 17346a504a75SDimitris Papastamos #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 17356a504a75SDimitris Papastamos static __devinit int wm8995_i2c_probe(struct i2c_client *i2c, 17366a504a75SDimitris Papastamos const struct i2c_device_id *id) 17376a504a75SDimitris Papastamos { 17386a504a75SDimitris Papastamos struct wm8995_priv *wm8995; 17396a504a75SDimitris Papastamos int ret; 17406a504a75SDimitris Papastamos 17416a504a75SDimitris Papastamos wm8995 = kzalloc(sizeof *wm8995, GFP_KERNEL); 17426a504a75SDimitris Papastamos if (!wm8995) 17436a504a75SDimitris Papastamos return -ENOMEM; 17446a504a75SDimitris Papastamos 17456a504a75SDimitris Papastamos wm8995->control_type = SND_SOC_I2C; 17466a504a75SDimitris Papastamos i2c_set_clientdata(i2c, wm8995); 17476a504a75SDimitris Papastamos 17486a504a75SDimitris Papastamos ret = snd_soc_register_codec(&i2c->dev, 17496a504a75SDimitris Papastamos &soc_codec_dev_wm8995, wm8995_dai, 17506a504a75SDimitris Papastamos ARRAY_SIZE(wm8995_dai)); 17516a504a75SDimitris Papastamos if (ret < 0) 17526a504a75SDimitris Papastamos kfree(wm8995); 17536a504a75SDimitris Papastamos return ret; 17546a504a75SDimitris Papastamos } 17556a504a75SDimitris Papastamos 17566a504a75SDimitris Papastamos static __devexit int wm8995_i2c_remove(struct i2c_client *client) 17576a504a75SDimitris Papastamos { 17586a504a75SDimitris Papastamos snd_soc_unregister_codec(&client->dev); 17596a504a75SDimitris Papastamos kfree(i2c_get_clientdata(client)); 17606a504a75SDimitris Papastamos return 0; 17616a504a75SDimitris Papastamos } 17626a504a75SDimitris Papastamos 17636a504a75SDimitris Papastamos static const struct i2c_device_id wm8995_i2c_id[] = { 17646a504a75SDimitris Papastamos {"wm8995", 0}, 17656a504a75SDimitris Papastamos {} 17666a504a75SDimitris Papastamos }; 17676a504a75SDimitris Papastamos 17686a504a75SDimitris Papastamos MODULE_DEVICE_TABLE(i2c, wm8995_i2c_id); 17696a504a75SDimitris Papastamos 17706a504a75SDimitris Papastamos static struct i2c_driver wm8995_i2c_driver = { 17716a504a75SDimitris Papastamos .driver = { 17726a504a75SDimitris Papastamos .name = "wm8995", 17736a504a75SDimitris Papastamos .owner = THIS_MODULE, 17746a504a75SDimitris Papastamos }, 17756a504a75SDimitris Papastamos .probe = wm8995_i2c_probe, 17766a504a75SDimitris Papastamos .remove = __devexit_p(wm8995_i2c_remove), 17776a504a75SDimitris Papastamos .id_table = wm8995_i2c_id 17786a504a75SDimitris Papastamos }; 17796a504a75SDimitris Papastamos #endif 17806a504a75SDimitris Papastamos 17816a504a75SDimitris Papastamos static int __init wm8995_modinit(void) 17826a504a75SDimitris Papastamos { 17836a504a75SDimitris Papastamos int ret = 0; 17846a504a75SDimitris Papastamos 17856a504a75SDimitris Papastamos #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 17866a504a75SDimitris Papastamos ret = i2c_add_driver(&wm8995_i2c_driver); 17876a504a75SDimitris Papastamos if (ret) { 17886a504a75SDimitris Papastamos printk(KERN_ERR "Failed to register wm8995 I2C driver: %d\n", 17896a504a75SDimitris Papastamos ret); 17906a504a75SDimitris Papastamos } 17916a504a75SDimitris Papastamos #endif 17926a504a75SDimitris Papastamos #if defined(CONFIG_SPI_MASTER) 17936a504a75SDimitris Papastamos ret = spi_register_driver(&wm8995_spi_driver); 17946a504a75SDimitris Papastamos if (ret) { 17956a504a75SDimitris Papastamos printk(KERN_ERR "Failed to register wm8995 SPI driver: %d\n", 17966a504a75SDimitris Papastamos ret); 17976a504a75SDimitris Papastamos } 17986a504a75SDimitris Papastamos #endif 17996a504a75SDimitris Papastamos return ret; 18006a504a75SDimitris Papastamos } 18016a504a75SDimitris Papastamos 18026a504a75SDimitris Papastamos module_init(wm8995_modinit); 18036a504a75SDimitris Papastamos 18046a504a75SDimitris Papastamos static void __exit wm8995_exit(void) 18056a504a75SDimitris Papastamos { 18066a504a75SDimitris Papastamos #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 18076a504a75SDimitris Papastamos i2c_del_driver(&wm8995_i2c_driver); 18086a504a75SDimitris Papastamos #endif 18096a504a75SDimitris Papastamos #if defined(CONFIG_SPI_MASTER) 18106a504a75SDimitris Papastamos spi_unregister_driver(&wm8995_spi_driver); 18116a504a75SDimitris Papastamos #endif 18126a504a75SDimitris Papastamos } 18136a504a75SDimitris Papastamos 18146a504a75SDimitris Papastamos module_exit(wm8995_exit); 18156a504a75SDimitris Papastamos 18166a504a75SDimitris Papastamos MODULE_DESCRIPTION("ASoC WM8995 driver"); 18176a504a75SDimitris Papastamos MODULE_AUTHOR("Dimitris Papastamos <dp@opensource.wolfsonmicro.com>"); 18186a504a75SDimitris Papastamos MODULE_LICENSE("GPL"); 1819