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> 192a9ae13aSMark Brown #include <linux/platform_device.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 { 442a9ae13aSMark Brown enum snd_soc_control_type control_type; 452a9ae13aSMark Brown struct regulator_bulk_data supplies[WM8737_NUM_SUPPLIES]; 462a9ae13aSMark Brown unsigned int mclk; 472a9ae13aSMark Brown }; 482a9ae13aSMark Brown 492a9ae13aSMark Brown static const u16 wm8737_reg[WM8737_REGISTER_COUNT] = { 502a9ae13aSMark Brown 0x00C3, /* R0 - Left PGA volume */ 512a9ae13aSMark Brown 0x00C3, /* R1 - Right PGA volume */ 522a9ae13aSMark Brown 0x0007, /* R2 - AUDIO path L */ 532a9ae13aSMark Brown 0x0007, /* R3 - AUDIO path R */ 542a9ae13aSMark Brown 0x0000, /* R4 - 3D Enhance */ 552a9ae13aSMark Brown 0x0000, /* R5 - ADC Control */ 562a9ae13aSMark Brown 0x0000, /* R6 - Power Management */ 572a9ae13aSMark Brown 0x000A, /* R7 - Audio Format */ 582a9ae13aSMark Brown 0x0000, /* R8 - Clocking */ 592a9ae13aSMark Brown 0x000F, /* R9 - MIC Preamp Control */ 602a9ae13aSMark Brown 0x0003, /* R10 - Misc Bias Control */ 612a9ae13aSMark Brown 0x0000, /* R11 - Noise Gate */ 622a9ae13aSMark Brown 0x007C, /* R12 - ALC1 */ 632a9ae13aSMark Brown 0x0000, /* R13 - ALC2 */ 642a9ae13aSMark Brown 0x0032, /* R14 - ALC3 */ 652a9ae13aSMark Brown }; 662a9ae13aSMark Brown 672a9ae13aSMark Brown static int wm8737_reset(struct snd_soc_codec *codec) 682a9ae13aSMark Brown { 692a9ae13aSMark Brown return snd_soc_write(codec, WM8737_RESET, 0); 702a9ae13aSMark Brown } 712a9ae13aSMark Brown 722a9ae13aSMark Brown static const unsigned int micboost_tlv[] = { 732a9ae13aSMark Brown TLV_DB_RANGE_HEAD(4), 742a9ae13aSMark Brown 0, 0, TLV_DB_SCALE_ITEM(1300, 0, 0), 752a9ae13aSMark Brown 1, 1, TLV_DB_SCALE_ITEM(1800, 0, 0), 762a9ae13aSMark Brown 2, 2, TLV_DB_SCALE_ITEM(2800, 0, 0), 772a9ae13aSMark Brown 3, 3, TLV_DB_SCALE_ITEM(3300, 0, 0), 782a9ae13aSMark Brown }; 792a9ae13aSMark Brown static const DECLARE_TLV_DB_SCALE(pga_tlv, -9750, 50, 1); 802a9ae13aSMark Brown static const DECLARE_TLV_DB_SCALE(adc_tlv, -600, 600, 0); 812a9ae13aSMark Brown static const DECLARE_TLV_DB_SCALE(ng_tlv, -7800, 600, 0); 82fcd02e26SMark Brown static const DECLARE_TLV_DB_SCALE(alc_max_tlv, -1200, 600, 0); 83fcd02e26SMark Brown static const DECLARE_TLV_DB_SCALE(alc_target_tlv, -1800, 100, 0); 842a9ae13aSMark Brown 852a9ae13aSMark Brown static const char *micbias_enum_text[] = { 862a9ae13aSMark Brown "25%", 872a9ae13aSMark Brown "50%", 882a9ae13aSMark Brown "75%", 892a9ae13aSMark Brown "100%", 902a9ae13aSMark Brown }; 912a9ae13aSMark Brown 922a9ae13aSMark Brown static const struct soc_enum micbias_enum = 932a9ae13aSMark Brown SOC_ENUM_SINGLE(WM8737_MIC_PREAMP_CONTROL, 0, 4, micbias_enum_text); 942a9ae13aSMark Brown 952a9ae13aSMark Brown static const char *low_cutoff_text[] = { 962a9ae13aSMark Brown "Low", "High" 972a9ae13aSMark Brown }; 982a9ae13aSMark Brown 992a9ae13aSMark Brown static const struct soc_enum low_3d = 1002a9ae13aSMark Brown SOC_ENUM_SINGLE(WM8737_3D_ENHANCE, 6, 2, low_cutoff_text); 1012a9ae13aSMark Brown 1022a9ae13aSMark Brown static const char *high_cutoff_text[] = { 1032a9ae13aSMark Brown "High", "Low" 1042a9ae13aSMark Brown }; 1052a9ae13aSMark Brown 1062a9ae13aSMark Brown static const struct soc_enum high_3d = 1072a9ae13aSMark Brown SOC_ENUM_SINGLE(WM8737_3D_ENHANCE, 5, 2, high_cutoff_text); 1082a9ae13aSMark Brown 109fcd02e26SMark Brown static const char *alc_fn_text[] = { 110fcd02e26SMark Brown "Disabled", "Right", "Left", "Stereo" 111fcd02e26SMark Brown }; 112fcd02e26SMark Brown 113fcd02e26SMark Brown static const struct soc_enum alc_fn = 114fcd02e26SMark Brown SOC_ENUM_SINGLE(WM8737_ALC1, 7, 4, alc_fn_text); 115fcd02e26SMark Brown 116fcd02e26SMark Brown static const char *alc_hold_text[] = { 117fcd02e26SMark Brown "0", "2.67ms", "5.33ms", "10.66ms", "21.32ms", "42.64ms", "85.28ms", 118fcd02e26SMark Brown "170.56ms", "341.12ms", "682.24ms", "1.364s", "2.728s", "5.458s", 119fcd02e26SMark Brown "10.916s", "21.832s", "43.691s" 120fcd02e26SMark Brown }; 121fcd02e26SMark Brown 122fcd02e26SMark Brown static const struct soc_enum alc_hold = 123fcd02e26SMark Brown SOC_ENUM_SINGLE(WM8737_ALC2, 0, 16, alc_hold_text); 124fcd02e26SMark Brown 125fcd02e26SMark Brown static const char *alc_atk_text[] = { 126fcd02e26SMark Brown "8.4ms", "16.8ms", "33.6ms", "67.2ms", "134.4ms", "268.8ms", "537.6ms", 127fcd02e26SMark Brown "1.075s", "2.15s", "4.3s", "8.6s" 128fcd02e26SMark Brown }; 129fcd02e26SMark Brown 130fcd02e26SMark Brown static const struct soc_enum alc_atk = 131fcd02e26SMark Brown SOC_ENUM_SINGLE(WM8737_ALC3, 0, 11, alc_atk_text); 132fcd02e26SMark Brown 133fcd02e26SMark Brown static const char *alc_dcy_text[] = { 134fcd02e26SMark Brown "33.6ms", "67.2ms", "134.4ms", "268.8ms", "537.6ms", "1.075s", "2.15s", 135fcd02e26SMark Brown "4.3s", "8.6s", "17.2s", "34.41s" 136fcd02e26SMark Brown }; 137fcd02e26SMark Brown 138fcd02e26SMark Brown static const struct soc_enum alc_dcy = 139fcd02e26SMark Brown SOC_ENUM_SINGLE(WM8737_ALC3, 4, 11, alc_dcy_text); 140fcd02e26SMark Brown 1412a9ae13aSMark Brown static const struct snd_kcontrol_new wm8737_snd_controls[] = { 1422a9ae13aSMark Brown SOC_DOUBLE_R_TLV("Mic Boost Volume", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R, 1432a9ae13aSMark Brown 6, 3, 0, micboost_tlv), 1442a9ae13aSMark Brown SOC_DOUBLE_R("Mic Boost Switch", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R, 1452a9ae13aSMark Brown 4, 1, 0), 1462a9ae13aSMark Brown SOC_DOUBLE("Mic ZC Switch", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R, 1472a9ae13aSMark Brown 3, 1, 0), 1482a9ae13aSMark Brown 1492a9ae13aSMark Brown SOC_DOUBLE_R_TLV("Capture Volume", WM8737_LEFT_PGA_VOLUME, 1502a9ae13aSMark Brown WM8737_RIGHT_PGA_VOLUME, 0, 255, 0, pga_tlv), 1512a9ae13aSMark Brown SOC_DOUBLE("Capture ZC Switch", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R, 1522a9ae13aSMark Brown 2, 1, 0), 1532a9ae13aSMark Brown 1542a9ae13aSMark Brown SOC_DOUBLE("INPUT1 DC Bias Switch", WM8737_MISC_BIAS_CONTROL, 0, 1, 1, 0), 1552a9ae13aSMark Brown 1562a9ae13aSMark Brown SOC_ENUM("Mic PGA Bias", micbias_enum), 1572a9ae13aSMark Brown SOC_SINGLE("ADC Low Power Switch", WM8737_ADC_CONTROL, 2, 1, 0), 1582a9ae13aSMark Brown SOC_SINGLE("High Pass Filter Switch", WM8737_ADC_CONTROL, 0, 1, 1), 1592a9ae13aSMark Brown SOC_DOUBLE("Polarity Invert Switch", WM8737_ADC_CONTROL, 5, 6, 1, 0), 1602a9ae13aSMark Brown 1612a9ae13aSMark Brown SOC_SINGLE("3D Switch", WM8737_3D_ENHANCE, 0, 1, 0), 1622a9ae13aSMark Brown SOC_SINGLE("3D Depth", WM8737_3D_ENHANCE, 1, 15, 0), 1632a9ae13aSMark Brown SOC_ENUM("3D Low Cut-off", low_3d), 1642a9ae13aSMark Brown SOC_ENUM("3D High Cut-off", low_3d), 1652a9ae13aSMark Brown SOC_SINGLE_TLV("3D ADC Volume", WM8737_3D_ENHANCE, 7, 1, 1, adc_tlv), 1662a9ae13aSMark Brown 1672a9ae13aSMark Brown SOC_SINGLE("Noise Gate Switch", WM8737_NOISE_GATE, 0, 1, 0), 1682a9ae13aSMark Brown SOC_SINGLE_TLV("Noise Gate Threshold Volume", WM8737_NOISE_GATE, 2, 7, 0, 1692a9ae13aSMark Brown ng_tlv), 170fcd02e26SMark Brown 171fcd02e26SMark Brown SOC_ENUM("ALC", alc_fn), 172fcd02e26SMark Brown SOC_SINGLE_TLV("ALC Max Gain Volume", WM8737_ALC1, 4, 7, 0, alc_max_tlv), 173fcd02e26SMark Brown SOC_SINGLE_TLV("ALC Target Volume", WM8737_ALC1, 0, 15, 0, alc_target_tlv), 174fcd02e26SMark Brown SOC_ENUM("ALC Hold Time", alc_hold), 175fcd02e26SMark Brown SOC_SINGLE("ALC ZC Switch", WM8737_ALC2, 4, 1, 0), 176fcd02e26SMark Brown SOC_ENUM("ALC Attack Time", alc_atk), 177fcd02e26SMark Brown SOC_ENUM("ALC Decay Time", alc_dcy), 1782a9ae13aSMark Brown }; 1792a9ae13aSMark Brown 1802a9ae13aSMark Brown static const char *linsel_text[] = { 1812a9ae13aSMark Brown "LINPUT1", "LINPUT2", "LINPUT3", "LINPUT1 DC", 1822a9ae13aSMark Brown }; 1832a9ae13aSMark Brown 1842a9ae13aSMark Brown static const struct soc_enum linsel_enum = 1852a9ae13aSMark Brown SOC_ENUM_SINGLE(WM8737_AUDIO_PATH_L, 7, 4, linsel_text); 1862a9ae13aSMark Brown 1872a9ae13aSMark Brown static const struct snd_kcontrol_new linsel_mux = 1882a9ae13aSMark Brown SOC_DAPM_ENUM("LINSEL", linsel_enum); 1892a9ae13aSMark Brown 1902a9ae13aSMark Brown 1912a9ae13aSMark Brown static const char *rinsel_text[] = { 1922a9ae13aSMark Brown "RINPUT1", "RINPUT2", "RINPUT3", "RINPUT1 DC", 1932a9ae13aSMark Brown }; 1942a9ae13aSMark Brown 1952a9ae13aSMark Brown static const struct soc_enum rinsel_enum = 1962a9ae13aSMark Brown SOC_ENUM_SINGLE(WM8737_AUDIO_PATH_R, 7, 4, rinsel_text); 1972a9ae13aSMark Brown 1982a9ae13aSMark Brown static const struct snd_kcontrol_new rinsel_mux = 1992a9ae13aSMark Brown SOC_DAPM_ENUM("RINSEL", rinsel_enum); 2002a9ae13aSMark Brown 2012a9ae13aSMark Brown static const char *bypass_text[] = { 2022a9ae13aSMark Brown "Direct", "Preamp" 2032a9ae13aSMark Brown }; 2042a9ae13aSMark Brown 2052a9ae13aSMark Brown static const struct soc_enum lbypass_enum = 2062a9ae13aSMark Brown SOC_ENUM_SINGLE(WM8737_MIC_PREAMP_CONTROL, 2, 2, bypass_text); 2072a9ae13aSMark Brown 2082a9ae13aSMark Brown static const struct snd_kcontrol_new lbypass_mux = 2092a9ae13aSMark Brown SOC_DAPM_ENUM("Left Bypass", lbypass_enum); 2102a9ae13aSMark Brown 2112a9ae13aSMark Brown 2122a9ae13aSMark Brown static const struct soc_enum rbypass_enum = 2132a9ae13aSMark Brown SOC_ENUM_SINGLE(WM8737_MIC_PREAMP_CONTROL, 3, 2, bypass_text); 2142a9ae13aSMark Brown 2152a9ae13aSMark Brown static const struct snd_kcontrol_new rbypass_mux = 2162a9ae13aSMark Brown SOC_DAPM_ENUM("Left Bypass", rbypass_enum); 2172a9ae13aSMark Brown 2182a9ae13aSMark Brown static const struct snd_soc_dapm_widget wm8737_dapm_widgets[] = { 2192a9ae13aSMark Brown SND_SOC_DAPM_INPUT("LINPUT1"), 2202a9ae13aSMark Brown SND_SOC_DAPM_INPUT("LINPUT2"), 2212a9ae13aSMark Brown SND_SOC_DAPM_INPUT("LINPUT3"), 2222a9ae13aSMark Brown SND_SOC_DAPM_INPUT("RINPUT1"), 2232a9ae13aSMark Brown SND_SOC_DAPM_INPUT("RINPUT2"), 2242a9ae13aSMark Brown SND_SOC_DAPM_INPUT("RINPUT3"), 2252a9ae13aSMark Brown SND_SOC_DAPM_INPUT("LACIN"), 2262a9ae13aSMark Brown SND_SOC_DAPM_INPUT("RACIN"), 2272a9ae13aSMark Brown 2282a9ae13aSMark Brown SND_SOC_DAPM_MUX("LINSEL", SND_SOC_NOPM, 0, 0, &linsel_mux), 2292a9ae13aSMark Brown SND_SOC_DAPM_MUX("RINSEL", SND_SOC_NOPM, 0, 0, &rinsel_mux), 2302a9ae13aSMark Brown 2312a9ae13aSMark Brown SND_SOC_DAPM_MUX("Left Preamp Mux", SND_SOC_NOPM, 0, 0, &lbypass_mux), 2322a9ae13aSMark Brown SND_SOC_DAPM_MUX("Right Preamp Mux", SND_SOC_NOPM, 0, 0, &rbypass_mux), 2332a9ae13aSMark Brown 2342a9ae13aSMark Brown SND_SOC_DAPM_PGA("PGAL", WM8737_POWER_MANAGEMENT, 5, 0, NULL, 0), 2352a9ae13aSMark Brown SND_SOC_DAPM_PGA("PGAR", WM8737_POWER_MANAGEMENT, 4, 0, NULL, 0), 2362a9ae13aSMark Brown 2372a9ae13aSMark Brown SND_SOC_DAPM_DAC("ADCL", NULL, WM8737_POWER_MANAGEMENT, 3, 0), 2382a9ae13aSMark Brown SND_SOC_DAPM_DAC("ADCR", NULL, WM8737_POWER_MANAGEMENT, 2, 0), 2392a9ae13aSMark Brown 2402a9ae13aSMark Brown SND_SOC_DAPM_AIF_OUT("AIF", "Capture", 0, WM8737_POWER_MANAGEMENT, 6, 0), 2412a9ae13aSMark Brown }; 2422a9ae13aSMark Brown 2432a9ae13aSMark Brown static const struct snd_soc_dapm_route intercon[] = { 2442a9ae13aSMark Brown { "LINSEL", "LINPUT1", "LINPUT1" }, 2452a9ae13aSMark Brown { "LINSEL", "LINPUT2", "LINPUT2" }, 2462a9ae13aSMark Brown { "LINSEL", "LINPUT3", "LINPUT3" }, 2472a9ae13aSMark Brown { "LINSEL", "LINPUT1 DC", "LINPUT1" }, 2482a9ae13aSMark Brown 2492a9ae13aSMark Brown { "RINSEL", "RINPUT1", "RINPUT1" }, 2502a9ae13aSMark Brown { "RINSEL", "RINPUT2", "RINPUT2" }, 2512a9ae13aSMark Brown { "RINSEL", "RINPUT3", "RINPUT3" }, 2522a9ae13aSMark Brown { "RINSEL", "RINPUT1 DC", "RINPUT1" }, 2532a9ae13aSMark Brown 2542a9ae13aSMark Brown { "Left Preamp Mux", "Preamp", "LINSEL" }, 2552a9ae13aSMark Brown { "Left Preamp Mux", "Direct", "LACIN" }, 2562a9ae13aSMark Brown 2572a9ae13aSMark Brown { "Right Preamp Mux", "Preamp", "RINSEL" }, 2582a9ae13aSMark Brown { "Right Preamp Mux", "Direct", "RACIN" }, 2592a9ae13aSMark Brown 2602a9ae13aSMark Brown { "PGAL", NULL, "Left Preamp Mux" }, 2612a9ae13aSMark Brown { "PGAR", NULL, "Right Preamp Mux" }, 2622a9ae13aSMark Brown 2632a9ae13aSMark Brown { "ADCL", NULL, "PGAL" }, 2642a9ae13aSMark Brown { "ADCR", NULL, "PGAR" }, 2652a9ae13aSMark Brown 2662a9ae13aSMark Brown { "AIF", NULL, "ADCL" }, 2672a9ae13aSMark Brown { "AIF", NULL, "ADCR" }, 2682a9ae13aSMark Brown }; 2692a9ae13aSMark Brown 2702a9ae13aSMark Brown static int wm8737_add_widgets(struct snd_soc_codec *codec) 2712a9ae13aSMark Brown { 2722a9ae13aSMark Brown struct snd_soc_dapm_context *dapm = &codec->dapm; 2732a9ae13aSMark Brown 2742a9ae13aSMark Brown snd_soc_dapm_new_controls(dapm, wm8737_dapm_widgets, 2752a9ae13aSMark Brown ARRAY_SIZE(wm8737_dapm_widgets)); 2762a9ae13aSMark Brown snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon)); 2772a9ae13aSMark Brown 2782a9ae13aSMark Brown return 0; 2792a9ae13aSMark Brown } 2802a9ae13aSMark Brown 2812a9ae13aSMark Brown /* codec mclk clock divider coefficients */ 2822a9ae13aSMark Brown static const struct { 2832a9ae13aSMark Brown u32 mclk; 2842a9ae13aSMark Brown u32 rate; 2852a9ae13aSMark Brown u8 usb; 2862a9ae13aSMark Brown u8 sr; 2872a9ae13aSMark Brown } coeff_div[] = { 2882a9ae13aSMark Brown { 12288000, 8000, 0, 0x4 }, 2892a9ae13aSMark Brown { 12288000, 12000, 0, 0x8 }, 2902a9ae13aSMark Brown { 12288000, 16000, 0, 0xa }, 2912a9ae13aSMark Brown { 12288000, 24000, 0, 0x1c }, 2922a9ae13aSMark Brown { 12288000, 32000, 0, 0xc }, 2932a9ae13aSMark Brown { 12288000, 48000, 0, 0 }, 2942a9ae13aSMark Brown { 12288000, 96000, 0, 0xe }, 2952a9ae13aSMark Brown 2962a9ae13aSMark Brown { 11289600, 8000, 0, 0x14 }, 2972a9ae13aSMark Brown { 11289600, 11025, 0, 0x18 }, 2982a9ae13aSMark Brown { 11289600, 22050, 0, 0x1a }, 2992a9ae13aSMark Brown { 11289600, 44100, 0, 0x10 }, 3002a9ae13aSMark Brown { 11289600, 88200, 0, 0x1e }, 3012a9ae13aSMark Brown 3022a9ae13aSMark Brown { 18432000, 8000, 0, 0x5 }, 3032a9ae13aSMark Brown { 18432000, 12000, 0, 0x9 }, 3042a9ae13aSMark Brown { 18432000, 16000, 0, 0xb }, 3052a9ae13aSMark Brown { 18432000, 24000, 0, 0x1b }, 3062a9ae13aSMark Brown { 18432000, 32000, 0, 0xd }, 3072a9ae13aSMark Brown { 18432000, 48000, 0, 0x1 }, 3082a9ae13aSMark Brown { 18432000, 96000, 0, 0x1f }, 3092a9ae13aSMark Brown 3102a9ae13aSMark Brown { 16934400, 8000, 0, 0x15 }, 3112a9ae13aSMark Brown { 16934400, 11025, 0, 0x19 }, 3122a9ae13aSMark Brown { 16934400, 22050, 0, 0x1b }, 3132a9ae13aSMark Brown { 16934400, 44100, 0, 0x11 }, 3142a9ae13aSMark Brown { 16934400, 88200, 0, 0x1f }, 3152a9ae13aSMark Brown 3162a9ae13aSMark Brown { 12000000, 8000, 1, 0x4 }, 3172a9ae13aSMark Brown { 12000000, 11025, 1, 0x19 }, 3182a9ae13aSMark Brown { 12000000, 12000, 1, 0x8 }, 3192a9ae13aSMark Brown { 12000000, 16000, 1, 0xa }, 3202a9ae13aSMark Brown { 12000000, 22050, 1, 0x1b }, 3212a9ae13aSMark Brown { 12000000, 24000, 1, 0x1c }, 3222a9ae13aSMark Brown { 12000000, 32000, 1, 0xc }, 3232a9ae13aSMark Brown { 12000000, 44100, 1, 0x11 }, 3242a9ae13aSMark Brown { 12000000, 48000, 1, 0x0 }, 3252a9ae13aSMark Brown { 12000000, 88200, 1, 0x1f }, 3262a9ae13aSMark Brown { 12000000, 96000, 1, 0xe }, 3272a9ae13aSMark Brown }; 3282a9ae13aSMark Brown 3292a9ae13aSMark Brown static int wm8737_hw_params(struct snd_pcm_substream *substream, 3302a9ae13aSMark Brown struct snd_pcm_hw_params *params, 3312a9ae13aSMark Brown struct snd_soc_dai *dai) 3322a9ae13aSMark Brown { 3332a9ae13aSMark Brown struct snd_soc_pcm_runtime *rtd = substream->private_data; 3342a9ae13aSMark Brown struct snd_soc_codec *codec = rtd->codec; 3352a9ae13aSMark Brown struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); 3362a9ae13aSMark Brown int i; 3372a9ae13aSMark Brown u16 clocking = 0; 3382a9ae13aSMark Brown u16 af = 0; 3392a9ae13aSMark Brown 3402a9ae13aSMark Brown for (i = 0; i < ARRAY_SIZE(coeff_div); i++) { 3412a9ae13aSMark Brown if (coeff_div[i].rate != params_rate(params)) 3422a9ae13aSMark Brown continue; 3432a9ae13aSMark Brown 3442a9ae13aSMark Brown if (coeff_div[i].mclk == wm8737->mclk) 3452a9ae13aSMark Brown break; 3462a9ae13aSMark Brown 3472a9ae13aSMark Brown if (coeff_div[i].mclk == wm8737->mclk * 2) { 3482a9ae13aSMark Brown clocking |= WM8737_CLKDIV2; 3492a9ae13aSMark Brown break; 3502a9ae13aSMark Brown } 3512a9ae13aSMark Brown } 3522a9ae13aSMark Brown 3532a9ae13aSMark Brown if (i == ARRAY_SIZE(coeff_div)) { 3542a9ae13aSMark Brown dev_err(codec->dev, "%dHz MCLK can't support %dHz\n", 3552a9ae13aSMark Brown wm8737->mclk, params_rate(params)); 3562a9ae13aSMark Brown return -EINVAL; 3572a9ae13aSMark Brown } 3582a9ae13aSMark Brown 3592a9ae13aSMark Brown clocking |= coeff_div[i].usb | (coeff_div[i].sr << WM8737_SR_SHIFT); 3602a9ae13aSMark Brown 3612a9ae13aSMark Brown switch (params_format(params)) { 3622a9ae13aSMark Brown case SNDRV_PCM_FORMAT_S16_LE: 3632a9ae13aSMark Brown break; 3642a9ae13aSMark Brown case SNDRV_PCM_FORMAT_S20_3LE: 3652a9ae13aSMark Brown af |= 0x8; 3662a9ae13aSMark Brown break; 3672a9ae13aSMark Brown case SNDRV_PCM_FORMAT_S24_LE: 3682a9ae13aSMark Brown af |= 0x10; 3692a9ae13aSMark Brown break; 3702a9ae13aSMark Brown case SNDRV_PCM_FORMAT_S32_LE: 3712a9ae13aSMark Brown af |= 0x18; 3722a9ae13aSMark Brown break; 3732a9ae13aSMark Brown default: 3742a9ae13aSMark Brown return -EINVAL; 3752a9ae13aSMark Brown } 3762a9ae13aSMark Brown 3772a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_AUDIO_FORMAT, WM8737_WL_MASK, af); 3782a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_CLOCKING, 3792a9ae13aSMark Brown WM8737_USB_MODE | WM8737_CLKDIV2 | WM8737_SR_MASK, 3802a9ae13aSMark Brown clocking); 3812a9ae13aSMark Brown 3822a9ae13aSMark Brown return 0; 3832a9ae13aSMark Brown } 3842a9ae13aSMark Brown 3852a9ae13aSMark Brown static int wm8737_set_dai_sysclk(struct snd_soc_dai *codec_dai, 3862a9ae13aSMark Brown int clk_id, unsigned int freq, int dir) 3872a9ae13aSMark Brown { 3882a9ae13aSMark Brown struct snd_soc_codec *codec = codec_dai->codec; 3892a9ae13aSMark Brown struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); 3902a9ae13aSMark Brown int i; 3912a9ae13aSMark Brown 3922a9ae13aSMark Brown for (i = 0; i < ARRAY_SIZE(coeff_div); i++) { 3932a9ae13aSMark Brown if (freq == coeff_div[i].mclk || 3942a9ae13aSMark Brown freq == coeff_div[i].mclk * 2) { 3952a9ae13aSMark Brown wm8737->mclk = freq; 3962a9ae13aSMark Brown return 0; 3972a9ae13aSMark Brown } 3982a9ae13aSMark Brown } 3992a9ae13aSMark Brown 4002a9ae13aSMark Brown dev_err(codec->dev, "MCLK rate %dHz not supported\n", freq); 4012a9ae13aSMark Brown 4022a9ae13aSMark Brown return -EINVAL; 4032a9ae13aSMark Brown } 4042a9ae13aSMark Brown 4052a9ae13aSMark Brown 4062a9ae13aSMark Brown static int wm8737_set_dai_fmt(struct snd_soc_dai *codec_dai, 4072a9ae13aSMark Brown unsigned int fmt) 4082a9ae13aSMark Brown { 4092a9ae13aSMark Brown struct snd_soc_codec *codec = codec_dai->codec; 4102a9ae13aSMark Brown u16 af = 0; 4112a9ae13aSMark Brown 4122a9ae13aSMark Brown switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 4132a9ae13aSMark Brown case SND_SOC_DAIFMT_CBM_CFM: 4142a9ae13aSMark Brown af |= WM8737_MS; 4152a9ae13aSMark Brown break; 4162a9ae13aSMark Brown case SND_SOC_DAIFMT_CBS_CFS: 4172a9ae13aSMark Brown break; 4182a9ae13aSMark Brown default: 4192a9ae13aSMark Brown return -EINVAL; 4202a9ae13aSMark Brown } 4212a9ae13aSMark Brown 4222a9ae13aSMark Brown switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 4232a9ae13aSMark Brown case SND_SOC_DAIFMT_I2S: 4242a9ae13aSMark Brown af |= 0x2; 4252a9ae13aSMark Brown break; 4262a9ae13aSMark Brown case SND_SOC_DAIFMT_RIGHT_J: 4272a9ae13aSMark Brown break; 4282a9ae13aSMark Brown case SND_SOC_DAIFMT_LEFT_J: 4292a9ae13aSMark Brown af |= 0x1; 4302a9ae13aSMark Brown break; 4312a9ae13aSMark Brown case SND_SOC_DAIFMT_DSP_A: 4322a9ae13aSMark Brown af |= 0x3; 4332a9ae13aSMark Brown break; 4342a9ae13aSMark Brown case SND_SOC_DAIFMT_DSP_B: 4352a9ae13aSMark Brown af |= 0x13; 4362a9ae13aSMark Brown break; 4372a9ae13aSMark Brown default: 4382a9ae13aSMark Brown return -EINVAL; 4392a9ae13aSMark Brown } 4402a9ae13aSMark Brown 4412a9ae13aSMark Brown switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 4422a9ae13aSMark Brown case SND_SOC_DAIFMT_NB_NF: 4432a9ae13aSMark Brown break; 4442a9ae13aSMark Brown case SND_SOC_DAIFMT_NB_IF: 4452a9ae13aSMark Brown af |= WM8737_LRP; 4462a9ae13aSMark Brown break; 4472a9ae13aSMark Brown default: 4482a9ae13aSMark Brown return -EINVAL; 4492a9ae13aSMark Brown } 4502a9ae13aSMark Brown 4512a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_AUDIO_FORMAT, 4522a9ae13aSMark Brown WM8737_FORMAT_MASK | WM8737_LRP | WM8737_MS, af); 4532a9ae13aSMark Brown 4542a9ae13aSMark Brown return 0; 4552a9ae13aSMark Brown } 4562a9ae13aSMark Brown 4572a9ae13aSMark Brown static int wm8737_set_bias_level(struct snd_soc_codec *codec, 4582a9ae13aSMark Brown enum snd_soc_bias_level level) 4592a9ae13aSMark Brown { 4602a9ae13aSMark Brown struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); 4612a9ae13aSMark Brown int ret; 4622a9ae13aSMark Brown 4632a9ae13aSMark Brown switch (level) { 4642a9ae13aSMark Brown case SND_SOC_BIAS_ON: 4652a9ae13aSMark Brown break; 4662a9ae13aSMark Brown 4672a9ae13aSMark Brown case SND_SOC_BIAS_PREPARE: 4682a9ae13aSMark Brown /* VMID at 2*75k */ 4692a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL, 4702a9ae13aSMark Brown WM8737_VMIDSEL_MASK, 0); 4712a9ae13aSMark Brown break; 4722a9ae13aSMark Brown 4732a9ae13aSMark Brown case SND_SOC_BIAS_STANDBY: 4742a9ae13aSMark Brown if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 4752a9ae13aSMark Brown ret = regulator_bulk_enable(ARRAY_SIZE(wm8737->supplies), 4762a9ae13aSMark Brown wm8737->supplies); 4772a9ae13aSMark Brown if (ret != 0) { 4782a9ae13aSMark Brown dev_err(codec->dev, 4792a9ae13aSMark Brown "Failed to enable supplies: %d\n", 4802a9ae13aSMark Brown ret); 4812a9ae13aSMark Brown return ret; 4822a9ae13aSMark Brown } 4832a9ae13aSMark Brown 4842a9ae13aSMark Brown snd_soc_cache_sync(codec); 4852a9ae13aSMark Brown 4862a9ae13aSMark Brown /* Fast VMID ramp at 2*2.5k */ 4872a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL, 4882a9ae13aSMark Brown WM8737_VMIDSEL_MASK, 0x4); 4892a9ae13aSMark Brown 4902a9ae13aSMark Brown /* Bring VMID up */ 4912a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_POWER_MANAGEMENT, 4922a9ae13aSMark Brown WM8737_VMID_MASK | 4932a9ae13aSMark Brown WM8737_VREF_MASK, 4942a9ae13aSMark Brown WM8737_VMID_MASK | 4952a9ae13aSMark Brown WM8737_VREF_MASK); 4962a9ae13aSMark Brown 4972a9ae13aSMark Brown msleep(500); 4982a9ae13aSMark Brown } 4992a9ae13aSMark Brown 5002a9ae13aSMark Brown /* VMID at 2*300k */ 5012a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL, 5022a9ae13aSMark Brown WM8737_VMIDSEL_MASK, 2); 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 524*85e7652dSLars-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 #ifdef CONFIG_PM 5432a9ae13aSMark Brown static int wm8737_suspend(struct snd_soc_codec *codec, pm_message_t state) 5442a9ae13aSMark Brown { 5452a9ae13aSMark Brown wm8737_set_bias_level(codec, SND_SOC_BIAS_OFF); 5462a9ae13aSMark Brown return 0; 5472a9ae13aSMark Brown } 5482a9ae13aSMark Brown 5492a9ae13aSMark Brown static int wm8737_resume(struct snd_soc_codec *codec) 5502a9ae13aSMark Brown { 5512a9ae13aSMark Brown wm8737_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 5522a9ae13aSMark Brown return 0; 5532a9ae13aSMark Brown } 5542a9ae13aSMark Brown #else 5552a9ae13aSMark Brown #define wm8737_suspend NULL 5562a9ae13aSMark Brown #define wm8737_resume NULL 5572a9ae13aSMark Brown #endif 5582a9ae13aSMark Brown 5592a9ae13aSMark Brown static int wm8737_probe(struct snd_soc_codec *codec) 5602a9ae13aSMark Brown { 5612a9ae13aSMark Brown struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); 5622a9ae13aSMark Brown int ret, i; 5632a9ae13aSMark Brown 5642a9ae13aSMark Brown ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8737->control_type); 5652a9ae13aSMark Brown if (ret != 0) { 5662a9ae13aSMark Brown dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 5672a9ae13aSMark Brown return ret; 5682a9ae13aSMark Brown } 5692a9ae13aSMark Brown 5702a9ae13aSMark Brown for (i = 0; i < ARRAY_SIZE(wm8737->supplies); i++) 5712a9ae13aSMark Brown wm8737->supplies[i].supply = wm8737_supply_names[i]; 5722a9ae13aSMark Brown 5732a9ae13aSMark Brown ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8737->supplies), 5742a9ae13aSMark Brown wm8737->supplies); 5752a9ae13aSMark Brown if (ret != 0) { 5762a9ae13aSMark Brown dev_err(codec->dev, "Failed to request supplies: %d\n", ret); 5772a9ae13aSMark Brown return ret; 5782a9ae13aSMark Brown } 5792a9ae13aSMark Brown 5802a9ae13aSMark Brown ret = regulator_bulk_enable(ARRAY_SIZE(wm8737->supplies), 5812a9ae13aSMark Brown wm8737->supplies); 5822a9ae13aSMark Brown if (ret != 0) { 5832a9ae13aSMark Brown dev_err(codec->dev, "Failed to enable supplies: %d\n", ret); 5842a9ae13aSMark Brown goto err_get; 5852a9ae13aSMark Brown } 5862a9ae13aSMark Brown 5872a9ae13aSMark Brown ret = wm8737_reset(codec); 5882a9ae13aSMark Brown if (ret < 0) { 5892a9ae13aSMark Brown dev_err(codec->dev, "Failed to issue reset\n"); 5902a9ae13aSMark Brown goto err_enable; 5912a9ae13aSMark Brown } 5922a9ae13aSMark Brown 5932a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_LEFT_PGA_VOLUME, WM8737_LVU, 5942a9ae13aSMark Brown WM8737_LVU); 5952a9ae13aSMark Brown snd_soc_update_bits(codec, WM8737_RIGHT_PGA_VOLUME, WM8737_RVU, 5962a9ae13aSMark Brown WM8737_RVU); 5972a9ae13aSMark Brown 5982a9ae13aSMark Brown wm8737_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 5992a9ae13aSMark Brown 6002a9ae13aSMark Brown /* Bias level configuration will have done an extra enable */ 6012a9ae13aSMark Brown regulator_bulk_disable(ARRAY_SIZE(wm8737->supplies), wm8737->supplies); 6022a9ae13aSMark Brown 6032a9ae13aSMark Brown snd_soc_add_controls(codec, wm8737_snd_controls, 6042a9ae13aSMark Brown ARRAY_SIZE(wm8737_snd_controls)); 6052a9ae13aSMark Brown wm8737_add_widgets(codec); 6062a9ae13aSMark Brown 6072a9ae13aSMark Brown return 0; 6082a9ae13aSMark Brown 6092a9ae13aSMark Brown err_enable: 6102a9ae13aSMark Brown regulator_bulk_disable(ARRAY_SIZE(wm8737->supplies), wm8737->supplies); 6112a9ae13aSMark Brown err_get: 6122a9ae13aSMark Brown regulator_bulk_free(ARRAY_SIZE(wm8737->supplies), wm8737->supplies); 6132a9ae13aSMark Brown 6142a9ae13aSMark Brown return ret; 6152a9ae13aSMark Brown } 6162a9ae13aSMark Brown 6172a9ae13aSMark Brown static int wm8737_remove(struct snd_soc_codec *codec) 6182a9ae13aSMark Brown { 6192a9ae13aSMark Brown struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); 6202a9ae13aSMark Brown 6212a9ae13aSMark Brown wm8737_set_bias_level(codec, SND_SOC_BIAS_OFF); 6222a9ae13aSMark Brown regulator_bulk_free(ARRAY_SIZE(wm8737->supplies), wm8737->supplies); 6232a9ae13aSMark Brown return 0; 6242a9ae13aSMark Brown } 6252a9ae13aSMark Brown 6262a9ae13aSMark Brown static struct snd_soc_codec_driver soc_codec_dev_wm8737 = { 6272a9ae13aSMark Brown .probe = wm8737_probe, 6282a9ae13aSMark Brown .remove = wm8737_remove, 6292a9ae13aSMark Brown .suspend = wm8737_suspend, 6302a9ae13aSMark Brown .resume = wm8737_resume, 6312a9ae13aSMark Brown .set_bias_level = wm8737_set_bias_level, 6322a9ae13aSMark Brown 6332a9ae13aSMark Brown .reg_cache_size = WM8737_REGISTER_COUNT - 1, /* Skip reset */ 6342a9ae13aSMark Brown .reg_word_size = sizeof(u16), 6352a9ae13aSMark Brown .reg_cache_default = wm8737_reg, 6362a9ae13aSMark Brown }; 6372a9ae13aSMark Brown 63853a5a83dSMark Brown static const struct of_device_id wm8737_of_match[] = { 63953a5a83dSMark Brown { .compatible = "wlf,wm8737", }, 64053a5a83dSMark Brown { } 64153a5a83dSMark Brown }; 64253a5a83dSMark Brown 64353a5a83dSMark Brown MODULE_DEVICE_TABLE(of, wm8737_of_match); 64453a5a83dSMark Brown 6452a9ae13aSMark Brown #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 6462a9ae13aSMark Brown static __devinit int wm8737_i2c_probe(struct i2c_client *i2c, 6472a9ae13aSMark Brown const struct i2c_device_id *id) 6482a9ae13aSMark Brown { 6492a9ae13aSMark Brown struct wm8737_priv *wm8737; 6502a9ae13aSMark Brown int ret; 6512a9ae13aSMark Brown 6522a9ae13aSMark Brown wm8737 = kzalloc(sizeof(struct wm8737_priv), GFP_KERNEL); 6532a9ae13aSMark Brown if (wm8737 == NULL) 6542a9ae13aSMark Brown return -ENOMEM; 6552a9ae13aSMark Brown 6562a9ae13aSMark Brown i2c_set_clientdata(i2c, wm8737); 6572a9ae13aSMark Brown wm8737->control_type = SND_SOC_I2C; 6582a9ae13aSMark Brown 6592a9ae13aSMark Brown ret = snd_soc_register_codec(&i2c->dev, 6602a9ae13aSMark Brown &soc_codec_dev_wm8737, &wm8737_dai, 1); 6612a9ae13aSMark Brown if (ret < 0) 6622a9ae13aSMark Brown kfree(wm8737); 6632a9ae13aSMark Brown return ret; 6642a9ae13aSMark Brown 6652a9ae13aSMark Brown } 6662a9ae13aSMark Brown 6672a9ae13aSMark Brown static __devexit int wm8737_i2c_remove(struct i2c_client *client) 6682a9ae13aSMark Brown { 6692a9ae13aSMark Brown snd_soc_unregister_codec(&client->dev); 6702a9ae13aSMark Brown kfree(i2c_get_clientdata(client)); 6712a9ae13aSMark Brown return 0; 6722a9ae13aSMark Brown } 6732a9ae13aSMark Brown 6742a9ae13aSMark Brown static const struct i2c_device_id wm8737_i2c_id[] = { 6752a9ae13aSMark Brown { "wm8737", 0 }, 6762a9ae13aSMark Brown { } 6772a9ae13aSMark Brown }; 6782a9ae13aSMark Brown MODULE_DEVICE_TABLE(i2c, wm8737_i2c_id); 6792a9ae13aSMark Brown 6802a9ae13aSMark Brown static struct i2c_driver wm8737_i2c_driver = { 6812a9ae13aSMark Brown .driver = { 6822a9ae13aSMark Brown .name = "wm8737", 6832a9ae13aSMark Brown .owner = THIS_MODULE, 68453a5a83dSMark Brown .of_match_table = wm8737_of_match, 6852a9ae13aSMark Brown }, 6862a9ae13aSMark Brown .probe = wm8737_i2c_probe, 6872a9ae13aSMark Brown .remove = __devexit_p(wm8737_i2c_remove), 6882a9ae13aSMark Brown .id_table = wm8737_i2c_id, 6892a9ae13aSMark Brown }; 6902a9ae13aSMark Brown #endif 6912a9ae13aSMark Brown 6922a9ae13aSMark Brown #if defined(CONFIG_SPI_MASTER) 6932a9ae13aSMark Brown static int __devinit wm8737_spi_probe(struct spi_device *spi) 6942a9ae13aSMark Brown { 6952a9ae13aSMark Brown struct wm8737_priv *wm8737; 6962a9ae13aSMark Brown int ret; 6972a9ae13aSMark Brown 6982a9ae13aSMark Brown wm8737 = kzalloc(sizeof(struct wm8737_priv), GFP_KERNEL); 6992a9ae13aSMark Brown if (wm8737 == NULL) 7002a9ae13aSMark Brown return -ENOMEM; 7012a9ae13aSMark Brown 7022a9ae13aSMark Brown wm8737->control_type = SND_SOC_SPI; 7032a9ae13aSMark Brown spi_set_drvdata(spi, wm8737); 7042a9ae13aSMark Brown 7052a9ae13aSMark Brown ret = snd_soc_register_codec(&spi->dev, 7062a9ae13aSMark Brown &soc_codec_dev_wm8737, &wm8737_dai, 1); 7072a9ae13aSMark Brown if (ret < 0) 7082a9ae13aSMark Brown kfree(wm8737); 7092a9ae13aSMark Brown return ret; 7102a9ae13aSMark Brown } 7112a9ae13aSMark Brown 7122a9ae13aSMark Brown static int __devexit wm8737_spi_remove(struct spi_device *spi) 7132a9ae13aSMark Brown { 7142a9ae13aSMark Brown snd_soc_unregister_codec(&spi->dev); 7152a9ae13aSMark Brown kfree(spi_get_drvdata(spi)); 7162a9ae13aSMark Brown return 0; 7172a9ae13aSMark Brown } 7182a9ae13aSMark Brown 7192a9ae13aSMark Brown static struct spi_driver wm8737_spi_driver = { 7202a9ae13aSMark Brown .driver = { 7212a9ae13aSMark Brown .name = "wm8737", 7222a9ae13aSMark Brown .owner = THIS_MODULE, 72353a5a83dSMark Brown .of_match_table = wm8737_of_match, 7242a9ae13aSMark Brown }, 7252a9ae13aSMark Brown .probe = wm8737_spi_probe, 7262a9ae13aSMark Brown .remove = __devexit_p(wm8737_spi_remove), 7272a9ae13aSMark Brown }; 7282a9ae13aSMark Brown #endif /* CONFIG_SPI_MASTER */ 7292a9ae13aSMark Brown 7302a9ae13aSMark Brown static int __init wm8737_modinit(void) 7312a9ae13aSMark Brown { 7322a9ae13aSMark Brown int ret; 7332a9ae13aSMark Brown #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 7342a9ae13aSMark Brown ret = i2c_add_driver(&wm8737_i2c_driver); 7352a9ae13aSMark Brown if (ret != 0) { 7362a9ae13aSMark Brown printk(KERN_ERR "Failed to register WM8737 I2C driver: %d\n", 7372a9ae13aSMark Brown ret); 7382a9ae13aSMark Brown } 7392a9ae13aSMark Brown #endif 7402a9ae13aSMark Brown #if defined(CONFIG_SPI_MASTER) 7412a9ae13aSMark Brown ret = spi_register_driver(&wm8737_spi_driver); 7422a9ae13aSMark Brown if (ret != 0) { 7432a9ae13aSMark Brown printk(KERN_ERR "Failed to register WM8737 SPI driver: %d\n", 7442a9ae13aSMark Brown ret); 7452a9ae13aSMark Brown } 7462a9ae13aSMark Brown #endif 7472a9ae13aSMark Brown return 0; 7482a9ae13aSMark Brown } 7492a9ae13aSMark Brown module_init(wm8737_modinit); 7502a9ae13aSMark Brown 7512a9ae13aSMark Brown static void __exit wm8737_exit(void) 7522a9ae13aSMark Brown { 7532a9ae13aSMark Brown #if defined(CONFIG_SPI_MASTER) 7542a9ae13aSMark Brown spi_unregister_driver(&wm8737_spi_driver); 7552a9ae13aSMark Brown #endif 7562a9ae13aSMark Brown #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 7572a9ae13aSMark Brown i2c_del_driver(&wm8737_i2c_driver); 7582a9ae13aSMark Brown #endif 7592a9ae13aSMark Brown } 7602a9ae13aSMark Brown module_exit(wm8737_exit); 7612a9ae13aSMark Brown 7622a9ae13aSMark Brown MODULE_DESCRIPTION("ASoC WM8737 driver"); 7632a9ae13aSMark Brown MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 7642a9ae13aSMark Brown MODULE_LICENSE("GPL"); 765