140e0aa64SRichard Purdie /* 240e0aa64SRichard Purdie * wm8731.c -- WM8731 ALSA SoC Audio driver 340e0aa64SRichard Purdie * 440e0aa64SRichard Purdie * Copyright 2005 Openedhand Ltd. 540e0aa64SRichard Purdie * 640e0aa64SRichard Purdie * Author: Richard Purdie <richard@openedhand.com> 740e0aa64SRichard Purdie * 840e0aa64SRichard Purdie * Based on wm8753.c by Liam Girdwood 940e0aa64SRichard Purdie * 1040e0aa64SRichard Purdie * This program is free software; you can redistribute it and/or modify 1140e0aa64SRichard Purdie * it under the terms of the GNU General Public License version 2 as 1240e0aa64SRichard Purdie * published by the Free Software Foundation. 1340e0aa64SRichard Purdie */ 1440e0aa64SRichard Purdie 1540e0aa64SRichard Purdie #include <linux/module.h> 1640e0aa64SRichard Purdie #include <linux/moduleparam.h> 1740e0aa64SRichard Purdie #include <linux/init.h> 1840e0aa64SRichard Purdie #include <linux/delay.h> 1940e0aa64SRichard Purdie #include <linux/pm.h> 2040e0aa64SRichard Purdie #include <linux/i2c.h> 215a0e3ad6STejun Heo #include <linux/slab.h> 2240e0aa64SRichard Purdie #include <linux/platform_device.h> 237dea7c01SMark Brown #include <linux/regulator/consumer.h> 24d2a40355SCliff Cai #include <linux/spi/spi.h> 2540e0aa64SRichard Purdie #include <sound/core.h> 2640e0aa64SRichard Purdie #include <sound/pcm.h> 2740e0aa64SRichard Purdie #include <sound/pcm_params.h> 2840e0aa64SRichard Purdie #include <sound/soc.h> 2940e0aa64SRichard Purdie #include <sound/initval.h> 30d00efa64SMark Brown #include <sound/tlv.h> 3140e0aa64SRichard Purdie 3240e0aa64SRichard Purdie #include "wm8731.h" 3340e0aa64SRichard Purdie 347dea7c01SMark Brown #define WM8731_NUM_SUPPLIES 4 357dea7c01SMark Brown static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = { 367dea7c01SMark Brown "AVDD", 377dea7c01SMark Brown "HPVDD", 387dea7c01SMark Brown "DCVDD", 397dea7c01SMark Brown "DBVDD", 407dea7c01SMark Brown }; 417dea7c01SMark Brown 42b36d61d4SFrank Mandarino /* codec private data */ 43b36d61d4SFrank Mandarino struct wm8731_priv { 44f0fba2adSLiam Girdwood enum snd_soc_control_type control_type; 457dea7c01SMark Brown struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES]; 46b36d61d4SFrank Mandarino unsigned int sysclk; 479745e824SMark Brown int sysclk_type; 48dd31b310SMark Brown int playback_fs; 49dd31b310SMark Brown bool deemph; 50b36d61d4SFrank Mandarino }; 51b36d61d4SFrank Mandarino 52a8035c8fSMark Brown 5340e0aa64SRichard Purdie /* 5440e0aa64SRichard Purdie * wm8731 register cache 5540e0aa64SRichard Purdie * We can't read the WM8731 register space when we are 5640e0aa64SRichard Purdie * using 2 wire for device control, so we cache them instead. 5740e0aa64SRichard Purdie * There is no point in caching the reset register 5840e0aa64SRichard Purdie */ 5940e0aa64SRichard Purdie static const u16 wm8731_reg[WM8731_CACHEREGNUM] = { 6040e0aa64SRichard Purdie 0x0097, 0x0097, 0x0079, 0x0079, 6140e0aa64SRichard Purdie 0x000a, 0x0008, 0x009f, 0x000a, 6240e0aa64SRichard Purdie 0x0000, 0x0000 6340e0aa64SRichard Purdie }; 6440e0aa64SRichard Purdie 6517a52fd6SMark Brown #define wm8731_reset(c) snd_soc_write(c, WM8731_RESET, 0) 6640e0aa64SRichard Purdie 6740e0aa64SRichard Purdie static const char *wm8731_input_select[] = {"Line In", "Mic"}; 6859f72970SMark Brown 6959f72970SMark Brown static const struct soc_enum wm8731_insel_enum = 7059f72970SMark Brown SOC_ENUM_SINGLE(WM8731_APANA, 2, 2, wm8731_input_select); 7159f72970SMark Brown 72dd31b310SMark Brown static int wm8731_deemph[] = { 0, 32000, 44100, 48000 }; 7359f72970SMark Brown 74dd31b310SMark Brown static int wm8731_set_deemph(struct snd_soc_codec *codec) 75dd31b310SMark Brown { 76dd31b310SMark Brown struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 77dd31b310SMark Brown int val, i, best; 78dd31b310SMark Brown 79dd31b310SMark Brown /* If we're using deemphasis select the nearest available sample 80dd31b310SMark Brown * rate. 81dd31b310SMark Brown */ 82dd31b310SMark Brown if (wm8731->deemph) { 83dd31b310SMark Brown best = 1; 84dd31b310SMark Brown for (i = 2; i < ARRAY_SIZE(wm8731_deemph); i++) { 85dd31b310SMark Brown if (abs(wm8731_deemph[i] - wm8731->playback_fs) < 86dd31b310SMark Brown abs(wm8731_deemph[best] - wm8731->playback_fs)) 87dd31b310SMark Brown best = i; 88dd31b310SMark Brown } 89dd31b310SMark Brown 90dd31b310SMark Brown val = best << 1; 91dd31b310SMark Brown } else { 92dd31b310SMark Brown best = 0; 93dd31b310SMark Brown val = 0; 94dd31b310SMark Brown } 95dd31b310SMark Brown 96dd31b310SMark Brown dev_dbg(codec->dev, "Set deemphasis %d (%dHz)\n", 97dd31b310SMark Brown best, wm8731_deemph[best]); 98dd31b310SMark Brown 99dd31b310SMark Brown return snd_soc_update_bits(codec, WM8731_APDIGI, 0x6, val); 100dd31b310SMark Brown } 101dd31b310SMark Brown 102dd31b310SMark Brown static int wm8731_get_deemph(struct snd_kcontrol *kcontrol, 103dd31b310SMark Brown struct snd_ctl_elem_value *ucontrol) 104dd31b310SMark Brown { 105dd31b310SMark Brown struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 106dd31b310SMark Brown struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 107dd31b310SMark Brown 108dd31b310SMark Brown ucontrol->value.enumerated.item[0] = wm8731->deemph; 109dd31b310SMark Brown 110dd31b310SMark Brown return 0; 111dd31b310SMark Brown } 112dd31b310SMark Brown 113dd31b310SMark Brown static int wm8731_put_deemph(struct snd_kcontrol *kcontrol, 114dd31b310SMark Brown struct snd_ctl_elem_value *ucontrol) 115dd31b310SMark Brown { 116dd31b310SMark Brown struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 117dd31b310SMark Brown struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 118dd31b310SMark Brown int deemph = ucontrol->value.enumerated.item[0]; 119dd31b310SMark Brown int ret = 0; 120dd31b310SMark Brown 121dd31b310SMark Brown if (deemph > 1) 122dd31b310SMark Brown return -EINVAL; 123dd31b310SMark Brown 124dd31b310SMark Brown mutex_lock(&codec->mutex); 125dd31b310SMark Brown if (wm8731->deemph != deemph) { 126dd31b310SMark Brown wm8731->deemph = deemph; 127dd31b310SMark Brown 128dd31b310SMark Brown wm8731_set_deemph(codec); 129dd31b310SMark Brown 130dd31b310SMark Brown ret = 1; 131dd31b310SMark Brown } 132dd31b310SMark Brown mutex_unlock(&codec->mutex); 133dd31b310SMark Brown 134dd31b310SMark Brown return ret; 135dd31b310SMark Brown } 13640e0aa64SRichard Purdie 137d00efa64SMark Brown static const DECLARE_TLV_DB_SCALE(in_tlv, -3450, 150, 0); 138d00efa64SMark Brown static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -1500, 300, 0); 139d00efa64SMark Brown static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1); 140d921184eSMark Brown static const DECLARE_TLV_DB_SCALE(mic_tlv, 0, 2000, 0); 141d00efa64SMark Brown 14240e0aa64SRichard Purdie static const struct snd_kcontrol_new wm8731_snd_controls[] = { 14340e0aa64SRichard Purdie 144d00efa64SMark Brown SOC_DOUBLE_R_TLV("Master Playback Volume", WM8731_LOUT1V, WM8731_ROUT1V, 145d00efa64SMark Brown 0, 127, 0, out_tlv), 146bd903b6eSLiam Girdwood SOC_DOUBLE_R("Master Playback ZC Switch", WM8731_LOUT1V, WM8731_ROUT1V, 147bd903b6eSLiam Girdwood 7, 1, 0), 14840e0aa64SRichard Purdie 149d00efa64SMark Brown SOC_DOUBLE_R_TLV("Capture Volume", WM8731_LINVOL, WM8731_RINVOL, 0, 31, 0, 150d00efa64SMark Brown in_tlv), 15140e0aa64SRichard Purdie SOC_DOUBLE_R("Line Capture Switch", WM8731_LINVOL, WM8731_RINVOL, 7, 1, 1), 15240e0aa64SRichard Purdie 153d921184eSMark Brown SOC_SINGLE_TLV("Mic Boost Volume", WM8731_APANA, 0, 1, 0, mic_tlv), 154ef38ed88SMark Brown SOC_SINGLE("Mic Capture Switch", WM8731_APANA, 1, 1, 1), 15540e0aa64SRichard Purdie 156d00efa64SMark Brown SOC_SINGLE_TLV("Sidetone Playback Volume", WM8731_APANA, 6, 3, 1, 157d00efa64SMark Brown sidetone_tlv), 15840e0aa64SRichard Purdie 15940e0aa64SRichard Purdie SOC_SINGLE("ADC High Pass Filter Switch", WM8731_APDIGI, 0, 1, 1), 16040e0aa64SRichard Purdie SOC_SINGLE("Store DC Offset Switch", WM8731_APDIGI, 4, 1, 0), 16140e0aa64SRichard Purdie 162dd31b310SMark Brown SOC_SINGLE_BOOL_EXT("Playback Deemphasis Switch", 0, 163dd31b310SMark Brown wm8731_get_deemph, wm8731_put_deemph), 16440e0aa64SRichard Purdie }; 16540e0aa64SRichard Purdie 16640e0aa64SRichard Purdie /* Output Mixer */ 16740e0aa64SRichard Purdie static const struct snd_kcontrol_new wm8731_output_mixer_controls[] = { 16840e0aa64SRichard Purdie SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA, 3, 1, 0), 16940e0aa64SRichard Purdie SOC_DAPM_SINGLE("Mic Sidetone Switch", WM8731_APANA, 5, 1, 0), 17040e0aa64SRichard Purdie SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731_APANA, 4, 1, 0), 17140e0aa64SRichard Purdie }; 17240e0aa64SRichard Purdie 17340e0aa64SRichard Purdie /* Input mux */ 17440e0aa64SRichard Purdie static const struct snd_kcontrol_new wm8731_input_mux_controls = 17559f72970SMark Brown SOC_DAPM_ENUM("Input Select", wm8731_insel_enum); 17640e0aa64SRichard Purdie 17740e0aa64SRichard Purdie static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = { 1789745e824SMark Brown SND_SOC_DAPM_SUPPLY("OSC", WM8731_PWR, 5, 1, NULL, 0), 17940e0aa64SRichard Purdie SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR, 4, 1, 18040e0aa64SRichard Purdie &wm8731_output_mixer_controls[0], 18140e0aa64SRichard Purdie ARRAY_SIZE(wm8731_output_mixer_controls)), 18240e0aa64SRichard Purdie SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM8731_PWR, 3, 1), 18340e0aa64SRichard Purdie SND_SOC_DAPM_OUTPUT("LOUT"), 18440e0aa64SRichard Purdie SND_SOC_DAPM_OUTPUT("LHPOUT"), 18540e0aa64SRichard Purdie SND_SOC_DAPM_OUTPUT("ROUT"), 18640e0aa64SRichard Purdie SND_SOC_DAPM_OUTPUT("RHPOUT"), 18740e0aa64SRichard Purdie SND_SOC_DAPM_ADC("ADC", "HiFi Capture", WM8731_PWR, 2, 1), 18840e0aa64SRichard Purdie SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0, &wm8731_input_mux_controls), 18940e0aa64SRichard Purdie SND_SOC_DAPM_PGA("Line Input", WM8731_PWR, 0, 1, NULL, 0), 19040e0aa64SRichard Purdie SND_SOC_DAPM_MICBIAS("Mic Bias", WM8731_PWR, 1, 1), 19140e0aa64SRichard Purdie SND_SOC_DAPM_INPUT("MICIN"), 19240e0aa64SRichard Purdie SND_SOC_DAPM_INPUT("RLINEIN"), 19340e0aa64SRichard Purdie SND_SOC_DAPM_INPUT("LLINEIN"), 19440e0aa64SRichard Purdie }; 19540e0aa64SRichard Purdie 1969745e824SMark Brown static int wm8731_check_osc(struct snd_soc_dapm_widget *source, 1979745e824SMark Brown struct snd_soc_dapm_widget *sink) 1989745e824SMark Brown { 1999745e824SMark Brown struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(source->codec); 2009745e824SMark Brown 2019745e824SMark Brown return wm8731->sysclk_type == WM8731_SYSCLK_MCLK; 2029745e824SMark Brown } 2039745e824SMark Brown 204*5e251aecSMark Brown static const struct snd_soc_dapm_route wm8731_intercon[] = { 2059745e824SMark Brown {"DAC", NULL, "OSC", wm8731_check_osc}, 2069745e824SMark Brown {"ADC", NULL, "OSC", wm8731_check_osc}, 2079745e824SMark Brown 20840e0aa64SRichard Purdie /* output mixer */ 20940e0aa64SRichard Purdie {"Output Mixer", "Line Bypass Switch", "Line Input"}, 21040e0aa64SRichard Purdie {"Output Mixer", "HiFi Playback Switch", "DAC"}, 21140e0aa64SRichard Purdie {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"}, 21240e0aa64SRichard Purdie 21340e0aa64SRichard Purdie /* outputs */ 21440e0aa64SRichard Purdie {"RHPOUT", NULL, "Output Mixer"}, 21540e0aa64SRichard Purdie {"ROUT", NULL, "Output Mixer"}, 21640e0aa64SRichard Purdie {"LHPOUT", NULL, "Output Mixer"}, 21740e0aa64SRichard Purdie {"LOUT", NULL, "Output Mixer"}, 21840e0aa64SRichard Purdie 21940e0aa64SRichard Purdie /* input mux */ 22040e0aa64SRichard Purdie {"Input Mux", "Line In", "Line Input"}, 22140e0aa64SRichard Purdie {"Input Mux", "Mic", "Mic Bias"}, 22240e0aa64SRichard Purdie {"ADC", NULL, "Input Mux"}, 22340e0aa64SRichard Purdie 22440e0aa64SRichard Purdie /* inputs */ 22540e0aa64SRichard Purdie {"Line Input", NULL, "LLINEIN"}, 22640e0aa64SRichard Purdie {"Line Input", NULL, "RLINEIN"}, 22740e0aa64SRichard Purdie {"Mic Bias", NULL, "MICIN"}, 22840e0aa64SRichard Purdie }; 22940e0aa64SRichard Purdie 23040e0aa64SRichard Purdie struct _coeff_div { 23140e0aa64SRichard Purdie u32 mclk; 23240e0aa64SRichard Purdie u32 rate; 23340e0aa64SRichard Purdie u16 fs; 23440e0aa64SRichard Purdie u8 sr:4; 23540e0aa64SRichard Purdie u8 bosr:1; 23640e0aa64SRichard Purdie u8 usb:1; 23740e0aa64SRichard Purdie }; 23840e0aa64SRichard Purdie 23940e0aa64SRichard Purdie /* codec mclk clock divider coefficients */ 24040e0aa64SRichard Purdie static const struct _coeff_div coeff_div[] = { 24140e0aa64SRichard Purdie /* 48k */ 24240e0aa64SRichard Purdie {12288000, 48000, 256, 0x0, 0x0, 0x0}, 24340e0aa64SRichard Purdie {18432000, 48000, 384, 0x0, 0x1, 0x0}, 24440e0aa64SRichard Purdie {12000000, 48000, 250, 0x0, 0x0, 0x1}, 24540e0aa64SRichard Purdie 24640e0aa64SRichard Purdie /* 32k */ 24740e0aa64SRichard Purdie {12288000, 32000, 384, 0x6, 0x0, 0x0}, 24840e0aa64SRichard Purdie {18432000, 32000, 576, 0x6, 0x1, 0x0}, 249298a2c75SFrank Mandarino {12000000, 32000, 375, 0x6, 0x0, 0x1}, 25040e0aa64SRichard Purdie 25140e0aa64SRichard Purdie /* 8k */ 25240e0aa64SRichard Purdie {12288000, 8000, 1536, 0x3, 0x0, 0x0}, 25340e0aa64SRichard Purdie {18432000, 8000, 2304, 0x3, 0x1, 0x0}, 25440e0aa64SRichard Purdie {11289600, 8000, 1408, 0xb, 0x0, 0x0}, 25540e0aa64SRichard Purdie {16934400, 8000, 2112, 0xb, 0x1, 0x0}, 25640e0aa64SRichard Purdie {12000000, 8000, 1500, 0x3, 0x0, 0x1}, 25740e0aa64SRichard Purdie 25840e0aa64SRichard Purdie /* 96k */ 25940e0aa64SRichard Purdie {12288000, 96000, 128, 0x7, 0x0, 0x0}, 26040e0aa64SRichard Purdie {18432000, 96000, 192, 0x7, 0x1, 0x0}, 26140e0aa64SRichard Purdie {12000000, 96000, 125, 0x7, 0x0, 0x1}, 26240e0aa64SRichard Purdie 26340e0aa64SRichard Purdie /* 44.1k */ 26440e0aa64SRichard Purdie {11289600, 44100, 256, 0x8, 0x0, 0x0}, 26540e0aa64SRichard Purdie {16934400, 44100, 384, 0x8, 0x1, 0x0}, 26640e0aa64SRichard Purdie {12000000, 44100, 272, 0x8, 0x1, 0x1}, 26740e0aa64SRichard Purdie 26840e0aa64SRichard Purdie /* 88.2k */ 26940e0aa64SRichard Purdie {11289600, 88200, 128, 0xf, 0x0, 0x0}, 27040e0aa64SRichard Purdie {16934400, 88200, 192, 0xf, 0x1, 0x0}, 27140e0aa64SRichard Purdie {12000000, 88200, 136, 0xf, 0x1, 0x1}, 27240e0aa64SRichard Purdie }; 27340e0aa64SRichard Purdie 27440e0aa64SRichard Purdie static inline int get_coeff(int mclk, int rate) 27540e0aa64SRichard Purdie { 27640e0aa64SRichard Purdie int i; 27740e0aa64SRichard Purdie 27840e0aa64SRichard Purdie for (i = 0; i < ARRAY_SIZE(coeff_div); i++) { 27940e0aa64SRichard Purdie if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk) 28040e0aa64SRichard Purdie return i; 28140e0aa64SRichard Purdie } 28240e0aa64SRichard Purdie return 0; 28340e0aa64SRichard Purdie } 28440e0aa64SRichard Purdie 285b36d61d4SFrank Mandarino static int wm8731_hw_params(struct snd_pcm_substream *substream, 286dee89c4dSMark Brown struct snd_pcm_hw_params *params, 287dee89c4dSMark Brown struct snd_soc_dai *dai) 28840e0aa64SRichard Purdie { 289f0fba2adSLiam Girdwood struct snd_soc_codec *codec = dai->codec; 290b2c812e2SMark Brown struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 29117a52fd6SMark Brown u16 iface = snd_soc_read(codec, WM8731_IFACE) & 0xfff3; 292b36d61d4SFrank Mandarino int i = get_coeff(wm8731->sysclk, params_rate(params)); 293b36d61d4SFrank Mandarino u16 srate = (coeff_div[i].sr << 2) | 294b36d61d4SFrank Mandarino (coeff_div[i].bosr << 1) | coeff_div[i].usb; 29540e0aa64SRichard Purdie 296dd31b310SMark Brown wm8731->playback_fs = params_rate(params); 297dd31b310SMark Brown 29817a52fd6SMark Brown snd_soc_write(codec, WM8731_SRATE, srate); 29940e0aa64SRichard Purdie 300b36d61d4SFrank Mandarino /* bit size */ 301b36d61d4SFrank Mandarino switch (params_format(params)) { 302b36d61d4SFrank Mandarino case SNDRV_PCM_FORMAT_S16_LE: 303b36d61d4SFrank Mandarino break; 304b36d61d4SFrank Mandarino case SNDRV_PCM_FORMAT_S20_3LE: 305b36d61d4SFrank Mandarino iface |= 0x0004; 306b36d61d4SFrank Mandarino break; 307b36d61d4SFrank Mandarino case SNDRV_PCM_FORMAT_S24_LE: 308b36d61d4SFrank Mandarino iface |= 0x0008; 309b36d61d4SFrank Mandarino break; 310b36d61d4SFrank Mandarino } 311b36d61d4SFrank Mandarino 312dd31b310SMark Brown wm8731_set_deemph(codec); 313dd31b310SMark Brown 31417a52fd6SMark Brown snd_soc_write(codec, WM8731_IFACE, iface); 315b36d61d4SFrank Mandarino return 0; 31640e0aa64SRichard Purdie } 31740e0aa64SRichard Purdie 318dee89c4dSMark Brown static int wm8731_pcm_prepare(struct snd_pcm_substream *substream, 319dee89c4dSMark Brown struct snd_soc_dai *dai) 32040e0aa64SRichard Purdie { 321f0fba2adSLiam Girdwood struct snd_soc_codec *codec = dai->codec; 32240e0aa64SRichard Purdie 32340e0aa64SRichard Purdie /* set active */ 32417a52fd6SMark Brown snd_soc_write(codec, WM8731_ACTIVE, 0x0001); 325b36d61d4SFrank Mandarino 32640e0aa64SRichard Purdie return 0; 32740e0aa64SRichard Purdie } 32840e0aa64SRichard Purdie 329dee89c4dSMark Brown static void wm8731_shutdown(struct snd_pcm_substream *substream, 330dee89c4dSMark Brown struct snd_soc_dai *dai) 33140e0aa64SRichard Purdie { 332f0fba2adSLiam Girdwood struct snd_soc_codec *codec = dai->codec; 33340e0aa64SRichard Purdie 33440e0aa64SRichard Purdie /* deactivate */ 33540e0aa64SRichard Purdie if (!codec->active) { 33640e0aa64SRichard Purdie udelay(50); 33717a52fd6SMark Brown snd_soc_write(codec, WM8731_ACTIVE, 0x0); 33840e0aa64SRichard Purdie } 33940e0aa64SRichard Purdie } 34040e0aa64SRichard Purdie 341e550e17fSLiam Girdwood static int wm8731_mute(struct snd_soc_dai *dai, int mute) 34240e0aa64SRichard Purdie { 343b36d61d4SFrank Mandarino struct snd_soc_codec *codec = dai->codec; 34417a52fd6SMark Brown u16 mute_reg = snd_soc_read(codec, WM8731_APDIGI) & 0xfff7; 345b36d61d4SFrank Mandarino 34640e0aa64SRichard Purdie if (mute) 34717a52fd6SMark Brown snd_soc_write(codec, WM8731_APDIGI, mute_reg | 0x8); 34840e0aa64SRichard Purdie else 34917a52fd6SMark Brown snd_soc_write(codec, WM8731_APDIGI, mute_reg); 35040e0aa64SRichard Purdie return 0; 35140e0aa64SRichard Purdie } 35240e0aa64SRichard Purdie 353e550e17fSLiam Girdwood static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai, 354b36d61d4SFrank Mandarino int clk_id, unsigned int freq, int dir) 355b36d61d4SFrank Mandarino { 356b36d61d4SFrank Mandarino struct snd_soc_codec *codec = codec_dai->codec; 357b2c812e2SMark Brown struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 358b36d61d4SFrank Mandarino 3599745e824SMark Brown switch (clk_id) { 3609745e824SMark Brown case WM8731_SYSCLK_XTAL: 3619745e824SMark Brown case WM8731_SYSCLK_MCLK: 3629745e824SMark Brown wm8731->sysclk_type = clk_id; 3639745e824SMark Brown break; 3649745e824SMark Brown default: 3659745e824SMark Brown return -EINVAL; 3669745e824SMark Brown } 3679745e824SMark Brown 368b36d61d4SFrank Mandarino switch (freq) { 369b36d61d4SFrank Mandarino case 11289600: 370b36d61d4SFrank Mandarino case 12000000: 371b36d61d4SFrank Mandarino case 12288000: 372b36d61d4SFrank Mandarino case 16934400: 373b36d61d4SFrank Mandarino case 18432000: 374b36d61d4SFrank Mandarino wm8731->sysclk = freq; 3759745e824SMark Brown break; 3769745e824SMark Brown default: 377b36d61d4SFrank Mandarino return -EINVAL; 378b36d61d4SFrank Mandarino } 379b36d61d4SFrank Mandarino 380ce6120ccSLiam Girdwood snd_soc_dapm_sync(&codec->dapm); 3819745e824SMark Brown 3829745e824SMark Brown return 0; 3839745e824SMark Brown } 3849745e824SMark Brown 385b36d61d4SFrank Mandarino 386e550e17fSLiam Girdwood static int wm8731_set_dai_fmt(struct snd_soc_dai *codec_dai, 387b36d61d4SFrank Mandarino unsigned int fmt) 388b36d61d4SFrank Mandarino { 389b36d61d4SFrank Mandarino struct snd_soc_codec *codec = codec_dai->codec; 390b36d61d4SFrank Mandarino u16 iface = 0; 391b36d61d4SFrank Mandarino 392b36d61d4SFrank Mandarino /* set master/slave audio interface */ 393b36d61d4SFrank Mandarino switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 394b36d61d4SFrank Mandarino case SND_SOC_DAIFMT_CBM_CFM: 395b36d61d4SFrank Mandarino iface |= 0x0040; 396b36d61d4SFrank Mandarino break; 397b36d61d4SFrank Mandarino case SND_SOC_DAIFMT_CBS_CFS: 398b36d61d4SFrank Mandarino break; 399b36d61d4SFrank Mandarino default: 400b36d61d4SFrank Mandarino return -EINVAL; 401b36d61d4SFrank Mandarino } 402b36d61d4SFrank Mandarino 403b36d61d4SFrank Mandarino /* interface format */ 404b36d61d4SFrank Mandarino switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 405b36d61d4SFrank Mandarino case SND_SOC_DAIFMT_I2S: 406b36d61d4SFrank Mandarino iface |= 0x0002; 407b36d61d4SFrank Mandarino break; 408b36d61d4SFrank Mandarino case SND_SOC_DAIFMT_RIGHT_J: 409b36d61d4SFrank Mandarino break; 410b36d61d4SFrank Mandarino case SND_SOC_DAIFMT_LEFT_J: 411b36d61d4SFrank Mandarino iface |= 0x0001; 412b36d61d4SFrank Mandarino break; 413b36d61d4SFrank Mandarino case SND_SOC_DAIFMT_DSP_A: 414b36d61d4SFrank Mandarino iface |= 0x0003; 415b36d61d4SFrank Mandarino break; 416b36d61d4SFrank Mandarino case SND_SOC_DAIFMT_DSP_B: 417b36d61d4SFrank Mandarino iface |= 0x0013; 418b36d61d4SFrank Mandarino break; 419b36d61d4SFrank Mandarino default: 420b36d61d4SFrank Mandarino return -EINVAL; 421b36d61d4SFrank Mandarino } 422b36d61d4SFrank Mandarino 423b36d61d4SFrank Mandarino /* clock inversion */ 424b36d61d4SFrank Mandarino switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 425b36d61d4SFrank Mandarino case SND_SOC_DAIFMT_NB_NF: 426b36d61d4SFrank Mandarino break; 427b36d61d4SFrank Mandarino case SND_SOC_DAIFMT_IB_IF: 428b36d61d4SFrank Mandarino iface |= 0x0090; 429b36d61d4SFrank Mandarino break; 430b36d61d4SFrank Mandarino case SND_SOC_DAIFMT_IB_NF: 431b36d61d4SFrank Mandarino iface |= 0x0080; 432b36d61d4SFrank Mandarino break; 433b36d61d4SFrank Mandarino case SND_SOC_DAIFMT_NB_IF: 434b36d61d4SFrank Mandarino iface |= 0x0010; 435b36d61d4SFrank Mandarino break; 436b36d61d4SFrank Mandarino default: 437b36d61d4SFrank Mandarino return -EINVAL; 438b36d61d4SFrank Mandarino } 439b36d61d4SFrank Mandarino 440b36d61d4SFrank Mandarino /* set iface */ 44117a52fd6SMark Brown snd_soc_write(codec, WM8731_IFACE, iface); 442b36d61d4SFrank Mandarino return 0; 443b36d61d4SFrank Mandarino } 444b36d61d4SFrank Mandarino 4450be9898aSMark Brown static int wm8731_set_bias_level(struct snd_soc_codec *codec, 4460be9898aSMark Brown enum snd_soc_bias_level level) 44740e0aa64SRichard Purdie { 44806ae9988SMark Brown struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 44906ae9988SMark Brown int i, ret; 45006ae9988SMark Brown u8 data[2]; 45106ae9988SMark Brown u16 *cache = codec->reg_cache; 45222d22ee5SMark Brown u16 reg; 45340e0aa64SRichard Purdie 4540be9898aSMark Brown switch (level) { 4550be9898aSMark Brown case SND_SOC_BIAS_ON: 45640e0aa64SRichard Purdie break; 4570be9898aSMark Brown case SND_SOC_BIAS_PREPARE: 45840e0aa64SRichard Purdie break; 4590be9898aSMark Brown case SND_SOC_BIAS_STANDBY: 460ce6120ccSLiam Girdwood if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 46106ae9988SMark Brown ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies), 46206ae9988SMark Brown wm8731->supplies); 46306ae9988SMark Brown if (ret != 0) 46406ae9988SMark Brown return ret; 46506ae9988SMark Brown 46606ae9988SMark Brown /* Sync reg_cache with the hardware */ 46706ae9988SMark Brown for (i = 0; i < ARRAY_SIZE(wm8731_reg); i++) { 46806ae9988SMark Brown if (cache[i] == wm8731_reg[i]) 46906ae9988SMark Brown continue; 47006ae9988SMark Brown 47106ae9988SMark Brown data[0] = (i << 1) | ((cache[i] >> 8) 47206ae9988SMark Brown & 0x0001); 47306ae9988SMark Brown data[1] = cache[i] & 0x00ff; 47406ae9988SMark Brown codec->hw_write(codec->control_data, data, 2); 47506ae9988SMark Brown } 47606ae9988SMark Brown } 47706ae9988SMark Brown 47822d22ee5SMark Brown /* Clear PWROFF, gate CLKOUT, everything else as-is */ 47917a52fd6SMark Brown reg = snd_soc_read(codec, WM8731_PWR) & 0xff7f; 48017a52fd6SMark Brown snd_soc_write(codec, WM8731_PWR, reg | 0x0040); 48140e0aa64SRichard Purdie break; 4820be9898aSMark Brown case SND_SOC_BIAS_OFF: 48317a52fd6SMark Brown snd_soc_write(codec, WM8731_ACTIVE, 0x0); 48417a52fd6SMark Brown snd_soc_write(codec, WM8731_PWR, 0xffff); 48506ae9988SMark Brown regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), 48606ae9988SMark Brown wm8731->supplies); 48740e0aa64SRichard Purdie break; 48840e0aa64SRichard Purdie } 489ce6120ccSLiam Girdwood codec->dapm.bias_level = level; 49040e0aa64SRichard Purdie return 0; 49140e0aa64SRichard Purdie } 49240e0aa64SRichard Purdie 493e135443eSBill Gatliff #define WM8731_RATES SNDRV_PCM_RATE_8000_96000 494b36d61d4SFrank Mandarino 495b36d61d4SFrank Mandarino #define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 496b36d61d4SFrank Mandarino SNDRV_PCM_FMTBIT_S24_LE) 497b36d61d4SFrank Mandarino 4986335d055SEric Miao static struct snd_soc_dai_ops wm8731_dai_ops = { 4996335d055SEric Miao .prepare = wm8731_pcm_prepare, 5006335d055SEric Miao .hw_params = wm8731_hw_params, 5016335d055SEric Miao .shutdown = wm8731_shutdown, 5026335d055SEric Miao .digital_mute = wm8731_mute, 5036335d055SEric Miao .set_sysclk = wm8731_set_dai_sysclk, 5046335d055SEric Miao .set_fmt = wm8731_set_dai_fmt, 5056335d055SEric Miao }; 5066335d055SEric Miao 507f0fba2adSLiam Girdwood static struct snd_soc_dai_driver wm8731_dai = { 508f0fba2adSLiam Girdwood .name = "wm8731-hifi", 50940e0aa64SRichard Purdie .playback = { 51040e0aa64SRichard Purdie .stream_name = "Playback", 51140e0aa64SRichard Purdie .channels_min = 1, 51240e0aa64SRichard Purdie .channels_max = 2, 513b36d61d4SFrank Mandarino .rates = WM8731_RATES, 514b36d61d4SFrank Mandarino .formats = WM8731_FORMATS,}, 51540e0aa64SRichard Purdie .capture = { 51640e0aa64SRichard Purdie .stream_name = "Capture", 51740e0aa64SRichard Purdie .channels_min = 1, 51840e0aa64SRichard Purdie .channels_max = 2, 519b36d61d4SFrank Mandarino .rates = WM8731_RATES, 520b36d61d4SFrank Mandarino .formats = WM8731_FORMATS,}, 5216335d055SEric Miao .ops = &wm8731_dai_ops, 5224934482dSMark Brown .symmetric_rates = 1, 52340e0aa64SRichard Purdie }; 52440e0aa64SRichard Purdie 525b3b50b3fSMark Brown #ifdef CONFIG_PM 526f0fba2adSLiam Girdwood static int wm8731_suspend(struct snd_soc_codec *codec, pm_message_t state) 52740e0aa64SRichard Purdie { 5280be9898aSMark Brown wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF); 52906ae9988SMark Brown 53040e0aa64SRichard Purdie return 0; 53140e0aa64SRichard Purdie } 53240e0aa64SRichard Purdie 533f0fba2adSLiam Girdwood static int wm8731_resume(struct snd_soc_codec *codec) 53440e0aa64SRichard Purdie { 5350be9898aSMark Brown wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 5367dea7c01SMark Brown 53740e0aa64SRichard Purdie return 0; 53840e0aa64SRichard Purdie } 539b3b50b3fSMark Brown #else 540b3b50b3fSMark Brown #define wm8731_suspend NULL 541b3b50b3fSMark Brown #define wm8731_resume NULL 542b3b50b3fSMark Brown #endif 54340e0aa64SRichard Purdie 544f0fba2adSLiam Girdwood static int wm8731_probe(struct snd_soc_codec *codec) 54540e0aa64SRichard Purdie { 546f0fba2adSLiam Girdwood struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 547f0fba2adSLiam Girdwood int ret = 0, i; 54840e0aa64SRichard Purdie 549f0fba2adSLiam Girdwood ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8731->control_type); 55017a52fd6SMark Brown if (ret < 0) { 55117a52fd6SMark Brown dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 552f0fba2adSLiam Girdwood return ret; 55317a52fd6SMark Brown } 55417a52fd6SMark Brown 5557dea7c01SMark Brown for (i = 0; i < ARRAY_SIZE(wm8731->supplies); i++) 5567dea7c01SMark Brown wm8731->supplies[i].supply = wm8731_supply_names[i]; 5577dea7c01SMark Brown 5587dea7c01SMark Brown ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8731->supplies), 5597dea7c01SMark Brown wm8731->supplies); 5607dea7c01SMark Brown if (ret != 0) { 5617dea7c01SMark Brown dev_err(codec->dev, "Failed to request supplies: %d\n", ret); 562f0fba2adSLiam Girdwood return ret; 5637dea7c01SMark Brown } 5647dea7c01SMark Brown 5657dea7c01SMark Brown ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies), 5667dea7c01SMark Brown wm8731->supplies); 5677dea7c01SMark Brown if (ret != 0) { 5687dea7c01SMark Brown dev_err(codec->dev, "Failed to enable supplies: %d\n", ret); 5697dea7c01SMark Brown goto err_regulator_get; 5707dea7c01SMark Brown } 5717dea7c01SMark Brown 572519cf2dfSMark Brown ret = wm8731_reset(codec); 573519cf2dfSMark Brown if (ret < 0) { 574fe5422fcSMark Brown dev_err(codec->dev, "Failed to issue reset: %d\n", ret); 5757dea7c01SMark Brown goto err_regulator_enable; 576519cf2dfSMark Brown } 577519cf2dfSMark Brown 5785998102bSMark Brown wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 5795998102bSMark Brown 5805998102bSMark Brown /* Latch the update bits */ 58117a52fd6SMark Brown snd_soc_update_bits(codec, WM8731_LOUT1V, 0x100, 0); 58217a52fd6SMark Brown snd_soc_update_bits(codec, WM8731_ROUT1V, 0x100, 0); 58317a52fd6SMark Brown snd_soc_update_bits(codec, WM8731_LINVOL, 0x100, 0); 58417a52fd6SMark Brown snd_soc_update_bits(codec, WM8731_RINVOL, 0x100, 0); 5855998102bSMark Brown 586ce3bdaa8SMark Brown /* Disable bypass path by default */ 5872062ea52SDimitris Papastamos snd_soc_update_bits(codec, WM8731_APANA, 0x8, 0); 588ce3bdaa8SMark Brown 589f0fba2adSLiam Girdwood snd_soc_add_controls(codec, wm8731_snd_controls, 590f0fba2adSLiam Girdwood ARRAY_SIZE(wm8731_snd_controls)); 5915998102bSMark Brown 59206ae9988SMark Brown /* Regulators will have been enabled by bias management */ 59306ae9988SMark Brown regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); 59406ae9988SMark Brown 595a8035c8fSMark Brown return 0; 596fe5422fcSMark Brown 5977dea7c01SMark Brown err_regulator_enable: 5987dea7c01SMark Brown regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); 5997dea7c01SMark Brown err_regulator_get: 6007dea7c01SMark Brown regulator_bulk_free(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); 601f0fba2adSLiam Girdwood 602fe5422fcSMark Brown return ret; 603a8035c8fSMark Brown } 604a8035c8fSMark Brown 605f0fba2adSLiam Girdwood /* power down chip */ 606f0fba2adSLiam Girdwood static int wm8731_remove(struct snd_soc_codec *codec) 6075998102bSMark Brown { 608f0fba2adSLiam Girdwood struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 609f0fba2adSLiam Girdwood 610f0fba2adSLiam Girdwood wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF); 611f0fba2adSLiam Girdwood 612f0fba2adSLiam Girdwood regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); 6137dea7c01SMark Brown regulator_bulk_free(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); 614f0fba2adSLiam Girdwood 615f0fba2adSLiam Girdwood return 0; 6165998102bSMark Brown } 617a8035c8fSMark Brown 618f0fba2adSLiam Girdwood static struct snd_soc_codec_driver soc_codec_dev_wm8731 = { 619f0fba2adSLiam Girdwood .probe = wm8731_probe, 620f0fba2adSLiam Girdwood .remove = wm8731_remove, 621f0fba2adSLiam Girdwood .suspend = wm8731_suspend, 622f0fba2adSLiam Girdwood .resume = wm8731_resume, 623f0fba2adSLiam Girdwood .set_bias_level = wm8731_set_bias_level, 624e5eec34cSDimitris Papastamos .reg_cache_size = ARRAY_SIZE(wm8731_reg), 625f0fba2adSLiam Girdwood .reg_word_size = sizeof(u16), 626f0fba2adSLiam Girdwood .reg_cache_default = wm8731_reg, 627*5e251aecSMark Brown .dapm_widgets = wm8731_dapm_widgets, 628*5e251aecSMark Brown .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets), 629*5e251aecSMark Brown .dapm_routes = wm8731_intercon, 630*5e251aecSMark Brown .num_dapm_routes = ARRAY_SIZE(wm8731_intercon), 631f0fba2adSLiam Girdwood }; 632f0fba2adSLiam Girdwood 6335998102bSMark Brown #if defined(CONFIG_SPI_MASTER) 6345998102bSMark Brown static int __devinit wm8731_spi_probe(struct spi_device *spi) 6355998102bSMark Brown { 6365998102bSMark Brown struct wm8731_priv *wm8731; 637f0fba2adSLiam Girdwood int ret; 6385998102bSMark Brown 6395998102bSMark Brown wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL); 6405998102bSMark Brown if (wm8731 == NULL) 6415998102bSMark Brown return -ENOMEM; 6425998102bSMark Brown 643f0fba2adSLiam Girdwood wm8731->control_type = SND_SOC_SPI; 644f0fba2adSLiam Girdwood spi_set_drvdata(spi, wm8731); 6455998102bSMark Brown 646f0fba2adSLiam Girdwood ret = snd_soc_register_codec(&spi->dev, 647f0fba2adSLiam Girdwood &soc_codec_dev_wm8731, &wm8731_dai, 1); 648f0fba2adSLiam Girdwood if (ret < 0) 649f0fba2adSLiam Girdwood kfree(wm8731); 650f0fba2adSLiam Girdwood return ret; 6515998102bSMark Brown } 6525998102bSMark Brown 6535998102bSMark Brown static int __devexit wm8731_spi_remove(struct spi_device *spi) 6545998102bSMark Brown { 655f0fba2adSLiam Girdwood snd_soc_unregister_codec(&spi->dev); 656f0fba2adSLiam Girdwood kfree(spi_get_drvdata(spi)); 6575998102bSMark Brown return 0; 6585998102bSMark Brown } 6595998102bSMark Brown 6605998102bSMark Brown static struct spi_driver wm8731_spi_driver = { 6615998102bSMark Brown .driver = { 662f0fba2adSLiam Girdwood .name = "wm8731-codec", 6635998102bSMark Brown .owner = THIS_MODULE, 6645998102bSMark Brown }, 6655998102bSMark Brown .probe = wm8731_spi_probe, 6665998102bSMark Brown .remove = __devexit_p(wm8731_spi_remove), 6675998102bSMark Brown }; 668a8035c8fSMark Brown #endif /* CONFIG_SPI_MASTER */ 669a8035c8fSMark Brown 670a8035c8fSMark Brown #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 671c6f29811SMark Brown static __devinit int wm8731_i2c_probe(struct i2c_client *i2c, 672a8035c8fSMark Brown const struct i2c_device_id *id) 673a8035c8fSMark Brown { 6745998102bSMark Brown struct wm8731_priv *wm8731; 675f0fba2adSLiam Girdwood int ret; 676a8035c8fSMark Brown 6775998102bSMark Brown wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL); 6785998102bSMark Brown if (wm8731 == NULL) 6795998102bSMark Brown return -ENOMEM; 6805998102bSMark Brown 6815998102bSMark Brown i2c_set_clientdata(i2c, wm8731); 682f0fba2adSLiam Girdwood wm8731->control_type = SND_SOC_I2C; 683a8035c8fSMark Brown 684f0fba2adSLiam Girdwood ret = snd_soc_register_codec(&i2c->dev, 685f0fba2adSLiam Girdwood &soc_codec_dev_wm8731, &wm8731_dai, 1); 686f0fba2adSLiam Girdwood if (ret < 0) 687f0fba2adSLiam Girdwood kfree(wm8731); 688f0fba2adSLiam Girdwood return ret; 689a8035c8fSMark Brown } 690a8035c8fSMark Brown 691c6f29811SMark Brown static __devexit int wm8731_i2c_remove(struct i2c_client *client) 692a8035c8fSMark Brown { 693f0fba2adSLiam Girdwood snd_soc_unregister_codec(&client->dev); 694f0fba2adSLiam Girdwood kfree(i2c_get_clientdata(client)); 695a8035c8fSMark Brown return 0; 696a8035c8fSMark Brown } 697a8035c8fSMark Brown 698a8035c8fSMark Brown static const struct i2c_device_id wm8731_i2c_id[] = { 699a8035c8fSMark Brown { "wm8731", 0 }, 700a8035c8fSMark Brown { } 701a8035c8fSMark Brown }; 702a8035c8fSMark Brown MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id); 703a8035c8fSMark Brown 704a8035c8fSMark Brown static struct i2c_driver wm8731_i2c_driver = { 705a8035c8fSMark Brown .driver = { 706f0fba2adSLiam Girdwood .name = "wm8731-codec", 707a8035c8fSMark Brown .owner = THIS_MODULE, 708a8035c8fSMark Brown }, 709a8035c8fSMark Brown .probe = wm8731_i2c_probe, 710c6f29811SMark Brown .remove = __devexit_p(wm8731_i2c_remove), 711a8035c8fSMark Brown .id_table = wm8731_i2c_id, 712a8035c8fSMark Brown }; 713a8035c8fSMark Brown #endif 714a8035c8fSMark Brown 715c9b3a40fSTakashi Iwai static int __init wm8731_modinit(void) 71664089b84SMark Brown { 717f0fba2adSLiam Girdwood int ret = 0; 7185998102bSMark Brown #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 7195998102bSMark Brown ret = i2c_add_driver(&wm8731_i2c_driver); 7205998102bSMark Brown if (ret != 0) { 7215998102bSMark Brown printk(KERN_ERR "Failed to register WM8731 I2C driver: %d\n", 7225998102bSMark Brown ret); 7235998102bSMark Brown } 7245998102bSMark Brown #endif 7255998102bSMark Brown #if defined(CONFIG_SPI_MASTER) 7265998102bSMark Brown ret = spi_register_driver(&wm8731_spi_driver); 7275998102bSMark Brown if (ret != 0) { 7285998102bSMark Brown printk(KERN_ERR "Failed to register WM8731 SPI driver: %d\n", 7295998102bSMark Brown ret); 7305998102bSMark Brown } 7315998102bSMark Brown #endif 732f0fba2adSLiam Girdwood return ret; 73364089b84SMark Brown } 73464089b84SMark Brown module_init(wm8731_modinit); 73564089b84SMark Brown 73664089b84SMark Brown static void __exit wm8731_exit(void) 73764089b84SMark Brown { 7385998102bSMark Brown #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 7395998102bSMark Brown i2c_del_driver(&wm8731_i2c_driver); 7405998102bSMark Brown #endif 7415998102bSMark Brown #if defined(CONFIG_SPI_MASTER) 7425998102bSMark Brown spi_unregister_driver(&wm8731_spi_driver); 7435998102bSMark Brown #endif 74464089b84SMark Brown } 74564089b84SMark Brown module_exit(wm8731_exit); 74664089b84SMark Brown 74740e0aa64SRichard Purdie MODULE_DESCRIPTION("ASoC WM8731 driver"); 74840e0aa64SRichard Purdie MODULE_AUTHOR("Richard Purdie"); 74940e0aa64SRichard Purdie MODULE_LICENSE("GPL"); 750