12a9ae13aSMark Brown /* 22a9ae13aSMark Brown * wm8737.c -- WM8737 ALSA SoC Audio driver 32a9ae13aSMark Brown * 42a9ae13aSMark Brown * Copyright 2010 Wolfson Microelectronics plc 52a9ae13aSMark Brown * 62a9ae13aSMark Brown * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> 72a9ae13aSMark Brown * 82a9ae13aSMark Brown * This program is free software; you can redistribute it and/or modify 92a9ae13aSMark Brown * it under the terms of the GNU General Public License version 2 as 102a9ae13aSMark Brown * published by the Free Software Foundation. 112a9ae13aSMark Brown */ 122a9ae13aSMark Brown 132a9ae13aSMark Brown #include <linux/module.h> 142a9ae13aSMark Brown #include <linux/moduleparam.h> 152a9ae13aSMark Brown #include <linux/init.h> 162a9ae13aSMark Brown #include <linux/delay.h> 172a9ae13aSMark Brown #include <linux/pm.h> 182a9ae13aSMark Brown #include <linux/i2c.h> 193ef8ac0dSMark Brown #include <linux/regmap.h> 202a9ae13aSMark Brown #include <linux/regulator/consumer.h> 212a9ae13aSMark Brown #include <linux/spi/spi.h> 222a9ae13aSMark Brown #include <linux/slab.h> 2353a5a83dSMark Brown #include <linux/of_device.h> 242a9ae13aSMark Brown #include <sound/core.h> 252a9ae13aSMark Brown #include <sound/pcm.h> 262a9ae13aSMark Brown #include <sound/pcm_params.h> 272a9ae13aSMark Brown #include <sound/soc.h> 282a9ae13aSMark Brown #include <sound/soc-dapm.h> 292a9ae13aSMark Brown #include <sound/initval.h> 302a9ae13aSMark Brown #include <sound/tlv.h> 312a9ae13aSMark Brown 322a9ae13aSMark Brown #include "wm8737.h" 332a9ae13aSMark Brown 342a9ae13aSMark Brown #define WM8737_NUM_SUPPLIES 4 352a9ae13aSMark Brown static const char *wm8737_supply_names[WM8737_NUM_SUPPLIES] = { 362a9ae13aSMark Brown "DCVDD", 372a9ae13aSMark Brown "DBVDD", 382a9ae13aSMark Brown "AVDD", 392a9ae13aSMark Brown "MVDD", 402a9ae13aSMark Brown }; 412a9ae13aSMark Brown 422a9ae13aSMark Brown /* codec private data */ 432a9ae13aSMark Brown struct wm8737_priv { 443ef8ac0dSMark Brown struct regmap *regmap; 452a9ae13aSMark Brown struct regulator_bulk_data supplies[WM8737_NUM_SUPPLIES]; 462a9ae13aSMark Brown unsigned int mclk; 472a9ae13aSMark Brown }; 482a9ae13aSMark Brown 493ef8ac0dSMark Brown static const struct reg_default wm8737_reg_defaults[] = { 503ef8ac0dSMark Brown { 0, 0x00C3 }, /* R0 - Left PGA volume */ 513ef8ac0dSMark Brown { 1, 0x00C3 }, /* R1 - Right PGA volume */ 523ef8ac0dSMark Brown { 2, 0x0007 }, /* R2 - AUDIO path L */ 533ef8ac0dSMark Brown { 3, 0x0007 }, /* R3 - AUDIO path R */ 543ef8ac0dSMark Brown { 4, 0x0000 }, /* R4 - 3D Enhance */ 553ef8ac0dSMark Brown { 5, 0x0000 }, /* R5 - ADC Control */ 563ef8ac0dSMark Brown { 6, 0x0000 }, /* R6 - Power Management */ 573ef8ac0dSMark Brown { 7, 0x000A }, /* R7 - Audio Format */ 583ef8ac0dSMark Brown { 8, 0x0000 }, /* R8 - Clocking */ 593ef8ac0dSMark Brown { 9, 0x000F }, /* R9 - MIC Preamp Control */ 603ef8ac0dSMark Brown { 10, 0x0003 }, /* R10 - Misc Bias Control */ 613ef8ac0dSMark Brown { 11, 0x0000 }, /* R11 - Noise Gate */ 623ef8ac0dSMark Brown { 12, 0x007C }, /* R12 - ALC1 */ 633ef8ac0dSMark Brown { 13, 0x0000 }, /* R13 - ALC2 */ 643ef8ac0dSMark Brown { 14, 0x0032 }, /* R14 - ALC3 */ 652a9ae13aSMark Brown }; 662a9ae13aSMark Brown 673ef8ac0dSMark Brown static bool wm8737_volatile(struct device *dev, unsigned int reg) 683ef8ac0dSMark Brown { 693ef8ac0dSMark Brown switch (reg) { 703ef8ac0dSMark Brown case WM8737_RESET: 713ef8ac0dSMark Brown return true; 723ef8ac0dSMark Brown default: 733ef8ac0dSMark Brown return false; 743ef8ac0dSMark Brown } 753ef8ac0dSMark Brown } 763ef8ac0dSMark Brown 772a9ae13aSMark Brown static int wm8737_reset(struct snd_soc_codec *codec) 782a9ae13aSMark Brown { 792a9ae13aSMark Brown return snd_soc_write(codec, WM8737_RESET, 0); 802a9ae13aSMark Brown } 812a9ae13aSMark Brown 822a9ae13aSMark Brown static const unsigned int micboost_tlv[] = { 832a9ae13aSMark Brown TLV_DB_RANGE_HEAD(4), 842a9ae13aSMark Brown 0, 0, TLV_DB_SCALE_ITEM(1300, 0, 0), 852a9ae13aSMark Brown 1, 1, TLV_DB_SCALE_ITEM(1800, 0, 0), 862a9ae13aSMark Brown 2, 2, TLV_DB_SCALE_ITEM(2800, 0, 0), 872a9ae13aSMark Brown 3, 3, TLV_DB_SCALE_ITEM(3300, 0, 0), 882a9ae13aSMark Brown }; 892a9ae13aSMark Brown static const DECLARE_TLV_DB_SCALE(pga_tlv, -9750, 50, 1); 902a9ae13aSMark Brown static const DECLARE_TLV_DB_SCALE(adc_tlv, -600, 600, 0); 912a9ae13aSMark Brown static const DECLARE_TLV_DB_SCALE(ng_tlv, -7800, 600, 0); 92fcd02e26SMark Brown static const DECLARE_TLV_DB_SCALE(alc_max_tlv, -1200, 600, 0); 93fcd02e26SMark Brown static const DECLARE_TLV_DB_SCALE(alc_target_tlv, -1800, 100, 0); 942a9ae13aSMark Brown 952a9ae13aSMark Brown static const char *micbias_enum_text[] = { 962a9ae13aSMark Brown "25%", 972a9ae13aSMark Brown "50%", 982a9ae13aSMark Brown "75%", 992a9ae13aSMark Brown "100%", 1002a9ae13aSMark Brown }; 1012a9ae13aSMark Brown 102ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(micbias_enum, 103ca275811STakashi Iwai WM8737_MIC_PREAMP_CONTROL, 0, micbias_enum_text); 1042a9ae13aSMark Brown 1052a9ae13aSMark Brown static const char *low_cutoff_text[] = { 1062a9ae13aSMark Brown "Low", "High" 1072a9ae13aSMark Brown }; 1082a9ae13aSMark Brown 109ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(low_3d, 110ca275811STakashi Iwai WM8737_3D_ENHANCE, 6, low_cutoff_text); 1112a9ae13aSMark Brown 1122a9ae13aSMark Brown static const char *high_cutoff_text[] = { 1132a9ae13aSMark Brown "High", "Low" 1142a9ae13aSMark Brown }; 1152a9ae13aSMark Brown 116ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(high_3d, 117ca275811STakashi Iwai WM8737_3D_ENHANCE, 5, high_cutoff_text); 1182a9ae13aSMark Brown 119fcd02e26SMark Brown static const char *alc_fn_text[] = { 120fcd02e26SMark Brown "Disabled", "Right", "Left", "Stereo" 121fcd02e26SMark Brown }; 122fcd02e26SMark Brown 123ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(alc_fn, 124ca275811STakashi Iwai WM8737_ALC1, 7, alc_fn_text); 125fcd02e26SMark Brown 126fcd02e26SMark Brown static const char *alc_hold_text[] = { 127fcd02e26SMark Brown "0", "2.67ms", "5.33ms", "10.66ms", "21.32ms", "42.64ms", "85.28ms", 128fcd02e26SMark Brown "170.56ms", "341.12ms", "682.24ms", "1.364s", "2.728s", "5.458s", 129fcd02e26SMark Brown "10.916s", "21.832s", "43.691s" 130fcd02e26SMark Brown }; 131fcd02e26SMark Brown 132ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(alc_hold, 133ca275811STakashi Iwai WM8737_ALC2, 0, alc_hold_text); 134fcd02e26SMark Brown 135fcd02e26SMark Brown static const char *alc_atk_text[] = { 136fcd02e26SMark Brown "8.4ms", "16.8ms", "33.6ms", "67.2ms", "134.4ms", "268.8ms", "537.6ms", 137fcd02e26SMark Brown "1.075s", "2.15s", "4.3s", "8.6s" 138fcd02e26SMark Brown }; 139fcd02e26SMark Brown 140ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(alc_atk, 141ca275811STakashi Iwai WM8737_ALC3, 0, alc_atk_text); 142fcd02e26SMark Brown 143fcd02e26SMark Brown static const char *alc_dcy_text[] = { 144fcd02e26SMark Brown "33.6ms", "67.2ms", "134.4ms", "268.8ms", "537.6ms", "1.075s", "2.15s", 145fcd02e26SMark Brown "4.3s", "8.6s", "17.2s", "34.41s" 146fcd02e26SMark Brown }; 147fcd02e26SMark Brown 148ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(alc_dcy, 149ca275811STakashi Iwai WM8737_ALC3, 4, alc_dcy_text); 150fcd02e26SMark Brown 1512a9ae13aSMark Brown static const struct snd_kcontrol_new wm8737_snd_controls[] = { 1522a9ae13aSMark Brown SOC_DOUBLE_R_TLV("Mic Boost Volume", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R, 1532a9ae13aSMark Brown 6, 3, 0, micboost_tlv), 1542a9ae13aSMark Brown SOC_DOUBLE_R("Mic Boost Switch", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R, 1552a9ae13aSMark Brown 4, 1, 0), 1562a9ae13aSMark Brown SOC_DOUBLE("Mic ZC Switch", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R, 1572a9ae13aSMark Brown 3, 1, 0), 1582a9ae13aSMark Brown 1592a9ae13aSMark Brown SOC_DOUBLE_R_TLV("Capture Volume", WM8737_LEFT_PGA_VOLUME, 1602a9ae13aSMark Brown WM8737_RIGHT_PGA_VOLUME, 0, 255, 0, pga_tlv), 1612a9ae13aSMark Brown SOC_DOUBLE("Capture ZC Switch", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R, 1622a9ae13aSMark Brown 2, 1, 0), 1632a9ae13aSMark Brown 1642a9ae13aSMark Brown SOC_DOUBLE("INPUT1 DC Bias Switch", WM8737_MISC_BIAS_CONTROL, 0, 1, 1, 0), 1652a9ae13aSMark Brown 1662a9ae13aSMark Brown SOC_ENUM("Mic PGA Bias", micbias_enum), 1672a9ae13aSMark Brown SOC_SINGLE("ADC Low Power Switch", WM8737_ADC_CONTROL, 2, 1, 0), 1682a9ae13aSMark Brown SOC_SINGLE("High Pass Filter Switch", WM8737_ADC_CONTROL, 0, 1, 1), 1692a9ae13aSMark Brown SOC_DOUBLE("Polarity Invert Switch", WM8737_ADC_CONTROL, 5, 6, 1, 0), 1702a9ae13aSMark Brown 1712a9ae13aSMark Brown SOC_SINGLE("3D Switch", WM8737_3D_ENHANCE, 0, 1, 0), 1722a9ae13aSMark Brown SOC_SINGLE("3D Depth", WM8737_3D_ENHANCE, 1, 15, 0), 1732a9ae13aSMark Brown SOC_ENUM("3D Low Cut-off", low_3d), 1742a9ae13aSMark Brown SOC_ENUM("3D High Cut-off", low_3d), 1752a9ae13aSMark Brown SOC_SINGLE_TLV("3D ADC Volume", WM8737_3D_ENHANCE, 7, 1, 1, adc_tlv), 1762a9ae13aSMark Brown 1772a9ae13aSMark Brown SOC_SINGLE("Noise Gate Switch", WM8737_NOISE_GATE, 0, 1, 0), 1782a9ae13aSMark Brown SOC_SINGLE_TLV("Noise Gate Threshold Volume", WM8737_NOISE_GATE, 2, 7, 0, 1792a9ae13aSMark Brown ng_tlv), 180fcd02e26SMark Brown 181fcd02e26SMark Brown SOC_ENUM("ALC", alc_fn), 182fcd02e26SMark Brown SOC_SINGLE_TLV("ALC Max Gain Volume", WM8737_ALC1, 4, 7, 0, alc_max_tlv), 183fcd02e26SMark Brown SOC_SINGLE_TLV("ALC Target Volume", WM8737_ALC1, 0, 15, 0, alc_target_tlv), 184fcd02e26SMark Brown SOC_ENUM("ALC Hold Time", alc_hold), 185fcd02e26SMark Brown SOC_SINGLE("ALC ZC Switch", WM8737_ALC2, 4, 1, 0), 186fcd02e26SMark Brown SOC_ENUM("ALC Attack Time", alc_atk), 187fcd02e26SMark Brown SOC_ENUM("ALC Decay Time", alc_dcy), 1882a9ae13aSMark Brown }; 1892a9ae13aSMark Brown 1902a9ae13aSMark Brown static const char *linsel_text[] = { 1912a9ae13aSMark Brown "LINPUT1", "LINPUT2", "LINPUT3", "LINPUT1 DC", 1922a9ae13aSMark Brown }; 1932a9ae13aSMark Brown 194ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(linsel_enum, 195ca275811STakashi Iwai WM8737_AUDIO_PATH_L, 7, linsel_text); 1962a9ae13aSMark Brown 1972a9ae13aSMark Brown static const struct snd_kcontrol_new linsel_mux = 1982a9ae13aSMark Brown SOC_DAPM_ENUM("LINSEL", linsel_enum); 1992a9ae13aSMark Brown 2002a9ae13aSMark Brown 2012a9ae13aSMark Brown static const char *rinsel_text[] = { 2022a9ae13aSMark Brown "RINPUT1", "RINPUT2", "RINPUT3", "RINPUT1 DC", 2032a9ae13aSMark Brown }; 2042a9ae13aSMark Brown 205ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(rinsel_enum, 206ca275811STakashi Iwai WM8737_AUDIO_PATH_R, 7, rinsel_text); 2072a9ae13aSMark Brown 2082a9ae13aSMark Brown static const struct snd_kcontrol_new rinsel_mux = 2092a9ae13aSMark Brown SOC_DAPM_ENUM("RINSEL", rinsel_enum); 2102a9ae13aSMark Brown 2112a9ae13aSMark Brown static const char *bypass_text[] = { 2122a9ae13aSMark Brown "Direct", "Preamp" 2132a9ae13aSMark Brown }; 2142a9ae13aSMark Brown 215ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(lbypass_enum, 216ca275811STakashi Iwai WM8737_MIC_PREAMP_CONTROL, 2, bypass_text); 2172a9ae13aSMark Brown 2182a9ae13aSMark Brown static const struct snd_kcontrol_new lbypass_mux = 2192a9ae13aSMark Brown SOC_DAPM_ENUM("Left Bypass", lbypass_enum); 2202a9ae13aSMark Brown 2212a9ae13aSMark Brown 222ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(rbypass_enum, 223ca275811STakashi Iwai WM8737_MIC_PREAMP_CONTROL, 3, bypass_text); 2242a9ae13aSMark Brown 2252a9ae13aSMark Brown static const struct snd_kcontrol_new rbypass_mux = 2262a9ae13aSMark Brown SOC_DAPM_ENUM("Left Bypass", rbypass_enum); 2272a9ae13aSMark Brown 2282a9ae13aSMark Brown static const struct snd_soc_dapm_widget wm8737_dapm_widgets[] = { 2292a9ae13aSMark Brown SND_SOC_DAPM_INPUT("LINPUT1"), 2302a9ae13aSMark Brown SND_SOC_DAPM_INPUT("LINPUT2"), 2312a9ae13aSMark Brown SND_SOC_DAPM_INPUT("LINPUT3"), 2322a9ae13aSMark Brown SND_SOC_DAPM_INPUT("RINPUT1"), 2332a9ae13aSMark Brown SND_SOC_DAPM_INPUT("RINPUT2"), 2342a9ae13aSMark Brown SND_SOC_DAPM_INPUT("RINPUT3"), 2352a9ae13aSMark Brown SND_SOC_DAPM_INPUT("LACIN"), 2362a9ae13aSMark Brown SND_SOC_DAPM_INPUT("RACIN"), 2372a9ae13aSMark Brown 2382a9ae13aSMark Brown SND_SOC_DAPM_MUX("LINSEL", SND_SOC_NOPM, 0, 0, &linsel_mux), 2392a9ae13aSMark Brown SND_SOC_DAPM_MUX("RINSEL", SND_SOC_NOPM, 0, 0, &rinsel_mux), 2402a9ae13aSMark Brown 2412a9ae13aSMark Brown SND_SOC_DAPM_MUX("Left Preamp Mux", SND_SOC_NOPM, 0, 0, &lbypass_mux), 2422a9ae13aSMark Brown SND_SOC_DAPM_MUX("Right Preamp Mux", SND_SOC_NOPM, 0, 0, &rbypass_mux), 2432a9ae13aSMark Brown 2442a9ae13aSMark Brown SND_SOC_DAPM_PGA("PGAL", WM8737_POWER_MANAGEMENT, 5, 0, NULL, 0), 2452a9ae13aSMark Brown SND_SOC_DAPM_PGA("PGAR", WM8737_POWER_MANAGEMENT, 4, 0, NULL, 0), 2462a9ae13aSMark Brown 2472a9ae13aSMark Brown SND_SOC_DAPM_DAC("ADCL", NULL, WM8737_POWER_MANAGEMENT, 3, 0), 2482a9ae13aSMark Brown SND_SOC_DAPM_DAC("ADCR", NULL, WM8737_POWER_MANAGEMENT, 2, 0), 2492a9ae13aSMark Brown 2502a9ae13aSMark Brown SND_SOC_DAPM_AIF_OUT("AIF", "Capture", 0, WM8737_POWER_MANAGEMENT, 6, 0), 2512a9ae13aSMark Brown }; 2522a9ae13aSMark Brown 2532a9ae13aSMark Brown static const struct snd_soc_dapm_route intercon[] = { 2542a9ae13aSMark Brown { "LINSEL", "LINPUT1", "LINPUT1" }, 2552a9ae13aSMark Brown { "LINSEL", "LINPUT2", "LINPUT2" }, 2562a9ae13aSMark Brown { "LINSEL", "LINPUT3", "LINPUT3" }, 2572a9ae13aSMark Brown { "LINSEL", "LINPUT1 DC", "LINPUT1" }, 2582a9ae13aSMark Brown 2592a9ae13aSMark Brown { "RINSEL", "RINPUT1", "RINPUT1" }, 2602a9ae13aSMark Brown { "RINSEL", "RINPUT2", "RINPUT2" }, 2612a9ae13aSMark Brown { "RINSEL", "RINPUT3", "RINPUT3" }, 2622a9ae13aSMark Brown { "RINSEL", "RINPUT1 DC", "RINPUT1" }, 2632a9ae13aSMark Brown 2642a9ae13aSMark Brown { "Left Preamp Mux", "Preamp", "LINSEL" }, 2652a9ae13aSMark Brown { "Left Preamp Mux", "Direct", "LACIN" }, 2662a9ae13aSMark Brown 2672a9ae13aSMark Brown { "Right Preamp Mux", "Preamp", "RINSEL" }, 2682a9ae13aSMark Brown { "Right Preamp Mux", "Direct", "RACIN" }, 2692a9ae13aSMark Brown 2702a9ae13aSMark Brown { "PGAL", NULL, "Left Preamp Mux" }, 2712a9ae13aSMark Brown { "PGAR", NULL, "Right Preamp Mux" }, 2722a9ae13aSMark Brown 2732a9ae13aSMark Brown { "ADCL", NULL, "PGAL" }, 2742a9ae13aSMark Brown { "ADCR", NULL, "PGAR" }, 2752a9ae13aSMark Brown 2762a9ae13aSMark Brown { "AIF", NULL, "ADCL" }, 2772a9ae13aSMark Brown { "AIF", NULL, "ADCR" }, 2782a9ae13aSMark Brown }; 2792a9ae13aSMark Brown 2802a9ae13aSMark Brown /* codec mclk clock divider coefficients */ 2812a9ae13aSMark Brown static const struct { 2822a9ae13aSMark Brown u32 mclk; 2832a9ae13aSMark Brown u32 rate; 2842a9ae13aSMark Brown u8 usb; 2852a9ae13aSMark Brown u8 sr; 2862a9ae13aSMark Brown } coeff_div[] = { 2872a9ae13aSMark Brown { 12288000, 8000, 0, 0x4 }, 2882a9ae13aSMark Brown { 12288000, 12000, 0, 0x8 }, 2892a9ae13aSMark Brown { 12288000, 16000, 0, 0xa }, 2902a9ae13aSMark Brown { 12288000, 24000, 0, 0x1c }, 2912a9ae13aSMark Brown { 12288000, 32000, 0, 0xc }, 2922a9ae13aSMark Brown { 12288000, 48000, 0, 0 }, 2932a9ae13aSMark Brown { 12288000, 96000, 0, 0xe }, 2942a9ae13aSMark Brown 2952a9ae13aSMark Brown { 11289600, 8000, 0, 0x14 }, 2962a9ae13aSMark Brown { 11289600, 11025, 0, 0x18 }, 2972a9ae13aSMark Brown { 11289600, 22050, 0, 0x1a }, 2982a9ae13aSMark Brown { 11289600, 44100, 0, 0x10 }, 2992a9ae13aSMark Brown { 11289600, 88200, 0, 0x1e }, 3002a9ae13aSMark Brown 3012a9ae13aSMark Brown { 18432000, 8000, 0, 0x5 }, 3022a9ae13aSMark Brown { 18432000, 12000, 0, 0x9 }, 3032a9ae13aSMark Brown { 18432000, 16000, 0, 0xb }, 3042a9ae13aSMark Brown { 18432000, 24000, 0, 0x1b }, 3052a9ae13aSMark Brown { 18432000, 32000, 0, 0xd }, 3062a9ae13aSMark Brown { 18432000, 48000, 0, 0x1 }, 3072a9ae13aSMark Brown { 18432000, 96000, 0, 0x1f }, 3082a9ae13aSMark Brown 3092a9ae13aSMark Brown { 16934400, 8000, 0, 0x15 }, 3102a9ae13aSMark Brown { 16934400, 11025, 0, 0x19 }, 3112a9ae13aSMark Brown { 16934400, 22050, 0, 0x1b }, 3122a9ae13aSMark Brown { 16934400, 44100, 0, 0x11 }, 3132a9ae13aSMark Brown { 16934400, 88200, 0, 0x1f }, 3142a9ae13aSMark Brown 3152a9ae13aSMark Brown { 12000000, 8000, 1, 0x4 }, 3162a9ae13aSMark Brown { 12000000, 11025, 1, 0x19 }, 3172a9ae13aSMark Brown { 12000000, 12000, 1, 0x8 }, 3182a9ae13aSMark Brown { 12000000, 16000, 1, 0xa }, 3192a9ae13aSMark Brown { 12000000, 22050, 1, 0x1b }, 3202a9ae13aSMark Brown { 12000000, 24000, 1, 0x1c }, 3212a9ae13aSMark Brown { 12000000, 32000, 1, 0xc }, 3222a9ae13aSMark Brown { 12000000, 44100, 1, 0x11 }, 3232a9ae13aSMark Brown { 12000000, 48000, 1, 0x0 }, 3242a9ae13aSMark Brown { 12000000, 88200, 1, 0x1f }, 3252a9ae13aSMark Brown { 12000000, 96000, 1, 0xe }, 3262a9ae13aSMark Brown }; 3272a9ae13aSMark Brown 3282a9ae13aSMark Brown static int wm8737_hw_params(struct snd_pcm_substream *substream, 3292a9ae13aSMark Brown struct snd_pcm_hw_params *params, 3302a9ae13aSMark Brown struct snd_soc_dai *dai) 3312a9ae13aSMark Brown { 332e6968a17SMark Brown struct snd_soc_codec *codec = dai->codec; 3332a9ae13aSMark Brown struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); 3342a9ae13aSMark Brown int i; 3352a9ae13aSMark Brown u16 clocking = 0; 3362a9ae13aSMark Brown u16 af = 0; 3372a9ae13aSMark Brown 3382a9ae13aSMark Brown for (i = 0; i < ARRAY_SIZE(coeff_div); i++) { 3392a9ae13aSMark Brown if (coeff_div[i].rate != params_rate(params)) 3402a9ae13aSMark Brown continue; 3412a9ae13aSMark Brown 3422a9ae13aSMark Brown if (coeff_div[i].mclk == wm8737->mclk) 3432a9ae13aSMark Brown break; 3442a9ae13aSMark Brown 3452a9ae13aSMark Brown if (coeff_div[i].mclk == wm8737->mclk * 2) { 3462a9ae13aSMark Brown clocking |= WM8737_CLKDIV2; 3472a9ae13aSMark Brown break; 3482a9ae13aSMark Brown } 3492a9ae13aSMark Brown } 3502a9ae13aSMark Brown 3512a9ae13aSMark Brown if (i == ARRAY_SIZE(coeff_div)) { 3522a9ae13aSMark Brown dev_err(codec->dev, "%dHz MCLK can't support %dHz\n", 3532a9ae13aSMark Brown wm8737->mclk, params_rate(params)); 3542a9ae13aSMark Brown return -EINVAL; 3552a9ae13aSMark Brown } 3562a9ae13aSMark Brown 3572a9ae13aSMark Brown clocking |= coeff_div[i].usb | (coeff_div[i].sr << WM8737_SR_SHIFT); 3582a9ae13aSMark Brown 359a5d0de23SMark Brown switch (params_width(params)) { 360a5d0de23SMark Brown case 16: 3612a9ae13aSMark Brown break; 362a5d0de23SMark Brown case 20: 3632a9ae13aSMark Brown af |= 0x8; 3642a9ae13aSMark Brown break; 365a5d0de23SMark Brown case 24: 3662a9ae13aSMark Brown af |= 0x10; 3672a9ae13aSMark Brown break; 368a5d0de23SMark Brown case 32: 3692a9ae13aSMark Brown af |= 0x18; 3702a9ae13aSMark Brown break; 3712a9ae13aSMark Brown default: 3722a9ae13aSMark Brown return -EINVAL; 3732a9ae13aSMark Brown } 3742a9ae13aSMark Brown 3752a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_AUDIO_FORMAT, WM8737_WL_MASK, af); 3762a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_CLOCKING, 3772a9ae13aSMark Brown WM8737_USB_MODE | WM8737_CLKDIV2 | WM8737_SR_MASK, 3782a9ae13aSMark Brown clocking); 3792a9ae13aSMark Brown 3802a9ae13aSMark Brown return 0; 3812a9ae13aSMark Brown } 3822a9ae13aSMark Brown 3832a9ae13aSMark Brown static int wm8737_set_dai_sysclk(struct snd_soc_dai *codec_dai, 3842a9ae13aSMark Brown int clk_id, unsigned int freq, int dir) 3852a9ae13aSMark Brown { 3862a9ae13aSMark Brown struct snd_soc_codec *codec = codec_dai->codec; 3872a9ae13aSMark Brown struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); 3882a9ae13aSMark Brown int i; 3892a9ae13aSMark Brown 3902a9ae13aSMark Brown for (i = 0; i < ARRAY_SIZE(coeff_div); i++) { 3912a9ae13aSMark Brown if (freq == coeff_div[i].mclk || 3922a9ae13aSMark Brown freq == coeff_div[i].mclk * 2) { 3932a9ae13aSMark Brown wm8737->mclk = freq; 3942a9ae13aSMark Brown return 0; 3952a9ae13aSMark Brown } 3962a9ae13aSMark Brown } 3972a9ae13aSMark Brown 3982a9ae13aSMark Brown dev_err(codec->dev, "MCLK rate %dHz not supported\n", freq); 3992a9ae13aSMark Brown 4002a9ae13aSMark Brown return -EINVAL; 4012a9ae13aSMark Brown } 4022a9ae13aSMark Brown 4032a9ae13aSMark Brown 4042a9ae13aSMark Brown static int wm8737_set_dai_fmt(struct snd_soc_dai *codec_dai, 4052a9ae13aSMark Brown unsigned int fmt) 4062a9ae13aSMark Brown { 4072a9ae13aSMark Brown struct snd_soc_codec *codec = codec_dai->codec; 4082a9ae13aSMark Brown u16 af = 0; 4092a9ae13aSMark Brown 4102a9ae13aSMark Brown switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 4112a9ae13aSMark Brown case SND_SOC_DAIFMT_CBM_CFM: 4122a9ae13aSMark Brown af |= WM8737_MS; 4132a9ae13aSMark Brown break; 4142a9ae13aSMark Brown case SND_SOC_DAIFMT_CBS_CFS: 4152a9ae13aSMark Brown break; 4162a9ae13aSMark Brown default: 4172a9ae13aSMark Brown return -EINVAL; 4182a9ae13aSMark Brown } 4192a9ae13aSMark Brown 4202a9ae13aSMark Brown switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 4212a9ae13aSMark Brown case SND_SOC_DAIFMT_I2S: 4222a9ae13aSMark Brown af |= 0x2; 4232a9ae13aSMark Brown break; 4242a9ae13aSMark Brown case SND_SOC_DAIFMT_RIGHT_J: 4252a9ae13aSMark Brown break; 4262a9ae13aSMark Brown case SND_SOC_DAIFMT_LEFT_J: 4272a9ae13aSMark Brown af |= 0x1; 4282a9ae13aSMark Brown break; 4292a9ae13aSMark Brown case SND_SOC_DAIFMT_DSP_A: 4302a9ae13aSMark Brown af |= 0x3; 4312a9ae13aSMark Brown break; 4322a9ae13aSMark Brown case SND_SOC_DAIFMT_DSP_B: 4332a9ae13aSMark Brown af |= 0x13; 4342a9ae13aSMark Brown break; 4352a9ae13aSMark Brown default: 4362a9ae13aSMark Brown return -EINVAL; 4372a9ae13aSMark Brown } 4382a9ae13aSMark Brown 4392a9ae13aSMark Brown switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 4402a9ae13aSMark Brown case SND_SOC_DAIFMT_NB_NF: 4412a9ae13aSMark Brown break; 4422a9ae13aSMark Brown case SND_SOC_DAIFMT_NB_IF: 4432a9ae13aSMark Brown af |= WM8737_LRP; 4442a9ae13aSMark Brown break; 4452a9ae13aSMark Brown default: 4462a9ae13aSMark Brown return -EINVAL; 4472a9ae13aSMark Brown } 4482a9ae13aSMark Brown 4492a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_AUDIO_FORMAT, 4502a9ae13aSMark Brown WM8737_FORMAT_MASK | WM8737_LRP | WM8737_MS, af); 4512a9ae13aSMark Brown 4522a9ae13aSMark Brown return 0; 4532a9ae13aSMark Brown } 4542a9ae13aSMark Brown 4552a9ae13aSMark Brown static int wm8737_set_bias_level(struct snd_soc_codec *codec, 4562a9ae13aSMark Brown enum snd_soc_bias_level level) 4572a9ae13aSMark Brown { 4582a9ae13aSMark Brown struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); 4592a9ae13aSMark Brown int ret; 4602a9ae13aSMark Brown 4612a9ae13aSMark Brown switch (level) { 4622a9ae13aSMark Brown case SND_SOC_BIAS_ON: 4632a9ae13aSMark Brown break; 4642a9ae13aSMark Brown 4652a9ae13aSMark Brown case SND_SOC_BIAS_PREPARE: 4662a9ae13aSMark Brown /* VMID at 2*75k */ 4672a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL, 4682a9ae13aSMark Brown WM8737_VMIDSEL_MASK, 0); 4692a9ae13aSMark Brown break; 4702a9ae13aSMark Brown 4712a9ae13aSMark Brown case SND_SOC_BIAS_STANDBY: 4722a9ae13aSMark Brown if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 4732a9ae13aSMark Brown ret = regulator_bulk_enable(ARRAY_SIZE(wm8737->supplies), 4742a9ae13aSMark Brown wm8737->supplies); 4752a9ae13aSMark Brown if (ret != 0) { 4762a9ae13aSMark Brown dev_err(codec->dev, 4772a9ae13aSMark Brown "Failed to enable supplies: %d\n", 4782a9ae13aSMark Brown ret); 4792a9ae13aSMark Brown return ret; 4802a9ae13aSMark Brown } 4812a9ae13aSMark Brown 4823ef8ac0dSMark Brown regcache_sync(wm8737->regmap); 4832a9ae13aSMark Brown 4842a9ae13aSMark Brown /* Fast VMID ramp at 2*2.5k */ 4852a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL, 486*14ba3ec1SAxel Lin WM8737_VMIDSEL_MASK, 487*14ba3ec1SAxel Lin 2 << WM8737_VMIDSEL_SHIFT); 4882a9ae13aSMark Brown 4892a9ae13aSMark Brown /* Bring VMID up */ 4902a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_POWER_MANAGEMENT, 4912a9ae13aSMark Brown WM8737_VMID_MASK | 4922a9ae13aSMark Brown WM8737_VREF_MASK, 4932a9ae13aSMark Brown WM8737_VMID_MASK | 4942a9ae13aSMark Brown WM8737_VREF_MASK); 4952a9ae13aSMark Brown 4962a9ae13aSMark Brown msleep(500); 4972a9ae13aSMark Brown } 4982a9ae13aSMark Brown 4992a9ae13aSMark Brown /* VMID at 2*300k */ 5002a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL, 501*14ba3ec1SAxel Lin WM8737_VMIDSEL_MASK, 502*14ba3ec1SAxel Lin 1 << WM8737_VMIDSEL_SHIFT); 5032a9ae13aSMark Brown 5042a9ae13aSMark Brown break; 5052a9ae13aSMark Brown 5062a9ae13aSMark Brown case SND_SOC_BIAS_OFF: 5072a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_POWER_MANAGEMENT, 5082a9ae13aSMark Brown WM8737_VMID_MASK | WM8737_VREF_MASK, 0); 5092a9ae13aSMark Brown 5102a9ae13aSMark Brown regulator_bulk_disable(ARRAY_SIZE(wm8737->supplies), 5112a9ae13aSMark Brown wm8737->supplies); 5122a9ae13aSMark Brown break; 5132a9ae13aSMark Brown } 5142a9ae13aSMark Brown 5152a9ae13aSMark Brown codec->dapm.bias_level = level; 5162a9ae13aSMark Brown return 0; 5172a9ae13aSMark Brown } 5182a9ae13aSMark Brown 5192a9ae13aSMark Brown #define WM8737_RATES SNDRV_PCM_RATE_8000_96000 5202a9ae13aSMark Brown 5212a9ae13aSMark Brown #define WM8737_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 5222a9ae13aSMark Brown SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) 5232a9ae13aSMark Brown 52485e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops wm8737_dai_ops = { 5252a9ae13aSMark Brown .hw_params = wm8737_hw_params, 5262a9ae13aSMark Brown .set_sysclk = wm8737_set_dai_sysclk, 5272a9ae13aSMark Brown .set_fmt = wm8737_set_dai_fmt, 5282a9ae13aSMark Brown }; 5292a9ae13aSMark Brown 5302a9ae13aSMark Brown static struct snd_soc_dai_driver wm8737_dai = { 5312a9ae13aSMark Brown .name = "wm8737", 5322a9ae13aSMark Brown .capture = { 5332a9ae13aSMark Brown .stream_name = "Capture", 5342a9ae13aSMark Brown .channels_min = 2, /* Mono modes not yet supported */ 5352a9ae13aSMark Brown .channels_max = 2, 5362a9ae13aSMark Brown .rates = WM8737_RATES, 5372a9ae13aSMark Brown .formats = WM8737_FORMATS, 5382a9ae13aSMark Brown }, 5392a9ae13aSMark Brown .ops = &wm8737_dai_ops, 5402a9ae13aSMark Brown }; 5412a9ae13aSMark Brown 5422a9ae13aSMark Brown static int wm8737_probe(struct snd_soc_codec *codec) 5432a9ae13aSMark Brown { 5442a9ae13aSMark Brown struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); 5454f69bb31SMark Brown int ret; 5462a9ae13aSMark Brown 5472a9ae13aSMark Brown ret = regulator_bulk_enable(ARRAY_SIZE(wm8737->supplies), 5482a9ae13aSMark Brown wm8737->supplies); 5492a9ae13aSMark Brown if (ret != 0) { 5502a9ae13aSMark Brown dev_err(codec->dev, "Failed to enable supplies: %d\n", ret); 5512a9ae13aSMark Brown goto err_get; 5522a9ae13aSMark Brown } 5532a9ae13aSMark Brown 5542a9ae13aSMark Brown ret = wm8737_reset(codec); 5552a9ae13aSMark Brown if (ret < 0) { 5562a9ae13aSMark Brown dev_err(codec->dev, "Failed to issue reset\n"); 5572a9ae13aSMark Brown goto err_enable; 5582a9ae13aSMark Brown } 5592a9ae13aSMark Brown 5602a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_LEFT_PGA_VOLUME, WM8737_LVU, 5612a9ae13aSMark Brown WM8737_LVU); 5622a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_RIGHT_PGA_VOLUME, WM8737_RVU, 5632a9ae13aSMark Brown WM8737_RVU); 5642a9ae13aSMark Brown 5652a9ae13aSMark Brown wm8737_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 5662a9ae13aSMark Brown 5672a9ae13aSMark Brown /* Bias level configuration will have done an extra enable */ 5682a9ae13aSMark Brown regulator_bulk_disable(ARRAY_SIZE(wm8737->supplies), wm8737->supplies); 5692a9ae13aSMark Brown 5702a9ae13aSMark Brown return 0; 5712a9ae13aSMark Brown 5722a9ae13aSMark Brown err_enable: 5732a9ae13aSMark Brown regulator_bulk_disable(ARRAY_SIZE(wm8737->supplies), wm8737->supplies); 5742a9ae13aSMark Brown err_get: 5752a9ae13aSMark Brown return ret; 5762a9ae13aSMark Brown } 5772a9ae13aSMark Brown 5782a9ae13aSMark Brown static struct snd_soc_codec_driver soc_codec_dev_wm8737 = { 5792a9ae13aSMark Brown .probe = wm8737_probe, 5802a9ae13aSMark Brown .set_bias_level = wm8737_set_bias_level, 58167cac3a3SLars-Peter Clausen .suspend_bias_off = true, 582a6bf3069SLars-Peter Clausen 583a6bf3069SLars-Peter Clausen .controls = wm8737_snd_controls, 584a6bf3069SLars-Peter Clausen .num_controls = ARRAY_SIZE(wm8737_snd_controls), 585a6bf3069SLars-Peter Clausen .dapm_widgets = wm8737_dapm_widgets, 586a6bf3069SLars-Peter Clausen .num_dapm_widgets = ARRAY_SIZE(wm8737_dapm_widgets), 587a6bf3069SLars-Peter Clausen .dapm_routes = intercon, 588a6bf3069SLars-Peter Clausen .num_dapm_routes = ARRAY_SIZE(intercon), 5892a9ae13aSMark Brown }; 5902a9ae13aSMark Brown 59153a5a83dSMark Brown static const struct of_device_id wm8737_of_match[] = { 59253a5a83dSMark Brown { .compatible = "wlf,wm8737", }, 59353a5a83dSMark Brown { } 59453a5a83dSMark Brown }; 59553a5a83dSMark Brown 59653a5a83dSMark Brown MODULE_DEVICE_TABLE(of, wm8737_of_match); 59753a5a83dSMark Brown 5983ef8ac0dSMark Brown static const struct regmap_config wm8737_regmap = { 5993ef8ac0dSMark Brown .reg_bits = 7, 6003ef8ac0dSMark Brown .val_bits = 9, 6013ef8ac0dSMark Brown .max_register = WM8737_MAX_REGISTER, 6023ef8ac0dSMark Brown 6033ef8ac0dSMark Brown .reg_defaults = wm8737_reg_defaults, 6043ef8ac0dSMark Brown .num_reg_defaults = ARRAY_SIZE(wm8737_reg_defaults), 6053ef8ac0dSMark Brown .cache_type = REGCACHE_RBTREE, 6063ef8ac0dSMark Brown 6073ef8ac0dSMark Brown .volatile_reg = wm8737_volatile, 6083ef8ac0dSMark Brown }; 6093ef8ac0dSMark Brown 6101037d567SFabio Estevam #if IS_ENABLED(CONFIG_I2C) 6117a79e94eSBill Pemberton static int wm8737_i2c_probe(struct i2c_client *i2c, 6122a9ae13aSMark Brown const struct i2c_device_id *id) 6132a9ae13aSMark Brown { 6142a9ae13aSMark Brown struct wm8737_priv *wm8737; 6154f69bb31SMark Brown int ret, i; 6162a9ae13aSMark Brown 61765fdd9bfSMark Brown wm8737 = devm_kzalloc(&i2c->dev, sizeof(struct wm8737_priv), 61865fdd9bfSMark Brown GFP_KERNEL); 6192a9ae13aSMark Brown if (wm8737 == NULL) 6202a9ae13aSMark Brown return -ENOMEM; 6212a9ae13aSMark Brown 6224f69bb31SMark Brown for (i = 0; i < ARRAY_SIZE(wm8737->supplies); i++) 6234f69bb31SMark Brown wm8737->supplies[i].supply = wm8737_supply_names[i]; 6244f69bb31SMark Brown 6254f69bb31SMark Brown ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8737->supplies), 6264f69bb31SMark Brown wm8737->supplies); 6274f69bb31SMark Brown if (ret != 0) { 6284f69bb31SMark Brown dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); 6294f69bb31SMark Brown return ret; 6304f69bb31SMark Brown } 6314f69bb31SMark Brown 6323ef8ac0dSMark Brown wm8737->regmap = devm_regmap_init_i2c(i2c, &wm8737_regmap); 6333ef8ac0dSMark Brown if (IS_ERR(wm8737->regmap)) 6343ef8ac0dSMark Brown return PTR_ERR(wm8737->regmap); 6353ef8ac0dSMark Brown 6362a9ae13aSMark Brown i2c_set_clientdata(i2c, wm8737); 6372a9ae13aSMark Brown 6382a9ae13aSMark Brown ret = snd_soc_register_codec(&i2c->dev, 6392a9ae13aSMark Brown &soc_codec_dev_wm8737, &wm8737_dai, 1); 64065fdd9bfSMark Brown 6412a9ae13aSMark Brown return ret; 6422a9ae13aSMark Brown 6432a9ae13aSMark Brown } 6442a9ae13aSMark Brown 6457a79e94eSBill Pemberton static int wm8737_i2c_remove(struct i2c_client *client) 6462a9ae13aSMark Brown { 6472a9ae13aSMark Brown snd_soc_unregister_codec(&client->dev); 64865fdd9bfSMark Brown 6492a9ae13aSMark Brown return 0; 6502a9ae13aSMark Brown } 6512a9ae13aSMark Brown 6522a9ae13aSMark Brown static const struct i2c_device_id wm8737_i2c_id[] = { 6532a9ae13aSMark Brown { "wm8737", 0 }, 6542a9ae13aSMark Brown { } 6552a9ae13aSMark Brown }; 6562a9ae13aSMark Brown MODULE_DEVICE_TABLE(i2c, wm8737_i2c_id); 6572a9ae13aSMark Brown 6582a9ae13aSMark Brown static struct i2c_driver wm8737_i2c_driver = { 6592a9ae13aSMark Brown .driver = { 6602a9ae13aSMark Brown .name = "wm8737", 6612a9ae13aSMark Brown .owner = THIS_MODULE, 66253a5a83dSMark Brown .of_match_table = wm8737_of_match, 6632a9ae13aSMark Brown }, 6642a9ae13aSMark Brown .probe = wm8737_i2c_probe, 6657a79e94eSBill Pemberton .remove = wm8737_i2c_remove, 6662a9ae13aSMark Brown .id_table = wm8737_i2c_id, 6672a9ae13aSMark Brown }; 6682a9ae13aSMark Brown #endif 6692a9ae13aSMark Brown 6702a9ae13aSMark Brown #if defined(CONFIG_SPI_MASTER) 6717a79e94eSBill Pemberton static int wm8737_spi_probe(struct spi_device *spi) 6722a9ae13aSMark Brown { 6732a9ae13aSMark Brown struct wm8737_priv *wm8737; 6744f69bb31SMark Brown int ret, i; 6752a9ae13aSMark Brown 67665fdd9bfSMark Brown wm8737 = devm_kzalloc(&spi->dev, sizeof(struct wm8737_priv), 67765fdd9bfSMark Brown GFP_KERNEL); 6782a9ae13aSMark Brown if (wm8737 == NULL) 6792a9ae13aSMark Brown return -ENOMEM; 6802a9ae13aSMark Brown 6814f69bb31SMark Brown for (i = 0; i < ARRAY_SIZE(wm8737->supplies); i++) 6824f69bb31SMark Brown wm8737->supplies[i].supply = wm8737_supply_names[i]; 6834f69bb31SMark Brown 6844f69bb31SMark Brown ret = devm_regulator_bulk_get(&spi->dev, ARRAY_SIZE(wm8737->supplies), 6854f69bb31SMark Brown wm8737->supplies); 6864f69bb31SMark Brown if (ret != 0) { 6874f69bb31SMark Brown dev_err(&spi->dev, "Failed to request supplies: %d\n", ret); 6884f69bb31SMark Brown return ret; 6894f69bb31SMark Brown } 6904f69bb31SMark Brown 6913ef8ac0dSMark Brown wm8737->regmap = devm_regmap_init_spi(spi, &wm8737_regmap); 6923ef8ac0dSMark Brown if (IS_ERR(wm8737->regmap)) 6933ef8ac0dSMark Brown return PTR_ERR(wm8737->regmap); 6943ef8ac0dSMark Brown 6952a9ae13aSMark Brown spi_set_drvdata(spi, wm8737); 6962a9ae13aSMark Brown 6972a9ae13aSMark Brown ret = snd_soc_register_codec(&spi->dev, 6982a9ae13aSMark Brown &soc_codec_dev_wm8737, &wm8737_dai, 1); 69965fdd9bfSMark Brown 7002a9ae13aSMark Brown return ret; 7012a9ae13aSMark Brown } 7022a9ae13aSMark Brown 7037a79e94eSBill Pemberton static int wm8737_spi_remove(struct spi_device *spi) 7042a9ae13aSMark Brown { 7052a9ae13aSMark Brown snd_soc_unregister_codec(&spi->dev); 70665fdd9bfSMark Brown 7072a9ae13aSMark Brown return 0; 7082a9ae13aSMark Brown } 7092a9ae13aSMark Brown 7102a9ae13aSMark Brown static struct spi_driver wm8737_spi_driver = { 7112a9ae13aSMark Brown .driver = { 7122a9ae13aSMark Brown .name = "wm8737", 7132a9ae13aSMark Brown .owner = THIS_MODULE, 71453a5a83dSMark Brown .of_match_table = wm8737_of_match, 7152a9ae13aSMark Brown }, 7162a9ae13aSMark Brown .probe = wm8737_spi_probe, 7177a79e94eSBill Pemberton .remove = wm8737_spi_remove, 7182a9ae13aSMark Brown }; 7192a9ae13aSMark Brown #endif /* CONFIG_SPI_MASTER */ 7202a9ae13aSMark Brown 7212a9ae13aSMark Brown static int __init wm8737_modinit(void) 7222a9ae13aSMark Brown { 7232a9ae13aSMark Brown int ret; 7241037d567SFabio Estevam #if IS_ENABLED(CONFIG_I2C) 7252a9ae13aSMark Brown ret = i2c_add_driver(&wm8737_i2c_driver); 7262a9ae13aSMark Brown if (ret != 0) { 7272a9ae13aSMark Brown printk(KERN_ERR "Failed to register WM8737 I2C driver: %d\n", 7282a9ae13aSMark Brown ret); 7292a9ae13aSMark Brown } 7302a9ae13aSMark Brown #endif 7312a9ae13aSMark Brown #if defined(CONFIG_SPI_MASTER) 7322a9ae13aSMark Brown ret = spi_register_driver(&wm8737_spi_driver); 7332a9ae13aSMark Brown if (ret != 0) { 7342a9ae13aSMark Brown printk(KERN_ERR "Failed to register WM8737 SPI driver: %d\n", 7352a9ae13aSMark Brown ret); 7362a9ae13aSMark Brown } 7372a9ae13aSMark Brown #endif 7382a9ae13aSMark Brown return 0; 7392a9ae13aSMark Brown } 7402a9ae13aSMark Brown module_init(wm8737_modinit); 7412a9ae13aSMark Brown 7422a9ae13aSMark Brown static void __exit wm8737_exit(void) 7432a9ae13aSMark Brown { 7442a9ae13aSMark Brown #if defined(CONFIG_SPI_MASTER) 7452a9ae13aSMark Brown spi_unregister_driver(&wm8737_spi_driver); 7462a9ae13aSMark Brown #endif 7471037d567SFabio Estevam #if IS_ENABLED(CONFIG_I2C) 7482a9ae13aSMark Brown i2c_del_driver(&wm8737_i2c_driver); 7492a9ae13aSMark Brown #endif 7502a9ae13aSMark Brown } 7512a9ae13aSMark Brown module_exit(wm8737_exit); 7522a9ae13aSMark Brown 7532a9ae13aSMark Brown MODULE_DESCRIPTION("ASoC WM8737 driver"); 7542a9ae13aSMark Brown MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 7552a9ae13aSMark Brown MODULE_LICENSE("GPL"); 756