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