1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 22a9ae13aSMark Brown /* 32a9ae13aSMark Brown * wm8737.c -- WM8737 ALSA SoC Audio driver 42a9ae13aSMark Brown * 52a9ae13aSMark Brown * Copyright 2010 Wolfson Microelectronics plc 62a9ae13aSMark Brown * 72a9ae13aSMark Brown * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> 82a9ae13aSMark Brown */ 92a9ae13aSMark Brown 102a9ae13aSMark Brown #include <linux/module.h> 112a9ae13aSMark Brown #include <linux/moduleparam.h> 122a9ae13aSMark Brown #include <linux/init.h> 132a9ae13aSMark Brown #include <linux/delay.h> 142a9ae13aSMark Brown #include <linux/pm.h> 152a9ae13aSMark Brown #include <linux/i2c.h> 163ef8ac0dSMark Brown #include <linux/regmap.h> 172a9ae13aSMark Brown #include <linux/regulator/consumer.h> 182a9ae13aSMark Brown #include <linux/spi/spi.h> 192a9ae13aSMark Brown #include <linux/slab.h> 2053a5a83dSMark Brown #include <linux/of_device.h> 212a9ae13aSMark Brown #include <sound/core.h> 222a9ae13aSMark Brown #include <sound/pcm.h> 232a9ae13aSMark Brown #include <sound/pcm_params.h> 242a9ae13aSMark Brown #include <sound/soc.h> 252a9ae13aSMark Brown #include <sound/soc-dapm.h> 262a9ae13aSMark Brown #include <sound/initval.h> 272a9ae13aSMark Brown #include <sound/tlv.h> 282a9ae13aSMark Brown 292a9ae13aSMark Brown #include "wm8737.h" 302a9ae13aSMark Brown 312a9ae13aSMark Brown #define WM8737_NUM_SUPPLIES 4 322a9ae13aSMark Brown static const char *wm8737_supply_names[WM8737_NUM_SUPPLIES] = { 332a9ae13aSMark Brown "DCVDD", 342a9ae13aSMark Brown "DBVDD", 352a9ae13aSMark Brown "AVDD", 362a9ae13aSMark Brown "MVDD", 372a9ae13aSMark Brown }; 382a9ae13aSMark Brown 392a9ae13aSMark Brown /* codec private data */ 402a9ae13aSMark Brown struct wm8737_priv { 413ef8ac0dSMark Brown struct regmap *regmap; 422a9ae13aSMark Brown struct regulator_bulk_data supplies[WM8737_NUM_SUPPLIES]; 432a9ae13aSMark Brown unsigned int mclk; 442a9ae13aSMark Brown }; 452a9ae13aSMark Brown 463ef8ac0dSMark Brown static const struct reg_default wm8737_reg_defaults[] = { 473ef8ac0dSMark Brown { 0, 0x00C3 }, /* R0 - Left PGA volume */ 483ef8ac0dSMark Brown { 1, 0x00C3 }, /* R1 - Right PGA volume */ 493ef8ac0dSMark Brown { 2, 0x0007 }, /* R2 - AUDIO path L */ 503ef8ac0dSMark Brown { 3, 0x0007 }, /* R3 - AUDIO path R */ 513ef8ac0dSMark Brown { 4, 0x0000 }, /* R4 - 3D Enhance */ 523ef8ac0dSMark Brown { 5, 0x0000 }, /* R5 - ADC Control */ 533ef8ac0dSMark Brown { 6, 0x0000 }, /* R6 - Power Management */ 543ef8ac0dSMark Brown { 7, 0x000A }, /* R7 - Audio Format */ 553ef8ac0dSMark Brown { 8, 0x0000 }, /* R8 - Clocking */ 563ef8ac0dSMark Brown { 9, 0x000F }, /* R9 - MIC Preamp Control */ 573ef8ac0dSMark Brown { 10, 0x0003 }, /* R10 - Misc Bias Control */ 583ef8ac0dSMark Brown { 11, 0x0000 }, /* R11 - Noise Gate */ 593ef8ac0dSMark Brown { 12, 0x007C }, /* R12 - ALC1 */ 603ef8ac0dSMark Brown { 13, 0x0000 }, /* R13 - ALC2 */ 613ef8ac0dSMark Brown { 14, 0x0032 }, /* R14 - ALC3 */ 622a9ae13aSMark Brown }; 632a9ae13aSMark Brown 643ef8ac0dSMark Brown static bool wm8737_volatile(struct device *dev, unsigned int reg) 653ef8ac0dSMark Brown { 663ef8ac0dSMark Brown switch (reg) { 673ef8ac0dSMark Brown case WM8737_RESET: 683ef8ac0dSMark Brown return true; 693ef8ac0dSMark Brown default: 703ef8ac0dSMark Brown return false; 713ef8ac0dSMark Brown } 723ef8ac0dSMark Brown } 733ef8ac0dSMark Brown 74840680dcSKuninori Morimoto static int wm8737_reset(struct snd_soc_component *component) 752a9ae13aSMark Brown { 76840680dcSKuninori Morimoto return snd_soc_component_write(component, WM8737_RESET, 0); 772a9ae13aSMark Brown } 782a9ae13aSMark Brown 797d711f63SLars-Peter Clausen static const DECLARE_TLV_DB_RANGE(micboost_tlv, 802a9ae13aSMark Brown 0, 0, TLV_DB_SCALE_ITEM(1300, 0, 0), 812a9ae13aSMark Brown 1, 1, TLV_DB_SCALE_ITEM(1800, 0, 0), 822a9ae13aSMark Brown 2, 2, TLV_DB_SCALE_ITEM(2800, 0, 0), 837d711f63SLars-Peter Clausen 3, 3, TLV_DB_SCALE_ITEM(3300, 0, 0) 847d711f63SLars-Peter Clausen ); 852a9ae13aSMark Brown static const DECLARE_TLV_DB_SCALE(pga_tlv, -9750, 50, 1); 862a9ae13aSMark Brown static const DECLARE_TLV_DB_SCALE(adc_tlv, -600, 600, 0); 872a9ae13aSMark Brown static const DECLARE_TLV_DB_SCALE(ng_tlv, -7800, 600, 0); 88fcd02e26SMark Brown static const DECLARE_TLV_DB_SCALE(alc_max_tlv, -1200, 600, 0); 89fcd02e26SMark Brown static const DECLARE_TLV_DB_SCALE(alc_target_tlv, -1800, 100, 0); 902a9ae13aSMark Brown 912a9ae13aSMark Brown static const char *micbias_enum_text[] = { 922a9ae13aSMark Brown "25%", 932a9ae13aSMark Brown "50%", 942a9ae13aSMark Brown "75%", 952a9ae13aSMark Brown "100%", 962a9ae13aSMark Brown }; 972a9ae13aSMark Brown 98ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(micbias_enum, 99ca275811STakashi Iwai WM8737_MIC_PREAMP_CONTROL, 0, micbias_enum_text); 1002a9ae13aSMark Brown 1012a9ae13aSMark Brown static const char *low_cutoff_text[] = { 1022a9ae13aSMark Brown "Low", "High" 1032a9ae13aSMark Brown }; 1042a9ae13aSMark Brown 105ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(low_3d, 106ca275811STakashi Iwai WM8737_3D_ENHANCE, 6, low_cutoff_text); 1072a9ae13aSMark Brown 1082a9ae13aSMark Brown static const char *high_cutoff_text[] = { 1092a9ae13aSMark Brown "High", "Low" 1102a9ae13aSMark Brown }; 1112a9ae13aSMark Brown 112ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(high_3d, 113ca275811STakashi Iwai WM8737_3D_ENHANCE, 5, high_cutoff_text); 1142a9ae13aSMark Brown 115fcd02e26SMark Brown static const char *alc_fn_text[] = { 116fcd02e26SMark Brown "Disabled", "Right", "Left", "Stereo" 117fcd02e26SMark Brown }; 118fcd02e26SMark Brown 119ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(alc_fn, 120ca275811STakashi Iwai WM8737_ALC1, 7, alc_fn_text); 121fcd02e26SMark Brown 122fcd02e26SMark Brown static const char *alc_hold_text[] = { 123fcd02e26SMark Brown "0", "2.67ms", "5.33ms", "10.66ms", "21.32ms", "42.64ms", "85.28ms", 124fcd02e26SMark Brown "170.56ms", "341.12ms", "682.24ms", "1.364s", "2.728s", "5.458s", 125fcd02e26SMark Brown "10.916s", "21.832s", "43.691s" 126fcd02e26SMark Brown }; 127fcd02e26SMark Brown 128ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(alc_hold, 129ca275811STakashi Iwai WM8737_ALC2, 0, alc_hold_text); 130fcd02e26SMark Brown 131fcd02e26SMark Brown static const char *alc_atk_text[] = { 132fcd02e26SMark Brown "8.4ms", "16.8ms", "33.6ms", "67.2ms", "134.4ms", "268.8ms", "537.6ms", 133fcd02e26SMark Brown "1.075s", "2.15s", "4.3s", "8.6s" 134fcd02e26SMark Brown }; 135fcd02e26SMark Brown 136ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(alc_atk, 137ca275811STakashi Iwai WM8737_ALC3, 0, alc_atk_text); 138fcd02e26SMark Brown 139fcd02e26SMark Brown static const char *alc_dcy_text[] = { 140fcd02e26SMark Brown "33.6ms", "67.2ms", "134.4ms", "268.8ms", "537.6ms", "1.075s", "2.15s", 141fcd02e26SMark Brown "4.3s", "8.6s", "17.2s", "34.41s" 142fcd02e26SMark Brown }; 143fcd02e26SMark Brown 144ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(alc_dcy, 145ca275811STakashi Iwai WM8737_ALC3, 4, alc_dcy_text); 146fcd02e26SMark Brown 1472a9ae13aSMark Brown static const struct snd_kcontrol_new wm8737_snd_controls[] = { 1482a9ae13aSMark Brown SOC_DOUBLE_R_TLV("Mic Boost Volume", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R, 1492a9ae13aSMark Brown 6, 3, 0, micboost_tlv), 1502a9ae13aSMark Brown SOC_DOUBLE_R("Mic Boost Switch", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R, 1512a9ae13aSMark Brown 4, 1, 0), 1522a9ae13aSMark Brown SOC_DOUBLE("Mic ZC Switch", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R, 1532a9ae13aSMark Brown 3, 1, 0), 1542a9ae13aSMark Brown 1552a9ae13aSMark Brown SOC_DOUBLE_R_TLV("Capture Volume", WM8737_LEFT_PGA_VOLUME, 1562a9ae13aSMark Brown WM8737_RIGHT_PGA_VOLUME, 0, 255, 0, pga_tlv), 1572a9ae13aSMark Brown SOC_DOUBLE("Capture ZC Switch", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R, 1582a9ae13aSMark Brown 2, 1, 0), 1592a9ae13aSMark Brown 1602a9ae13aSMark Brown SOC_DOUBLE("INPUT1 DC Bias Switch", WM8737_MISC_BIAS_CONTROL, 0, 1, 1, 0), 1612a9ae13aSMark Brown 1622a9ae13aSMark Brown SOC_ENUM("Mic PGA Bias", micbias_enum), 1632a9ae13aSMark Brown SOC_SINGLE("ADC Low Power Switch", WM8737_ADC_CONTROL, 2, 1, 0), 1642a9ae13aSMark Brown SOC_SINGLE("High Pass Filter Switch", WM8737_ADC_CONTROL, 0, 1, 1), 1652a9ae13aSMark Brown SOC_DOUBLE("Polarity Invert Switch", WM8737_ADC_CONTROL, 5, 6, 1, 0), 1662a9ae13aSMark Brown 1672a9ae13aSMark Brown SOC_SINGLE("3D Switch", WM8737_3D_ENHANCE, 0, 1, 0), 1682a9ae13aSMark Brown SOC_SINGLE("3D Depth", WM8737_3D_ENHANCE, 1, 15, 0), 1692a9ae13aSMark Brown SOC_ENUM("3D Low Cut-off", low_3d), 170*554b75bdSYueHaibing SOC_ENUM("3D High Cut-off", high_3d), 1712a9ae13aSMark Brown SOC_SINGLE_TLV("3D ADC Volume", WM8737_3D_ENHANCE, 7, 1, 1, adc_tlv), 1722a9ae13aSMark Brown 1732a9ae13aSMark Brown SOC_SINGLE("Noise Gate Switch", WM8737_NOISE_GATE, 0, 1, 0), 1742a9ae13aSMark Brown SOC_SINGLE_TLV("Noise Gate Threshold Volume", WM8737_NOISE_GATE, 2, 7, 0, 1752a9ae13aSMark Brown ng_tlv), 176fcd02e26SMark Brown 177fcd02e26SMark Brown SOC_ENUM("ALC", alc_fn), 178fcd02e26SMark Brown SOC_SINGLE_TLV("ALC Max Gain Volume", WM8737_ALC1, 4, 7, 0, alc_max_tlv), 179fcd02e26SMark Brown SOC_SINGLE_TLV("ALC Target Volume", WM8737_ALC1, 0, 15, 0, alc_target_tlv), 180fcd02e26SMark Brown SOC_ENUM("ALC Hold Time", alc_hold), 181fcd02e26SMark Brown SOC_SINGLE("ALC ZC Switch", WM8737_ALC2, 4, 1, 0), 182fcd02e26SMark Brown SOC_ENUM("ALC Attack Time", alc_atk), 183fcd02e26SMark Brown SOC_ENUM("ALC Decay Time", alc_dcy), 1842a9ae13aSMark Brown }; 1852a9ae13aSMark Brown 1862a9ae13aSMark Brown static const char *linsel_text[] = { 1872a9ae13aSMark Brown "LINPUT1", "LINPUT2", "LINPUT3", "LINPUT1 DC", 1882a9ae13aSMark Brown }; 1892a9ae13aSMark Brown 190ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(linsel_enum, 191ca275811STakashi Iwai WM8737_AUDIO_PATH_L, 7, linsel_text); 1922a9ae13aSMark Brown 1932a9ae13aSMark Brown static const struct snd_kcontrol_new linsel_mux = 1942a9ae13aSMark Brown SOC_DAPM_ENUM("LINSEL", linsel_enum); 1952a9ae13aSMark Brown 1962a9ae13aSMark Brown 1972a9ae13aSMark Brown static const char *rinsel_text[] = { 1982a9ae13aSMark Brown "RINPUT1", "RINPUT2", "RINPUT3", "RINPUT1 DC", 1992a9ae13aSMark Brown }; 2002a9ae13aSMark Brown 201ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(rinsel_enum, 202ca275811STakashi Iwai WM8737_AUDIO_PATH_R, 7, rinsel_text); 2032a9ae13aSMark Brown 2042a9ae13aSMark Brown static const struct snd_kcontrol_new rinsel_mux = 2052a9ae13aSMark Brown SOC_DAPM_ENUM("RINSEL", rinsel_enum); 2062a9ae13aSMark Brown 2072a9ae13aSMark Brown static const char *bypass_text[] = { 2082a9ae13aSMark Brown "Direct", "Preamp" 2092a9ae13aSMark Brown }; 2102a9ae13aSMark Brown 211ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(lbypass_enum, 212ca275811STakashi Iwai WM8737_MIC_PREAMP_CONTROL, 2, bypass_text); 2132a9ae13aSMark Brown 2142a9ae13aSMark Brown static const struct snd_kcontrol_new lbypass_mux = 2152a9ae13aSMark Brown SOC_DAPM_ENUM("Left Bypass", lbypass_enum); 2162a9ae13aSMark Brown 2172a9ae13aSMark Brown 218ca275811STakashi Iwai static SOC_ENUM_SINGLE_DECL(rbypass_enum, 219ca275811STakashi Iwai WM8737_MIC_PREAMP_CONTROL, 3, bypass_text); 2202a9ae13aSMark Brown 2212a9ae13aSMark Brown static const struct snd_kcontrol_new rbypass_mux = 2222a9ae13aSMark Brown SOC_DAPM_ENUM("Left Bypass", rbypass_enum); 2232a9ae13aSMark Brown 2242a9ae13aSMark Brown static const struct snd_soc_dapm_widget wm8737_dapm_widgets[] = { 2252a9ae13aSMark Brown SND_SOC_DAPM_INPUT("LINPUT1"), 2262a9ae13aSMark Brown SND_SOC_DAPM_INPUT("LINPUT2"), 2272a9ae13aSMark Brown SND_SOC_DAPM_INPUT("LINPUT3"), 2282a9ae13aSMark Brown SND_SOC_DAPM_INPUT("RINPUT1"), 2292a9ae13aSMark Brown SND_SOC_DAPM_INPUT("RINPUT2"), 2302a9ae13aSMark Brown SND_SOC_DAPM_INPUT("RINPUT3"), 2312a9ae13aSMark Brown SND_SOC_DAPM_INPUT("LACIN"), 2322a9ae13aSMark Brown SND_SOC_DAPM_INPUT("RACIN"), 2332a9ae13aSMark Brown 2342a9ae13aSMark Brown SND_SOC_DAPM_MUX("LINSEL", SND_SOC_NOPM, 0, 0, &linsel_mux), 2352a9ae13aSMark Brown SND_SOC_DAPM_MUX("RINSEL", SND_SOC_NOPM, 0, 0, &rinsel_mux), 2362a9ae13aSMark Brown 2372a9ae13aSMark Brown SND_SOC_DAPM_MUX("Left Preamp Mux", SND_SOC_NOPM, 0, 0, &lbypass_mux), 2382a9ae13aSMark Brown SND_SOC_DAPM_MUX("Right Preamp Mux", SND_SOC_NOPM, 0, 0, &rbypass_mux), 2392a9ae13aSMark Brown 2402a9ae13aSMark Brown SND_SOC_DAPM_PGA("PGAL", WM8737_POWER_MANAGEMENT, 5, 0, NULL, 0), 2412a9ae13aSMark Brown SND_SOC_DAPM_PGA("PGAR", WM8737_POWER_MANAGEMENT, 4, 0, NULL, 0), 2422a9ae13aSMark Brown 2432a9ae13aSMark Brown SND_SOC_DAPM_DAC("ADCL", NULL, WM8737_POWER_MANAGEMENT, 3, 0), 2442a9ae13aSMark Brown SND_SOC_DAPM_DAC("ADCR", NULL, WM8737_POWER_MANAGEMENT, 2, 0), 2452a9ae13aSMark Brown 2462a9ae13aSMark Brown SND_SOC_DAPM_AIF_OUT("AIF", "Capture", 0, WM8737_POWER_MANAGEMENT, 6, 0), 2472a9ae13aSMark Brown }; 2482a9ae13aSMark Brown 2492a9ae13aSMark Brown static const struct snd_soc_dapm_route intercon[] = { 2502a9ae13aSMark Brown { "LINSEL", "LINPUT1", "LINPUT1" }, 2512a9ae13aSMark Brown { "LINSEL", "LINPUT2", "LINPUT2" }, 2522a9ae13aSMark Brown { "LINSEL", "LINPUT3", "LINPUT3" }, 2532a9ae13aSMark Brown { "LINSEL", "LINPUT1 DC", "LINPUT1" }, 2542a9ae13aSMark Brown 2552a9ae13aSMark Brown { "RINSEL", "RINPUT1", "RINPUT1" }, 2562a9ae13aSMark Brown { "RINSEL", "RINPUT2", "RINPUT2" }, 2572a9ae13aSMark Brown { "RINSEL", "RINPUT3", "RINPUT3" }, 2582a9ae13aSMark Brown { "RINSEL", "RINPUT1 DC", "RINPUT1" }, 2592a9ae13aSMark Brown 2602a9ae13aSMark Brown { "Left Preamp Mux", "Preamp", "LINSEL" }, 2612a9ae13aSMark Brown { "Left Preamp Mux", "Direct", "LACIN" }, 2622a9ae13aSMark Brown 2632a9ae13aSMark Brown { "Right Preamp Mux", "Preamp", "RINSEL" }, 2642a9ae13aSMark Brown { "Right Preamp Mux", "Direct", "RACIN" }, 2652a9ae13aSMark Brown 2662a9ae13aSMark Brown { "PGAL", NULL, "Left Preamp Mux" }, 2672a9ae13aSMark Brown { "PGAR", NULL, "Right Preamp Mux" }, 2682a9ae13aSMark Brown 2692a9ae13aSMark Brown { "ADCL", NULL, "PGAL" }, 2702a9ae13aSMark Brown { "ADCR", NULL, "PGAR" }, 2712a9ae13aSMark Brown 2722a9ae13aSMark Brown { "AIF", NULL, "ADCL" }, 2732a9ae13aSMark Brown { "AIF", NULL, "ADCR" }, 2742a9ae13aSMark Brown }; 2752a9ae13aSMark Brown 2762a9ae13aSMark Brown /* codec mclk clock divider coefficients */ 2772a9ae13aSMark Brown static const struct { 2782a9ae13aSMark Brown u32 mclk; 2792a9ae13aSMark Brown u32 rate; 2802a9ae13aSMark Brown u8 usb; 2812a9ae13aSMark Brown u8 sr; 2822a9ae13aSMark Brown } coeff_div[] = { 2832a9ae13aSMark Brown { 12288000, 8000, 0, 0x4 }, 2842a9ae13aSMark Brown { 12288000, 12000, 0, 0x8 }, 2852a9ae13aSMark Brown { 12288000, 16000, 0, 0xa }, 2862a9ae13aSMark Brown { 12288000, 24000, 0, 0x1c }, 2872a9ae13aSMark Brown { 12288000, 32000, 0, 0xc }, 2882a9ae13aSMark Brown { 12288000, 48000, 0, 0 }, 2892a9ae13aSMark Brown { 12288000, 96000, 0, 0xe }, 2902a9ae13aSMark Brown 2912a9ae13aSMark Brown { 11289600, 8000, 0, 0x14 }, 2922a9ae13aSMark Brown { 11289600, 11025, 0, 0x18 }, 2932a9ae13aSMark Brown { 11289600, 22050, 0, 0x1a }, 2942a9ae13aSMark Brown { 11289600, 44100, 0, 0x10 }, 2952a9ae13aSMark Brown { 11289600, 88200, 0, 0x1e }, 2962a9ae13aSMark Brown 2972a9ae13aSMark Brown { 18432000, 8000, 0, 0x5 }, 2982a9ae13aSMark Brown { 18432000, 12000, 0, 0x9 }, 2992a9ae13aSMark Brown { 18432000, 16000, 0, 0xb }, 3002a9ae13aSMark Brown { 18432000, 24000, 0, 0x1b }, 3012a9ae13aSMark Brown { 18432000, 32000, 0, 0xd }, 3022a9ae13aSMark Brown { 18432000, 48000, 0, 0x1 }, 3032a9ae13aSMark Brown { 18432000, 96000, 0, 0x1f }, 3042a9ae13aSMark Brown 3052a9ae13aSMark Brown { 16934400, 8000, 0, 0x15 }, 3062a9ae13aSMark Brown { 16934400, 11025, 0, 0x19 }, 3072a9ae13aSMark Brown { 16934400, 22050, 0, 0x1b }, 3082a9ae13aSMark Brown { 16934400, 44100, 0, 0x11 }, 3092a9ae13aSMark Brown { 16934400, 88200, 0, 0x1f }, 3102a9ae13aSMark Brown 3112a9ae13aSMark Brown { 12000000, 8000, 1, 0x4 }, 3122a9ae13aSMark Brown { 12000000, 11025, 1, 0x19 }, 3132a9ae13aSMark Brown { 12000000, 12000, 1, 0x8 }, 3142a9ae13aSMark Brown { 12000000, 16000, 1, 0xa }, 3152a9ae13aSMark Brown { 12000000, 22050, 1, 0x1b }, 3162a9ae13aSMark Brown { 12000000, 24000, 1, 0x1c }, 3172a9ae13aSMark Brown { 12000000, 32000, 1, 0xc }, 3182a9ae13aSMark Brown { 12000000, 44100, 1, 0x11 }, 3192a9ae13aSMark Brown { 12000000, 48000, 1, 0x0 }, 3202a9ae13aSMark Brown { 12000000, 88200, 1, 0x1f }, 3212a9ae13aSMark Brown { 12000000, 96000, 1, 0xe }, 3222a9ae13aSMark Brown }; 3232a9ae13aSMark Brown 3242a9ae13aSMark Brown static int wm8737_hw_params(struct snd_pcm_substream *substream, 3252a9ae13aSMark Brown struct snd_pcm_hw_params *params, 3262a9ae13aSMark Brown struct snd_soc_dai *dai) 3272a9ae13aSMark Brown { 328840680dcSKuninori Morimoto struct snd_soc_component *component = dai->component; 329840680dcSKuninori Morimoto struct wm8737_priv *wm8737 = snd_soc_component_get_drvdata(component); 3302a9ae13aSMark Brown int i; 3312a9ae13aSMark Brown u16 clocking = 0; 3322a9ae13aSMark Brown u16 af = 0; 3332a9ae13aSMark Brown 3342a9ae13aSMark Brown for (i = 0; i < ARRAY_SIZE(coeff_div); i++) { 3352a9ae13aSMark Brown if (coeff_div[i].rate != params_rate(params)) 3362a9ae13aSMark Brown continue; 3372a9ae13aSMark Brown 3382a9ae13aSMark Brown if (coeff_div[i].mclk == wm8737->mclk) 3392a9ae13aSMark Brown break; 3402a9ae13aSMark Brown 3412a9ae13aSMark Brown if (coeff_div[i].mclk == wm8737->mclk * 2) { 3422a9ae13aSMark Brown clocking |= WM8737_CLKDIV2; 3432a9ae13aSMark Brown break; 3442a9ae13aSMark Brown } 3452a9ae13aSMark Brown } 3462a9ae13aSMark Brown 3472a9ae13aSMark Brown if (i == ARRAY_SIZE(coeff_div)) { 348840680dcSKuninori Morimoto dev_err(component->dev, "%dHz MCLK can't support %dHz\n", 3492a9ae13aSMark Brown wm8737->mclk, params_rate(params)); 3502a9ae13aSMark Brown return -EINVAL; 3512a9ae13aSMark Brown } 3522a9ae13aSMark Brown 3532a9ae13aSMark Brown clocking |= coeff_div[i].usb | (coeff_div[i].sr << WM8737_SR_SHIFT); 3542a9ae13aSMark Brown 355a5d0de23SMark Brown switch (params_width(params)) { 356a5d0de23SMark Brown case 16: 3572a9ae13aSMark Brown break; 358a5d0de23SMark Brown case 20: 3592a9ae13aSMark Brown af |= 0x8; 3602a9ae13aSMark Brown break; 361a5d0de23SMark Brown case 24: 3622a9ae13aSMark Brown af |= 0x10; 3632a9ae13aSMark Brown break; 364a5d0de23SMark Brown case 32: 3652a9ae13aSMark Brown af |= 0x18; 3662a9ae13aSMark Brown break; 3672a9ae13aSMark Brown default: 3682a9ae13aSMark Brown return -EINVAL; 3692a9ae13aSMark Brown } 3702a9ae13aSMark Brown 371840680dcSKuninori Morimoto snd_soc_component_update_bits(component, WM8737_AUDIO_FORMAT, WM8737_WL_MASK, af); 372840680dcSKuninori Morimoto snd_soc_component_update_bits(component, WM8737_CLOCKING, 3732a9ae13aSMark Brown WM8737_USB_MODE | WM8737_CLKDIV2 | WM8737_SR_MASK, 3742a9ae13aSMark Brown clocking); 3752a9ae13aSMark Brown 3762a9ae13aSMark Brown return 0; 3772a9ae13aSMark Brown } 3782a9ae13aSMark Brown 3792a9ae13aSMark Brown static int wm8737_set_dai_sysclk(struct snd_soc_dai *codec_dai, 3802a9ae13aSMark Brown int clk_id, unsigned int freq, int dir) 3812a9ae13aSMark Brown { 382840680dcSKuninori Morimoto struct snd_soc_component *component = codec_dai->component; 383840680dcSKuninori Morimoto struct wm8737_priv *wm8737 = snd_soc_component_get_drvdata(component); 3842a9ae13aSMark Brown int i; 3852a9ae13aSMark Brown 3862a9ae13aSMark Brown for (i = 0; i < ARRAY_SIZE(coeff_div); i++) { 3872a9ae13aSMark Brown if (freq == coeff_div[i].mclk || 3882a9ae13aSMark Brown freq == coeff_div[i].mclk * 2) { 3892a9ae13aSMark Brown wm8737->mclk = freq; 3902a9ae13aSMark Brown return 0; 3912a9ae13aSMark Brown } 3922a9ae13aSMark Brown } 3932a9ae13aSMark Brown 394840680dcSKuninori Morimoto dev_err(component->dev, "MCLK rate %dHz not supported\n", freq); 3952a9ae13aSMark Brown 3962a9ae13aSMark Brown return -EINVAL; 3972a9ae13aSMark Brown } 3982a9ae13aSMark Brown 3992a9ae13aSMark Brown 4002a9ae13aSMark Brown static int wm8737_set_dai_fmt(struct snd_soc_dai *codec_dai, 4012a9ae13aSMark Brown unsigned int fmt) 4022a9ae13aSMark Brown { 403840680dcSKuninori Morimoto struct snd_soc_component *component = codec_dai->component; 4042a9ae13aSMark Brown u16 af = 0; 4052a9ae13aSMark Brown 4062a9ae13aSMark Brown switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 4072a9ae13aSMark Brown case SND_SOC_DAIFMT_CBM_CFM: 4082a9ae13aSMark Brown af |= WM8737_MS; 4092a9ae13aSMark Brown break; 4102a9ae13aSMark Brown case SND_SOC_DAIFMT_CBS_CFS: 4112a9ae13aSMark Brown break; 4122a9ae13aSMark Brown default: 4132a9ae13aSMark Brown return -EINVAL; 4142a9ae13aSMark Brown } 4152a9ae13aSMark Brown 4162a9ae13aSMark Brown switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 4172a9ae13aSMark Brown case SND_SOC_DAIFMT_I2S: 4182a9ae13aSMark Brown af |= 0x2; 4192a9ae13aSMark Brown break; 4202a9ae13aSMark Brown case SND_SOC_DAIFMT_RIGHT_J: 4212a9ae13aSMark Brown break; 4222a9ae13aSMark Brown case SND_SOC_DAIFMT_LEFT_J: 4232a9ae13aSMark Brown af |= 0x1; 4242a9ae13aSMark Brown break; 4252a9ae13aSMark Brown case SND_SOC_DAIFMT_DSP_A: 4262a9ae13aSMark Brown af |= 0x3; 4272a9ae13aSMark Brown break; 4282a9ae13aSMark Brown case SND_SOC_DAIFMT_DSP_B: 4292a9ae13aSMark Brown af |= 0x13; 4302a9ae13aSMark Brown break; 4312a9ae13aSMark Brown default: 4322a9ae13aSMark Brown return -EINVAL; 4332a9ae13aSMark Brown } 4342a9ae13aSMark Brown 4352a9ae13aSMark Brown switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 4362a9ae13aSMark Brown case SND_SOC_DAIFMT_NB_NF: 4372a9ae13aSMark Brown break; 4382a9ae13aSMark Brown case SND_SOC_DAIFMT_NB_IF: 4392a9ae13aSMark Brown af |= WM8737_LRP; 4402a9ae13aSMark Brown break; 4412a9ae13aSMark Brown default: 4422a9ae13aSMark Brown return -EINVAL; 4432a9ae13aSMark Brown } 4442a9ae13aSMark Brown 445840680dcSKuninori Morimoto snd_soc_component_update_bits(component, WM8737_AUDIO_FORMAT, 4462a9ae13aSMark Brown WM8737_FORMAT_MASK | WM8737_LRP | WM8737_MS, af); 4472a9ae13aSMark Brown 4482a9ae13aSMark Brown return 0; 4492a9ae13aSMark Brown } 4502a9ae13aSMark Brown 451840680dcSKuninori Morimoto static int wm8737_set_bias_level(struct snd_soc_component *component, 4522a9ae13aSMark Brown enum snd_soc_bias_level level) 4532a9ae13aSMark Brown { 454840680dcSKuninori Morimoto struct wm8737_priv *wm8737 = snd_soc_component_get_drvdata(component); 4552a9ae13aSMark Brown int ret; 4562a9ae13aSMark Brown 4572a9ae13aSMark Brown switch (level) { 4582a9ae13aSMark Brown case SND_SOC_BIAS_ON: 4592a9ae13aSMark Brown break; 4602a9ae13aSMark Brown 4612a9ae13aSMark Brown case SND_SOC_BIAS_PREPARE: 4622a9ae13aSMark Brown /* VMID at 2*75k */ 463840680dcSKuninori Morimoto snd_soc_component_update_bits(component, WM8737_MISC_BIAS_CONTROL, 4642a9ae13aSMark Brown WM8737_VMIDSEL_MASK, 0); 4652a9ae13aSMark Brown break; 4662a9ae13aSMark Brown 4672a9ae13aSMark Brown case SND_SOC_BIAS_STANDBY: 468840680dcSKuninori Morimoto if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) { 4692a9ae13aSMark Brown ret = regulator_bulk_enable(ARRAY_SIZE(wm8737->supplies), 4702a9ae13aSMark Brown wm8737->supplies); 4712a9ae13aSMark Brown if (ret != 0) { 472840680dcSKuninori Morimoto dev_err(component->dev, 4732a9ae13aSMark Brown "Failed to enable supplies: %d\n", 4742a9ae13aSMark Brown ret); 4752a9ae13aSMark Brown return ret; 4762a9ae13aSMark Brown } 4772a9ae13aSMark Brown 4783ef8ac0dSMark Brown regcache_sync(wm8737->regmap); 4792a9ae13aSMark Brown 4802a9ae13aSMark Brown /* Fast VMID ramp at 2*2.5k */ 481840680dcSKuninori Morimoto snd_soc_component_update_bits(component, WM8737_MISC_BIAS_CONTROL, 48214ba3ec1SAxel Lin WM8737_VMIDSEL_MASK, 48314ba3ec1SAxel Lin 2 << WM8737_VMIDSEL_SHIFT); 4842a9ae13aSMark Brown 4852a9ae13aSMark Brown /* Bring VMID up */ 486840680dcSKuninori Morimoto snd_soc_component_update_bits(component, WM8737_POWER_MANAGEMENT, 4872a9ae13aSMark Brown WM8737_VMID_MASK | 4882a9ae13aSMark Brown WM8737_VREF_MASK, 4892a9ae13aSMark Brown WM8737_VMID_MASK | 4902a9ae13aSMark Brown WM8737_VREF_MASK); 4912a9ae13aSMark Brown 4922a9ae13aSMark Brown msleep(500); 4932a9ae13aSMark Brown } 4942a9ae13aSMark Brown 4952a9ae13aSMark Brown /* VMID at 2*300k */ 496840680dcSKuninori Morimoto snd_soc_component_update_bits(component, WM8737_MISC_BIAS_CONTROL, 49714ba3ec1SAxel Lin WM8737_VMIDSEL_MASK, 49814ba3ec1SAxel Lin 1 << WM8737_VMIDSEL_SHIFT); 4992a9ae13aSMark Brown 5002a9ae13aSMark Brown break; 5012a9ae13aSMark Brown 5022a9ae13aSMark Brown case SND_SOC_BIAS_OFF: 503840680dcSKuninori Morimoto snd_soc_component_update_bits(component, WM8737_POWER_MANAGEMENT, 5042a9ae13aSMark Brown WM8737_VMID_MASK | WM8737_VREF_MASK, 0); 5052a9ae13aSMark Brown 5062a9ae13aSMark Brown regulator_bulk_disable(ARRAY_SIZE(wm8737->supplies), 5072a9ae13aSMark Brown wm8737->supplies); 5082a9ae13aSMark Brown break; 5092a9ae13aSMark Brown } 5102a9ae13aSMark Brown 5112a9ae13aSMark Brown return 0; 5122a9ae13aSMark Brown } 5132a9ae13aSMark Brown 5142a9ae13aSMark Brown #define WM8737_RATES SNDRV_PCM_RATE_8000_96000 5152a9ae13aSMark Brown 5162a9ae13aSMark Brown #define WM8737_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 5172a9ae13aSMark Brown SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) 5182a9ae13aSMark Brown 51985e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops wm8737_dai_ops = { 5202a9ae13aSMark Brown .hw_params = wm8737_hw_params, 5212a9ae13aSMark Brown .set_sysclk = wm8737_set_dai_sysclk, 5222a9ae13aSMark Brown .set_fmt = wm8737_set_dai_fmt, 5232a9ae13aSMark Brown }; 5242a9ae13aSMark Brown 5252a9ae13aSMark Brown static struct snd_soc_dai_driver wm8737_dai = { 5262a9ae13aSMark Brown .name = "wm8737", 5272a9ae13aSMark Brown .capture = { 5282a9ae13aSMark Brown .stream_name = "Capture", 5292a9ae13aSMark Brown .channels_min = 2, /* Mono modes not yet supported */ 5302a9ae13aSMark Brown .channels_max = 2, 5312a9ae13aSMark Brown .rates = WM8737_RATES, 5322a9ae13aSMark Brown .formats = WM8737_FORMATS, 5332a9ae13aSMark Brown }, 5342a9ae13aSMark Brown .ops = &wm8737_dai_ops, 5352a9ae13aSMark Brown }; 5362a9ae13aSMark Brown 537840680dcSKuninori Morimoto static int wm8737_probe(struct snd_soc_component *component) 5382a9ae13aSMark Brown { 539840680dcSKuninori Morimoto struct wm8737_priv *wm8737 = snd_soc_component_get_drvdata(component); 5404f69bb31SMark Brown int ret; 5412a9ae13aSMark Brown 5422a9ae13aSMark Brown ret = regulator_bulk_enable(ARRAY_SIZE(wm8737->supplies), 5432a9ae13aSMark Brown wm8737->supplies); 5442a9ae13aSMark Brown if (ret != 0) { 545840680dcSKuninori Morimoto dev_err(component->dev, "Failed to enable supplies: %d\n", ret); 5462a9ae13aSMark Brown goto err_get; 5472a9ae13aSMark Brown } 5482a9ae13aSMark Brown 549840680dcSKuninori Morimoto ret = wm8737_reset(component); 5502a9ae13aSMark Brown if (ret < 0) { 551840680dcSKuninori Morimoto dev_err(component->dev, "Failed to issue reset\n"); 5522a9ae13aSMark Brown goto err_enable; 5532a9ae13aSMark Brown } 5542a9ae13aSMark Brown 555840680dcSKuninori Morimoto snd_soc_component_update_bits(component, WM8737_LEFT_PGA_VOLUME, WM8737_LVU, 5562a9ae13aSMark Brown WM8737_LVU); 557840680dcSKuninori Morimoto snd_soc_component_update_bits(component, WM8737_RIGHT_PGA_VOLUME, WM8737_RVU, 5582a9ae13aSMark Brown WM8737_RVU); 5592a9ae13aSMark Brown 560840680dcSKuninori Morimoto snd_soc_component_force_bias_level(component, SND_SOC_BIAS_STANDBY); 5612a9ae13aSMark Brown 5622a9ae13aSMark Brown /* Bias level configuration will have done an extra enable */ 5632a9ae13aSMark Brown regulator_bulk_disable(ARRAY_SIZE(wm8737->supplies), wm8737->supplies); 5642a9ae13aSMark Brown 5652a9ae13aSMark Brown return 0; 5662a9ae13aSMark Brown 5672a9ae13aSMark Brown err_enable: 5682a9ae13aSMark Brown regulator_bulk_disable(ARRAY_SIZE(wm8737->supplies), wm8737->supplies); 5692a9ae13aSMark Brown err_get: 5702a9ae13aSMark Brown return ret; 5712a9ae13aSMark Brown } 5722a9ae13aSMark Brown 573840680dcSKuninori Morimoto static const struct snd_soc_component_driver soc_component_dev_wm8737 = { 5742a9ae13aSMark Brown .probe = wm8737_probe, 5752a9ae13aSMark Brown .set_bias_level = wm8737_set_bias_level, 576a6bf3069SLars-Peter Clausen .controls = wm8737_snd_controls, 577a6bf3069SLars-Peter Clausen .num_controls = ARRAY_SIZE(wm8737_snd_controls), 578a6bf3069SLars-Peter Clausen .dapm_widgets = wm8737_dapm_widgets, 579a6bf3069SLars-Peter Clausen .num_dapm_widgets = ARRAY_SIZE(wm8737_dapm_widgets), 580a6bf3069SLars-Peter Clausen .dapm_routes = intercon, 581a6bf3069SLars-Peter Clausen .num_dapm_routes = ARRAY_SIZE(intercon), 582840680dcSKuninori Morimoto .suspend_bias_off = 1, 583840680dcSKuninori Morimoto .idle_bias_on = 1, 584840680dcSKuninori Morimoto .use_pmdown_time = 1, 585840680dcSKuninori Morimoto .endianness = 1, 586840680dcSKuninori Morimoto .non_legacy_dai_naming = 1, 5872a9ae13aSMark Brown }; 5882a9ae13aSMark Brown 58953a5a83dSMark Brown static const struct of_device_id wm8737_of_match[] = { 59053a5a83dSMark Brown { .compatible = "wlf,wm8737", }, 59153a5a83dSMark Brown { } 59253a5a83dSMark Brown }; 59353a5a83dSMark Brown 59453a5a83dSMark Brown MODULE_DEVICE_TABLE(of, wm8737_of_match); 59553a5a83dSMark Brown 5963ef8ac0dSMark Brown static const struct regmap_config wm8737_regmap = { 5973ef8ac0dSMark Brown .reg_bits = 7, 5983ef8ac0dSMark Brown .val_bits = 9, 5993ef8ac0dSMark Brown .max_register = WM8737_MAX_REGISTER, 6003ef8ac0dSMark Brown 6013ef8ac0dSMark Brown .reg_defaults = wm8737_reg_defaults, 6023ef8ac0dSMark Brown .num_reg_defaults = ARRAY_SIZE(wm8737_reg_defaults), 6033ef8ac0dSMark Brown .cache_type = REGCACHE_RBTREE, 6043ef8ac0dSMark Brown 6053ef8ac0dSMark Brown .volatile_reg = wm8737_volatile, 6063ef8ac0dSMark Brown }; 6073ef8ac0dSMark Brown 6081037d567SFabio Estevam #if IS_ENABLED(CONFIG_I2C) 6097a79e94eSBill Pemberton static int wm8737_i2c_probe(struct i2c_client *i2c, 6102a9ae13aSMark Brown const struct i2c_device_id *id) 6112a9ae13aSMark Brown { 6122a9ae13aSMark Brown struct wm8737_priv *wm8737; 6134f69bb31SMark Brown int ret, i; 6142a9ae13aSMark Brown 61565fdd9bfSMark Brown wm8737 = devm_kzalloc(&i2c->dev, sizeof(struct wm8737_priv), 61665fdd9bfSMark Brown GFP_KERNEL); 6172a9ae13aSMark Brown if (wm8737 == NULL) 6182a9ae13aSMark Brown return -ENOMEM; 6192a9ae13aSMark Brown 6204f69bb31SMark Brown for (i = 0; i < ARRAY_SIZE(wm8737->supplies); i++) 6214f69bb31SMark Brown wm8737->supplies[i].supply = wm8737_supply_names[i]; 6224f69bb31SMark Brown 6234f69bb31SMark Brown ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8737->supplies), 6244f69bb31SMark Brown wm8737->supplies); 6254f69bb31SMark Brown if (ret != 0) { 6264f69bb31SMark Brown dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); 6274f69bb31SMark Brown return ret; 6284f69bb31SMark Brown } 6294f69bb31SMark Brown 6303ef8ac0dSMark Brown wm8737->regmap = devm_regmap_init_i2c(i2c, &wm8737_regmap); 6313ef8ac0dSMark Brown if (IS_ERR(wm8737->regmap)) 6323ef8ac0dSMark Brown return PTR_ERR(wm8737->regmap); 6333ef8ac0dSMark Brown 6342a9ae13aSMark Brown i2c_set_clientdata(i2c, wm8737); 6352a9ae13aSMark Brown 636840680dcSKuninori Morimoto ret = devm_snd_soc_register_component(&i2c->dev, 637840680dcSKuninori Morimoto &soc_component_dev_wm8737, &wm8737_dai, 1); 63865fdd9bfSMark Brown 6392a9ae13aSMark Brown return ret; 6402a9ae13aSMark Brown 6412a9ae13aSMark Brown } 6422a9ae13aSMark Brown 6432a9ae13aSMark Brown static const struct i2c_device_id wm8737_i2c_id[] = { 6442a9ae13aSMark Brown { "wm8737", 0 }, 6452a9ae13aSMark Brown { } 6462a9ae13aSMark Brown }; 6472a9ae13aSMark Brown MODULE_DEVICE_TABLE(i2c, wm8737_i2c_id); 6482a9ae13aSMark Brown 6492a9ae13aSMark Brown static struct i2c_driver wm8737_i2c_driver = { 6502a9ae13aSMark Brown .driver = { 6512a9ae13aSMark Brown .name = "wm8737", 65253a5a83dSMark Brown .of_match_table = wm8737_of_match, 6532a9ae13aSMark Brown }, 6542a9ae13aSMark Brown .probe = wm8737_i2c_probe, 6552a9ae13aSMark Brown .id_table = wm8737_i2c_id, 6562a9ae13aSMark Brown }; 6572a9ae13aSMark Brown #endif 6582a9ae13aSMark Brown 6592a9ae13aSMark Brown #if defined(CONFIG_SPI_MASTER) 6607a79e94eSBill Pemberton static int wm8737_spi_probe(struct spi_device *spi) 6612a9ae13aSMark Brown { 6622a9ae13aSMark Brown struct wm8737_priv *wm8737; 6634f69bb31SMark Brown int ret, i; 6642a9ae13aSMark Brown 66565fdd9bfSMark Brown wm8737 = devm_kzalloc(&spi->dev, sizeof(struct wm8737_priv), 66665fdd9bfSMark Brown GFP_KERNEL); 6672a9ae13aSMark Brown if (wm8737 == NULL) 6682a9ae13aSMark Brown return -ENOMEM; 6692a9ae13aSMark Brown 6704f69bb31SMark Brown for (i = 0; i < ARRAY_SIZE(wm8737->supplies); i++) 6714f69bb31SMark Brown wm8737->supplies[i].supply = wm8737_supply_names[i]; 6724f69bb31SMark Brown 6734f69bb31SMark Brown ret = devm_regulator_bulk_get(&spi->dev, ARRAY_SIZE(wm8737->supplies), 6744f69bb31SMark Brown wm8737->supplies); 6754f69bb31SMark Brown if (ret != 0) { 6764f69bb31SMark Brown dev_err(&spi->dev, "Failed to request supplies: %d\n", ret); 6774f69bb31SMark Brown return ret; 6784f69bb31SMark Brown } 6794f69bb31SMark Brown 6803ef8ac0dSMark Brown wm8737->regmap = devm_regmap_init_spi(spi, &wm8737_regmap); 6813ef8ac0dSMark Brown if (IS_ERR(wm8737->regmap)) 6823ef8ac0dSMark Brown return PTR_ERR(wm8737->regmap); 6833ef8ac0dSMark Brown 6842a9ae13aSMark Brown spi_set_drvdata(spi, wm8737); 6852a9ae13aSMark Brown 686840680dcSKuninori Morimoto ret = devm_snd_soc_register_component(&spi->dev, 687840680dcSKuninori Morimoto &soc_component_dev_wm8737, &wm8737_dai, 1); 68865fdd9bfSMark Brown 6892a9ae13aSMark Brown return ret; 6902a9ae13aSMark Brown } 6912a9ae13aSMark Brown 6922a9ae13aSMark Brown static struct spi_driver wm8737_spi_driver = { 6932a9ae13aSMark Brown .driver = { 6942a9ae13aSMark Brown .name = "wm8737", 69553a5a83dSMark Brown .of_match_table = wm8737_of_match, 6962a9ae13aSMark Brown }, 6972a9ae13aSMark Brown .probe = wm8737_spi_probe, 6982a9ae13aSMark Brown }; 6992a9ae13aSMark Brown #endif /* CONFIG_SPI_MASTER */ 7002a9ae13aSMark Brown 7012a9ae13aSMark Brown static int __init wm8737_modinit(void) 7022a9ae13aSMark Brown { 7032a9ae13aSMark Brown int ret; 7041037d567SFabio Estevam #if IS_ENABLED(CONFIG_I2C) 7052a9ae13aSMark Brown ret = i2c_add_driver(&wm8737_i2c_driver); 7062a9ae13aSMark Brown if (ret != 0) { 7072a9ae13aSMark Brown printk(KERN_ERR "Failed to register WM8737 I2C driver: %d\n", 7082a9ae13aSMark Brown ret); 7092a9ae13aSMark Brown } 7102a9ae13aSMark Brown #endif 7112a9ae13aSMark Brown #if defined(CONFIG_SPI_MASTER) 7122a9ae13aSMark Brown ret = spi_register_driver(&wm8737_spi_driver); 7132a9ae13aSMark Brown if (ret != 0) { 7142a9ae13aSMark Brown printk(KERN_ERR "Failed to register WM8737 SPI driver: %d\n", 7152a9ae13aSMark Brown ret); 7162a9ae13aSMark Brown } 7172a9ae13aSMark Brown #endif 7182a9ae13aSMark Brown return 0; 7192a9ae13aSMark Brown } 7202a9ae13aSMark Brown module_init(wm8737_modinit); 7212a9ae13aSMark Brown 7222a9ae13aSMark Brown static void __exit wm8737_exit(void) 7232a9ae13aSMark Brown { 7242a9ae13aSMark Brown #if defined(CONFIG_SPI_MASTER) 7252a9ae13aSMark Brown spi_unregister_driver(&wm8737_spi_driver); 7262a9ae13aSMark Brown #endif 7271037d567SFabio Estevam #if IS_ENABLED(CONFIG_I2C) 7282a9ae13aSMark Brown i2c_del_driver(&wm8737_i2c_driver); 7292a9ae13aSMark Brown #endif 7302a9ae13aSMark Brown } 7312a9ae13aSMark Brown module_exit(wm8737_exit); 7322a9ae13aSMark Brown 7332a9ae13aSMark Brown MODULE_DESCRIPTION("ASoC WM8737 driver"); 7342a9ae13aSMark Brown MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 7352a9ae13aSMark Brown MODULE_LICENSE("GPL"); 736