blob: 915ea11ad4b6337f73bf85e9536a27c7d7fa45f1 [file] [log] [blame]
Richard Purdie40e0aa62006-10-06 18:36:07 +02001/*
2 * wm8731.c -- WM8731 ALSA SoC Audio driver
3 *
4 * Copyright 2005 Openedhand Ltd.
Mark Brown656baae2012-05-23 12:39:07 +01005 * Copyright 2006-12 Wolfson Microelectronics, plc
Richard Purdie40e0aa62006-10-06 18:36:07 +02006 *
7 * Author: Richard Purdie <richard@openedhand.com>
8 *
9 * Based on wm8753.c by Liam Girdwood
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include <linux/module.h>
17#include <linux/moduleparam.h>
18#include <linux/init.h>
19#include <linux/delay.h>
20#include <linux/pm.h>
21#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Mark Brown05d448e2011-11-21 12:10:03 +000023#include <linux/regmap.h>
Mark Brown7dea7c02009-10-26 15:20:17 +000024#include <linux/regulator/consumer.h>
Cliff Caid2a40352008-09-01 18:47:03 +010025#include <linux/spi/spi.h>
Mark Browna7f96e42011-07-26 21:00:13 +010026#include <linux/of_device.h>
Lars-Peter Clausena51ff302014-11-09 17:01:00 +010027#include <linux/mutex.h>
Songjun Wu99d42232015-03-12 10:17:11 +080028#include <linux/clk.h>
Richard Purdie40e0aa62006-10-06 18:36:07 +020029#include <sound/core.h>
30#include <sound/pcm.h>
31#include <sound/pcm_params.h>
32#include <sound/soc.h>
Richard Purdie40e0aa62006-10-06 18:36:07 +020033#include <sound/initval.h>
Mark Brownd00efa62009-07-08 16:53:12 +010034#include <sound/tlv.h>
Richard Purdie40e0aa62006-10-06 18:36:07 +020035
36#include "wm8731.h"
37
Mark Brown7dea7c02009-10-26 15:20:17 +000038#define WM8731_NUM_SUPPLIES 4
39static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = {
40 "AVDD",
41 "HPVDD",
42 "DCVDD",
43 "DBVDD",
44};
45
Frank Mandarinob36d61d2007-02-02 17:14:56 +010046/* codec private data */
47struct wm8731_priv {
Mark Brown05d448e2011-11-21 12:10:03 +000048 struct regmap *regmap;
Songjun Wu99d42232015-03-12 10:17:11 +080049 struct clk *mclk;
Mark Brown7dea7c02009-10-26 15:20:17 +000050 struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES];
Richard Genoud0890c2b2013-07-30 11:59:45 +020051 const struct snd_pcm_hw_constraint_list *constraints;
Frank Mandarinob36d61d2007-02-02 17:14:56 +010052 unsigned int sysclk;
Mark Brown9745e822010-08-17 23:40:24 +010053 int sysclk_type;
Mark Browndd31b312010-12-02 11:44:00 +000054 int playback_fs;
55 bool deemph;
Lars-Peter Clausena51ff302014-11-09 17:01:00 +010056
57 struct mutex lock;
Frank Mandarinob36d61d2007-02-02 17:14:56 +010058};
59
Mark Browna8035c82009-02-16 19:35:43 +000060
Richard Purdie40e0aa62006-10-06 18:36:07 +020061/*
62 * wm8731 register cache
Richard Purdie40e0aa62006-10-06 18:36:07 +020063 */
Mark Brown05d448e2011-11-21 12:10:03 +000064static const struct reg_default wm8731_reg_defaults[] = {
65 { 0, 0x0097 },
66 { 1, 0x0097 },
67 { 2, 0x0079 },
68 { 3, 0x0079 },
69 { 4, 0x000a },
70 { 5, 0x0008 },
71 { 6, 0x009f },
72 { 7, 0x000a },
73 { 8, 0x0000 },
74 { 9, 0x0000 },
Richard Purdie40e0aa62006-10-06 18:36:07 +020075};
76
Mark Brown05d448e2011-11-21 12:10:03 +000077static bool wm8731_volatile(struct device *dev, unsigned int reg)
78{
79 return reg == WM8731_RESET;
80}
81
82static bool wm8731_writeable(struct device *dev, unsigned int reg)
83{
84 return reg <= WM8731_RESET;
85}
86
Mark Brown17a52fd2009-07-05 17:24:50 +010087#define wm8731_reset(c) snd_soc_write(c, WM8731_RESET, 0)
Richard Purdie40e0aa62006-10-06 18:36:07 +020088
89static const char *wm8731_input_select[] = {"Line In", "Mic"};
Mark Brown59f72972010-11-30 21:03:44 +000090
Takashi Iwai9e74b142014-02-18 10:36:16 +010091static SOC_ENUM_SINGLE_DECL(wm8731_insel_enum,
92 WM8731_APANA, 2, wm8731_input_select);
Mark Brown59f72972010-11-30 21:03:44 +000093
Mark Browndd31b312010-12-02 11:44:00 +000094static int wm8731_deemph[] = { 0, 32000, 44100, 48000 };
Mark Brown59f72972010-11-30 21:03:44 +000095
Mark Browndd31b312010-12-02 11:44:00 +000096static int wm8731_set_deemph(struct snd_soc_codec *codec)
97{
98 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
99 int val, i, best;
100
101 /* If we're using deemphasis select the nearest available sample
102 * rate.
103 */
104 if (wm8731->deemph) {
105 best = 1;
106 for (i = 2; i < ARRAY_SIZE(wm8731_deemph); i++) {
107 if (abs(wm8731_deemph[i] - wm8731->playback_fs) <
108 abs(wm8731_deemph[best] - wm8731->playback_fs))
109 best = i;
110 }
111
112 val = best << 1;
113 } else {
114 best = 0;
115 val = 0;
116 }
117
118 dev_dbg(codec->dev, "Set deemphasis %d (%dHz)\n",
119 best, wm8731_deemph[best]);
120
121 return snd_soc_update_bits(codec, WM8731_APDIGI, 0x6, val);
122}
123
124static int wm8731_get_deemph(struct snd_kcontrol *kcontrol,
125 struct snd_ctl_elem_value *ucontrol)
126{
Lars-Peter Clausenea53bf72014-03-18 09:02:04 +0100127 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
Mark Browndd31b312010-12-02 11:44:00 +0000128 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
129
Takashi Iwaibd140162015-03-10 12:39:10 +0100130 ucontrol->value.integer.value[0] = wm8731->deemph;
Mark Browndd31b312010-12-02 11:44:00 +0000131
132 return 0;
133}
134
135static int wm8731_put_deemph(struct snd_kcontrol *kcontrol,
136 struct snd_ctl_elem_value *ucontrol)
137{
Lars-Peter Clausenea53bf72014-03-18 09:02:04 +0100138 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
Mark Browndd31b312010-12-02 11:44:00 +0000139 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
Takashi Iwaibd140162015-03-10 12:39:10 +0100140 int deemph = ucontrol->value.integer.value[0];
Mark Browndd31b312010-12-02 11:44:00 +0000141 int ret = 0;
142
143 if (deemph > 1)
144 return -EINVAL;
145
Lars-Peter Clausena51ff302014-11-09 17:01:00 +0100146 mutex_lock(&wm8731->lock);
Mark Browndd31b312010-12-02 11:44:00 +0000147 if (wm8731->deemph != deemph) {
148 wm8731->deemph = deemph;
149
150 wm8731_set_deemph(codec);
151
152 ret = 1;
153 }
Lars-Peter Clausena51ff302014-11-09 17:01:00 +0100154 mutex_unlock(&wm8731->lock);
Mark Browndd31b312010-12-02 11:44:00 +0000155
156 return ret;
157}
Richard Purdie40e0aa62006-10-06 18:36:07 +0200158
Mark Brownd00efa62009-07-08 16:53:12 +0100159static const DECLARE_TLV_DB_SCALE(in_tlv, -3450, 150, 0);
160static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -1500, 300, 0);
161static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1);
Mark Brownd9211842010-11-30 21:03:09 +0000162static const DECLARE_TLV_DB_SCALE(mic_tlv, 0, 2000, 0);
Mark Brownd00efa62009-07-08 16:53:12 +0100163
Richard Purdie40e0aa62006-10-06 18:36:07 +0200164static const struct snd_kcontrol_new wm8731_snd_controls[] = {
165
Mark Brownd00efa62009-07-08 16:53:12 +0100166SOC_DOUBLE_R_TLV("Master Playback Volume", WM8731_LOUT1V, WM8731_ROUT1V,
167 0, 127, 0, out_tlv),
Liam Girdwoodbd903b62006-11-09 16:35:01 +0100168SOC_DOUBLE_R("Master Playback ZC Switch", WM8731_LOUT1V, WM8731_ROUT1V,
169 7, 1, 0),
Richard Purdie40e0aa62006-10-06 18:36:07 +0200170
Mark Brownd00efa62009-07-08 16:53:12 +0100171SOC_DOUBLE_R_TLV("Capture Volume", WM8731_LINVOL, WM8731_RINVOL, 0, 31, 0,
172 in_tlv),
Richard Purdie40e0aa62006-10-06 18:36:07 +0200173SOC_DOUBLE_R("Line Capture Switch", WM8731_LINVOL, WM8731_RINVOL, 7, 1, 1),
174
Mark Brownd9211842010-11-30 21:03:09 +0000175SOC_SINGLE_TLV("Mic Boost Volume", WM8731_APANA, 0, 1, 0, mic_tlv),
Mark Brownef38ed82009-07-08 17:05:43 +0100176SOC_SINGLE("Mic Capture Switch", WM8731_APANA, 1, 1, 1),
Richard Purdie40e0aa62006-10-06 18:36:07 +0200177
Mark Brownd00efa62009-07-08 16:53:12 +0100178SOC_SINGLE_TLV("Sidetone Playback Volume", WM8731_APANA, 6, 3, 1,
179 sidetone_tlv),
Richard Purdie40e0aa62006-10-06 18:36:07 +0200180
181SOC_SINGLE("ADC High Pass Filter Switch", WM8731_APDIGI, 0, 1, 1),
182SOC_SINGLE("Store DC Offset Switch", WM8731_APDIGI, 4, 1, 0),
183
Mark Browndd31b312010-12-02 11:44:00 +0000184SOC_SINGLE_BOOL_EXT("Playback Deemphasis Switch", 0,
185 wm8731_get_deemph, wm8731_put_deemph),
Richard Purdie40e0aa62006-10-06 18:36:07 +0200186};
187
Richard Purdie40e0aa62006-10-06 18:36:07 +0200188/* Output Mixer */
189static const struct snd_kcontrol_new wm8731_output_mixer_controls[] = {
190SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA, 3, 1, 0),
191SOC_DAPM_SINGLE("Mic Sidetone Switch", WM8731_APANA, 5, 1, 0),
192SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731_APANA, 4, 1, 0),
193};
194
195/* Input mux */
196static const struct snd_kcontrol_new wm8731_input_mux_controls =
Mark Brown59f72972010-11-30 21:03:44 +0000197SOC_DAPM_ENUM("Input Select", wm8731_insel_enum);
Richard Purdie40e0aa62006-10-06 18:36:07 +0200198
199static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = {
Mark Brown8a27bd92011-07-04 10:27:51 -0700200SND_SOC_DAPM_SUPPLY("ACTIVE",WM8731_ACTIVE, 0, 0, NULL, 0),
Mark Brown9745e822010-08-17 23:40:24 +0100201SND_SOC_DAPM_SUPPLY("OSC", WM8731_PWR, 5, 1, NULL, 0),
Richard Purdie40e0aa62006-10-06 18:36:07 +0200202SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR, 4, 1,
203 &wm8731_output_mixer_controls[0],
204 ARRAY_SIZE(wm8731_output_mixer_controls)),
205SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM8731_PWR, 3, 1),
206SND_SOC_DAPM_OUTPUT("LOUT"),
207SND_SOC_DAPM_OUTPUT("LHPOUT"),
208SND_SOC_DAPM_OUTPUT("ROUT"),
209SND_SOC_DAPM_OUTPUT("RHPOUT"),
210SND_SOC_DAPM_ADC("ADC", "HiFi Capture", WM8731_PWR, 2, 1),
211SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0, &wm8731_input_mux_controls),
212SND_SOC_DAPM_PGA("Line Input", WM8731_PWR, 0, 1, NULL, 0),
213SND_SOC_DAPM_MICBIAS("Mic Bias", WM8731_PWR, 1, 1),
214SND_SOC_DAPM_INPUT("MICIN"),
215SND_SOC_DAPM_INPUT("RLINEIN"),
216SND_SOC_DAPM_INPUT("LLINEIN"),
217};
218
Mark Brown9745e822010-08-17 23:40:24 +0100219static int wm8731_check_osc(struct snd_soc_dapm_widget *source,
220 struct snd_soc_dapm_widget *sink)
221{
Lars-Peter Clausend286b802015-01-13 10:27:14 +0100222 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
223 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
Mark Brown9745e822010-08-17 23:40:24 +0100224
Nicolas Ferre5a195b42011-05-24 11:50:57 +0200225 return wm8731->sysclk_type == WM8731_SYSCLK_XTAL;
Mark Brown9745e822010-08-17 23:40:24 +0100226}
227
Mark Brown5e251ae2011-03-27 14:33:03 +0100228static const struct snd_soc_dapm_route wm8731_intercon[] = {
Mark Brown9745e822010-08-17 23:40:24 +0100229 {"DAC", NULL, "OSC", wm8731_check_osc},
230 {"ADC", NULL, "OSC", wm8731_check_osc},
Mark Brown8a27bd92011-07-04 10:27:51 -0700231 {"DAC", NULL, "ACTIVE"},
232 {"ADC", NULL, "ACTIVE"},
Mark Brown9745e822010-08-17 23:40:24 +0100233
Richard Purdie40e0aa62006-10-06 18:36:07 +0200234 /* output mixer */
235 {"Output Mixer", "Line Bypass Switch", "Line Input"},
236 {"Output Mixer", "HiFi Playback Switch", "DAC"},
237 {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},
238
239 /* outputs */
240 {"RHPOUT", NULL, "Output Mixer"},
241 {"ROUT", NULL, "Output Mixer"},
242 {"LHPOUT", NULL, "Output Mixer"},
243 {"LOUT", NULL, "Output Mixer"},
244
245 /* input mux */
246 {"Input Mux", "Line In", "Line Input"},
247 {"Input Mux", "Mic", "Mic Bias"},
248 {"ADC", NULL, "Input Mux"},
249
250 /* inputs */
251 {"Line Input", NULL, "LLINEIN"},
252 {"Line Input", NULL, "RLINEIN"},
253 {"Mic Bias", NULL, "MICIN"},
Richard Purdie40e0aa62006-10-06 18:36:07 +0200254};
255
Richard Purdie40e0aa62006-10-06 18:36:07 +0200256struct _coeff_div {
257 u32 mclk;
258 u32 rate;
259 u16 fs;
260 u8 sr:4;
261 u8 bosr:1;
262 u8 usb:1;
263};
264
265/* codec mclk clock divider coefficients */
266static const struct _coeff_div coeff_div[] = {
267 /* 48k */
268 {12288000, 48000, 256, 0x0, 0x0, 0x0},
269 {18432000, 48000, 384, 0x0, 0x1, 0x0},
270 {12000000, 48000, 250, 0x0, 0x0, 0x1},
271
272 /* 32k */
273 {12288000, 32000, 384, 0x6, 0x0, 0x0},
274 {18432000, 32000, 576, 0x6, 0x1, 0x0},
Frank Mandarino298a2c72007-01-31 10:02:56 +0100275 {12000000, 32000, 375, 0x6, 0x0, 0x1},
Richard Purdie40e0aa62006-10-06 18:36:07 +0200276
277 /* 8k */
278 {12288000, 8000, 1536, 0x3, 0x0, 0x0},
279 {18432000, 8000, 2304, 0x3, 0x1, 0x0},
280 {11289600, 8000, 1408, 0xb, 0x0, 0x0},
281 {16934400, 8000, 2112, 0xb, 0x1, 0x0},
282 {12000000, 8000, 1500, 0x3, 0x0, 0x1},
283
284 /* 96k */
285 {12288000, 96000, 128, 0x7, 0x0, 0x0},
286 {18432000, 96000, 192, 0x7, 0x1, 0x0},
287 {12000000, 96000, 125, 0x7, 0x0, 0x1},
288
289 /* 44.1k */
290 {11289600, 44100, 256, 0x8, 0x0, 0x0},
291 {16934400, 44100, 384, 0x8, 0x1, 0x0},
292 {12000000, 44100, 272, 0x8, 0x1, 0x1},
293
294 /* 88.2k */
295 {11289600, 88200, 128, 0xf, 0x0, 0x0},
296 {16934400, 88200, 192, 0xf, 0x1, 0x0},
297 {12000000, 88200, 136, 0xf, 0x1, 0x1},
298};
299
Richard Genoud0890c2b2013-07-30 11:59:45 +0200300/* rates constraints */
301static const unsigned int wm8731_rates_12000000[] = {
302 8000, 32000, 44100, 48000, 96000, 88200,
303};
304
305static const unsigned int wm8731_rates_12288000_18432000[] = {
306 8000, 32000, 48000, 96000,
307};
308
309static const unsigned int wm8731_rates_11289600_16934400[] = {
310 8000, 44100, 88200,
311};
312
313static const struct snd_pcm_hw_constraint_list wm8731_constraints_12000000 = {
314 .list = wm8731_rates_12000000,
315 .count = ARRAY_SIZE(wm8731_rates_12000000),
316};
317
318static const
319struct snd_pcm_hw_constraint_list wm8731_constraints_12288000_18432000 = {
320 .list = wm8731_rates_12288000_18432000,
321 .count = ARRAY_SIZE(wm8731_rates_12288000_18432000),
322};
323
324static const
325struct snd_pcm_hw_constraint_list wm8731_constraints_11289600_16934400 = {
326 .list = wm8731_rates_11289600_16934400,
327 .count = ARRAY_SIZE(wm8731_rates_11289600_16934400),
328};
329
Richard Purdie40e0aa62006-10-06 18:36:07 +0200330static inline int get_coeff(int mclk, int rate)
331{
332 int i;
333
334 for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
335 if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk)
336 return i;
337 }
338 return 0;
339}
340
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100341static int wm8731_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000342 struct snd_pcm_hw_params *params,
343 struct snd_soc_dai *dai)
Richard Purdie40e0aa62006-10-06 18:36:07 +0200344{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000345 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900346 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
Mark Brown17a52fd2009-07-05 17:24:50 +0100347 u16 iface = snd_soc_read(codec, WM8731_IFACE) & 0xfff3;
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100348 int i = get_coeff(wm8731->sysclk, params_rate(params));
349 u16 srate = (coeff_div[i].sr << 2) |
350 (coeff_div[i].bosr << 1) | coeff_div[i].usb;
Richard Purdie40e0aa62006-10-06 18:36:07 +0200351
Mark Browndd31b312010-12-02 11:44:00 +0000352 wm8731->playback_fs = params_rate(params);
353
Mark Brown17a52fd2009-07-05 17:24:50 +0100354 snd_soc_write(codec, WM8731_SRATE, srate);
Richard Purdie40e0aa62006-10-06 18:36:07 +0200355
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100356 /* bit size */
Mark Browndfb67782014-07-31 12:51:32 +0100357 switch (params_width(params)) {
358 case 16:
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100359 break;
Mark Browndfb67782014-07-31 12:51:32 +0100360 case 20:
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100361 iface |= 0x0004;
362 break;
Mark Browndfb67782014-07-31 12:51:32 +0100363 case 24:
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100364 iface |= 0x0008;
365 break;
366 }
367
Mark Browndd31b312010-12-02 11:44:00 +0000368 wm8731_set_deemph(codec);
369
Mark Brown17a52fd2009-07-05 17:24:50 +0100370 snd_soc_write(codec, WM8731_IFACE, iface);
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100371 return 0;
Richard Purdie40e0aa62006-10-06 18:36:07 +0200372}
373
Liam Girdwoode550e172008-07-07 16:07:52 +0100374static int wm8731_mute(struct snd_soc_dai *dai, int mute)
Richard Purdie40e0aa62006-10-06 18:36:07 +0200375{
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100376 struct snd_soc_codec *codec = dai->codec;
Mark Brown17a52fd2009-07-05 17:24:50 +0100377 u16 mute_reg = snd_soc_read(codec, WM8731_APDIGI) & 0xfff7;
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100378
Richard Purdie40e0aa62006-10-06 18:36:07 +0200379 if (mute)
Mark Brown17a52fd2009-07-05 17:24:50 +0100380 snd_soc_write(codec, WM8731_APDIGI, mute_reg | 0x8);
Richard Purdie40e0aa62006-10-06 18:36:07 +0200381 else
Mark Brown17a52fd2009-07-05 17:24:50 +0100382 snd_soc_write(codec, WM8731_APDIGI, mute_reg);
Richard Purdie40e0aa62006-10-06 18:36:07 +0200383 return 0;
384}
385
Liam Girdwoode550e172008-07-07 16:07:52 +0100386static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai,
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100387 int clk_id, unsigned int freq, int dir)
388{
389 struct snd_soc_codec *codec = codec_dai->codec;
Lars-Peter Clausenfc31fda2015-06-01 10:10:36 +0200390 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
Mark Brownb2c812e2010-04-14 15:35:19 +0900391 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100392
Mark Brown9745e822010-08-17 23:40:24 +0100393 switch (clk_id) {
394 case WM8731_SYSCLK_XTAL:
395 case WM8731_SYSCLK_MCLK:
Songjun Wu99d42232015-03-12 10:17:11 +0800396 if (wm8731->mclk && clk_set_rate(wm8731->mclk, freq))
397 return -EINVAL;
Mark Brown9745e822010-08-17 23:40:24 +0100398 wm8731->sysclk_type = clk_id;
399 break;
400 default:
401 return -EINVAL;
402 }
403
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100404 switch (freq) {
Richard Genoud0890c2b2013-07-30 11:59:45 +0200405 case 0:
406 wm8731->constraints = NULL;
407 break;
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100408 case 12000000:
Richard Genoud0890c2b2013-07-30 11:59:45 +0200409 wm8731->constraints = &wm8731_constraints_12000000;
410 break;
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100411 case 12288000:
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100412 case 18432000:
Richard Genoud0890c2b2013-07-30 11:59:45 +0200413 wm8731->constraints = &wm8731_constraints_12288000_18432000;
414 break;
415 case 16934400:
416 case 11289600:
417 wm8731->constraints = &wm8731_constraints_11289600_16934400;
Mark Brown9745e822010-08-17 23:40:24 +0100418 break;
419 default:
420 return -EINVAL;
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100421 }
Mark Brown9745e822010-08-17 23:40:24 +0100422
Richard Genoud0890c2b2013-07-30 11:59:45 +0200423 wm8731->sysclk = freq;
424
Lars-Peter Clausenfc31fda2015-06-01 10:10:36 +0200425 snd_soc_dapm_sync(dapm);
Mark Brown9745e822010-08-17 23:40:24 +0100426
427 return 0;
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100428}
429
430
Liam Girdwoode550e172008-07-07 16:07:52 +0100431static int wm8731_set_dai_fmt(struct snd_soc_dai *codec_dai,
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100432 unsigned int fmt)
433{
434 struct snd_soc_codec *codec = codec_dai->codec;
435 u16 iface = 0;
436
437 /* set master/slave audio interface */
438 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
439 case SND_SOC_DAIFMT_CBM_CFM:
440 iface |= 0x0040;
441 break;
442 case SND_SOC_DAIFMT_CBS_CFS:
443 break;
444 default:
445 return -EINVAL;
446 }
447
448 /* interface format */
449 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
450 case SND_SOC_DAIFMT_I2S:
451 iface |= 0x0002;
452 break;
453 case SND_SOC_DAIFMT_RIGHT_J:
454 break;
455 case SND_SOC_DAIFMT_LEFT_J:
456 iface |= 0x0001;
457 break;
458 case SND_SOC_DAIFMT_DSP_A:
Bo Shenb4af6ef2013-12-03 18:04:54 +0800459 iface |= 0x0013;
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100460 break;
461 case SND_SOC_DAIFMT_DSP_B:
Bo Shenb4af6ef2013-12-03 18:04:54 +0800462 iface |= 0x0003;
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100463 break;
464 default:
465 return -EINVAL;
466 }
467
468 /* clock inversion */
469 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
470 case SND_SOC_DAIFMT_NB_NF:
471 break;
472 case SND_SOC_DAIFMT_IB_IF:
473 iface |= 0x0090;
474 break;
475 case SND_SOC_DAIFMT_IB_NF:
476 iface |= 0x0080;
477 break;
478 case SND_SOC_DAIFMT_NB_IF:
479 iface |= 0x0010;
480 break;
481 default:
482 return -EINVAL;
483 }
484
485 /* set iface */
Mark Brown17a52fd2009-07-05 17:24:50 +0100486 snd_soc_write(codec, WM8731_IFACE, iface);
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100487 return 0;
488}
489
Mark Brown0be98982008-05-19 12:31:28 +0200490static int wm8731_set_bias_level(struct snd_soc_codec *codec,
491 enum snd_soc_bias_level level)
Richard Purdie40e0aa62006-10-06 18:36:07 +0200492{
Mark Brown06ae9982010-05-07 19:14:45 +0100493 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
Axel Lin9bf311f2011-10-07 21:39:09 +0800494 int ret;
Mark Brown22d22ee2009-02-16 19:20:15 +0000495 u16 reg;
Richard Purdie40e0aa62006-10-06 18:36:07 +0200496
Mark Brown0be98982008-05-19 12:31:28 +0200497 switch (level) {
498 case SND_SOC_BIAS_ON:
Songjun Wu99d42232015-03-12 10:17:11 +0800499 if (wm8731->mclk)
500 clk_prepare_enable(wm8731->mclk);
Richard Purdie40e0aa62006-10-06 18:36:07 +0200501 break;
Mark Brown0be98982008-05-19 12:31:28 +0200502 case SND_SOC_BIAS_PREPARE:
Richard Purdie40e0aa62006-10-06 18:36:07 +0200503 break;
Mark Brown0be98982008-05-19 12:31:28 +0200504 case SND_SOC_BIAS_STANDBY:
Lars-Peter Clausenfc31fda2015-06-01 10:10:36 +0200505 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
Mark Brown06ae9982010-05-07 19:14:45 +0100506 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies),
507 wm8731->supplies);
508 if (ret != 0)
509 return ret;
510
Mark Brown05d448e2011-11-21 12:10:03 +0000511 regcache_sync(wm8731->regmap);
Mark Brown06ae9982010-05-07 19:14:45 +0100512 }
513
Mark Brown22d22ee2009-02-16 19:20:15 +0000514 /* Clear PWROFF, gate CLKOUT, everything else as-is */
Mark Brown17a52fd2009-07-05 17:24:50 +0100515 reg = snd_soc_read(codec, WM8731_PWR) & 0xff7f;
516 snd_soc_write(codec, WM8731_PWR, reg | 0x0040);
Richard Purdie40e0aa62006-10-06 18:36:07 +0200517 break;
Mark Brown0be98982008-05-19 12:31:28 +0200518 case SND_SOC_BIAS_OFF:
Songjun Wu99d42232015-03-12 10:17:11 +0800519 if (wm8731->mclk)
520 clk_disable_unprepare(wm8731->mclk);
Mark Brown17a52fd2009-07-05 17:24:50 +0100521 snd_soc_write(codec, WM8731_PWR, 0xffff);
Mark Brown06ae9982010-05-07 19:14:45 +0100522 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies),
523 wm8731->supplies);
Mark Brown05d448e2011-11-21 12:10:03 +0000524 regcache_mark_dirty(wm8731->regmap);
Richard Purdie40e0aa62006-10-06 18:36:07 +0200525 break;
526 }
Richard Purdie40e0aa62006-10-06 18:36:07 +0200527 return 0;
528}
529
Richard Genoud0890c2b2013-07-30 11:59:45 +0200530static int wm8731_startup(struct snd_pcm_substream *substream,
531 struct snd_soc_dai *dai)
532{
533 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(dai->codec);
534
535 if (wm8731->constraints)
536 snd_pcm_hw_constraint_list(substream->runtime, 0,
537 SNDRV_PCM_HW_PARAM_RATE,
538 wm8731->constraints);
539
540 return 0;
541}
542
Bill Gatliffe1354432010-04-09 18:08:08 +0100543#define WM8731_RATES SNDRV_PCM_RATE_8000_96000
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100544
545#define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
546 SNDRV_PCM_FMTBIT_S24_LE)
547
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100548static const struct snd_soc_dai_ops wm8731_dai_ops = {
Richard Genoud0890c2b2013-07-30 11:59:45 +0200549 .startup = wm8731_startup,
Eric Miao6335d052009-03-03 09:41:00 +0800550 .hw_params = wm8731_hw_params,
Eric Miao6335d052009-03-03 09:41:00 +0800551 .digital_mute = wm8731_mute,
552 .set_sysclk = wm8731_set_dai_sysclk,
553 .set_fmt = wm8731_set_dai_fmt,
554};
555
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000556static struct snd_soc_dai_driver wm8731_dai = {
557 .name = "wm8731-hifi",
Richard Purdie40e0aa62006-10-06 18:36:07 +0200558 .playback = {
559 .stream_name = "Playback",
560 .channels_min = 1,
561 .channels_max = 2,
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100562 .rates = WM8731_RATES,
563 .formats = WM8731_FORMATS,},
Richard Purdie40e0aa62006-10-06 18:36:07 +0200564 .capture = {
565 .stream_name = "Capture",
566 .channels_min = 1,
567 .channels_max = 2,
Frank Mandarinob36d61d2007-02-02 17:14:56 +0100568 .rates = WM8731_RATES,
569 .formats = WM8731_FORMATS,},
Eric Miao6335d052009-03-03 09:41:00 +0800570 .ops = &wm8731_dai_ops,
Mark Brown49344822009-07-08 17:48:12 +0100571 .symmetric_rates = 1,
Richard Purdie40e0aa62006-10-06 18:36:07 +0200572};
Richard Purdie40e0aa62006-10-06 18:36:07 +0200573
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000574static int wm8731_probe(struct snd_soc_codec *codec)
Richard Purdie40e0aa62006-10-06 18:36:07 +0200575{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000576 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
577 int ret = 0, i;
Richard Purdie40e0aa62006-10-06 18:36:07 +0200578
Mark Brown7dea7c02009-10-26 15:20:17 +0000579 for (i = 0; i < ARRAY_SIZE(wm8731->supplies); i++)
580 wm8731->supplies[i].supply = wm8731_supply_names[i];
581
Fabio Estevam3598aad2014-04-24 22:27:04 -0300582 ret = devm_regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8731->supplies),
Mark Brown7dea7c02009-10-26 15:20:17 +0000583 wm8731->supplies);
584 if (ret != 0) {
585 dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000586 return ret;
Mark Brown7dea7c02009-10-26 15:20:17 +0000587 }
588
589 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies),
590 wm8731->supplies);
591 if (ret != 0) {
592 dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
Fabio Estevam3598aad2014-04-24 22:27:04 -0300593 return ret;
Mark Brown7dea7c02009-10-26 15:20:17 +0000594 }
595
Mark Brown519cf2d2009-02-18 21:06:01 +0000596 ret = wm8731_reset(codec);
597 if (ret < 0) {
Mark Brownfe5422f2009-07-05 15:18:01 +0100598 dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
Mark Brown7dea7c02009-10-26 15:20:17 +0000599 goto err_regulator_enable;
Mark Brown519cf2d2009-02-18 21:06:01 +0000600 }
601
Lars-Peter Clausenbd1204c2015-04-27 22:13:24 +0200602 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
Mark Brown59981022009-02-16 20:49:16 +0000603
604 /* Latch the update bits */
Mark Brown17a52fd2009-07-05 17:24:50 +0100605 snd_soc_update_bits(codec, WM8731_LOUT1V, 0x100, 0);
606 snd_soc_update_bits(codec, WM8731_ROUT1V, 0x100, 0);
607 snd_soc_update_bits(codec, WM8731_LINVOL, 0x100, 0);
608 snd_soc_update_bits(codec, WM8731_RINVOL, 0x100, 0);
Mark Brown59981022009-02-16 20:49:16 +0000609
Mark Brownce3bdaa2009-02-19 14:29:49 +0000610 /* Disable bypass path by default */
Dimitris Papastamos2062ea52010-12-01 09:38:55 +0000611 snd_soc_update_bits(codec, WM8731_APANA, 0x8, 0);
Mark Brownce3bdaa2009-02-19 14:29:49 +0000612
Mark Brown06ae9982010-05-07 19:14:45 +0100613 /* Regulators will have been enabled by bias management */
614 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
615
Mark Browna8035c82009-02-16 19:35:43 +0000616 return 0;
Mark Brownfe5422f2009-07-05 15:18:01 +0100617
Mark Brown7dea7c02009-10-26 15:20:17 +0000618err_regulator_enable:
619 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000620
Mark Brownfe5422f2009-07-05 15:18:01 +0100621 return ret;
Mark Browna8035c82009-02-16 19:35:43 +0000622}
623
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000624/* power down chip */
625static int wm8731_remove(struct snd_soc_codec *codec)
Mark Brown59981022009-02-16 20:49:16 +0000626{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000627 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
628
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000629 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000630
631 return 0;
Mark Brown59981022009-02-16 20:49:16 +0000632}
Mark Browna8035c82009-02-16 19:35:43 +0000633
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000634static struct snd_soc_codec_driver soc_codec_dev_wm8731 = {
635 .probe = wm8731_probe,
636 .remove = wm8731_remove,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000637 .set_bias_level = wm8731_set_bias_level,
Lars-Peter Clausen2081b2c2014-11-23 13:37:24 +0100638 .suspend_bias_off = true,
639
Mark Brown5e251ae2011-03-27 14:33:03 +0100640 .dapm_widgets = wm8731_dapm_widgets,
641 .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets),
642 .dapm_routes = wm8731_intercon,
643 .num_dapm_routes = ARRAY_SIZE(wm8731_intercon),
Mark Browncb555312011-11-21 12:59:52 +0000644 .controls = wm8731_snd_controls,
645 .num_controls = ARRAY_SIZE(wm8731_snd_controls),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000646};
647
Mark Browna7f96e42011-07-26 21:00:13 +0100648static const struct of_device_id wm8731_of_match[] = {
649 { .compatible = "wlf,wm8731", },
650 { }
651};
652
653MODULE_DEVICE_TABLE(of, wm8731_of_match);
654
Mark Brown05d448e2011-11-21 12:10:03 +0000655static const struct regmap_config wm8731_regmap = {
656 .reg_bits = 7,
657 .val_bits = 9,
658
659 .max_register = WM8731_RESET,
660 .volatile_reg = wm8731_volatile,
661 .writeable_reg = wm8731_writeable,
662
663 .cache_type = REGCACHE_RBTREE,
664 .reg_defaults = wm8731_reg_defaults,
665 .num_reg_defaults = ARRAY_SIZE(wm8731_reg_defaults),
666};
667
Mark Brown59981022009-02-16 20:49:16 +0000668#if defined(CONFIG_SPI_MASTER)
Bill Pemberton7a79e942012-12-07 09:26:37 -0500669static int wm8731_spi_probe(struct spi_device *spi)
Mark Brown59981022009-02-16 20:49:16 +0000670{
Mark Brown59981022009-02-16 20:49:16 +0000671 struct wm8731_priv *wm8731;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000672 int ret;
Mark Brown59981022009-02-16 20:49:16 +0000673
Fabio Estevamcea82d82014-10-24 13:01:27 -0200674 wm8731 = devm_kzalloc(&spi->dev, sizeof(*wm8731), GFP_KERNEL);
Mark Brown59981022009-02-16 20:49:16 +0000675 if (wm8731 == NULL)
676 return -ENOMEM;
677
Songjun Wu99d42232015-03-12 10:17:11 +0800678 wm8731->mclk = devm_clk_get(&spi->dev, "mclk");
679 if (IS_ERR(wm8731->mclk)) {
680 ret = PTR_ERR(wm8731->mclk);
681 if (ret == -ENOENT) {
682 wm8731->mclk = NULL;
683 dev_warn(&spi->dev, "Assuming static MCLK\n");
684 } else {
685 dev_err(&spi->dev, "Failed to get MCLK: %d\n",
686 ret);
687 return ret;
688 }
689 }
690
Lars-Peter Clausena51ff302014-11-09 17:01:00 +0100691 mutex_init(&wm8731->lock);
692
Mark Brownf1992dd2012-05-12 20:08:43 +0100693 wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap);
Mark Brown05d448e2011-11-21 12:10:03 +0000694 if (IS_ERR(wm8731->regmap)) {
695 ret = PTR_ERR(wm8731->regmap);
696 dev_err(&spi->dev, "Failed to allocate register map: %d\n",
697 ret);
Mark Brownf1992dd2012-05-12 20:08:43 +0100698 return ret;
Mark Brown05d448e2011-11-21 12:10:03 +0000699 }
700
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000701 spi_set_drvdata(spi, wm8731);
Mark Brown59981022009-02-16 20:49:16 +0000702
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000703 ret = snd_soc_register_codec(&spi->dev,
704 &soc_codec_dev_wm8731, &wm8731_dai, 1);
Mark Brown05d448e2011-11-21 12:10:03 +0000705 if (ret != 0) {
706 dev_err(&spi->dev, "Failed to register CODEC: %d\n", ret);
Mark Brownf1992dd2012-05-12 20:08:43 +0100707 return ret;
Mark Brown05d448e2011-11-21 12:10:03 +0000708 }
709
710 return 0;
Mark Brown59981022009-02-16 20:49:16 +0000711}
712
Bill Pemberton7a79e942012-12-07 09:26:37 -0500713static int wm8731_spi_remove(struct spi_device *spi)
Mark Brown59981022009-02-16 20:49:16 +0000714{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000715 snd_soc_unregister_codec(&spi->dev);
Mark Brown59981022009-02-16 20:49:16 +0000716 return 0;
717}
718
719static struct spi_driver wm8731_spi_driver = {
720 .driver = {
Mark Brown99b59f32011-03-27 14:35:15 +0100721 .name = "wm8731",
Mark Brown59981022009-02-16 20:49:16 +0000722 .owner = THIS_MODULE,
Mark Browna7f96e42011-07-26 21:00:13 +0100723 .of_match_table = wm8731_of_match,
Mark Brown59981022009-02-16 20:49:16 +0000724 },
725 .probe = wm8731_spi_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -0500726 .remove = wm8731_spi_remove,
Mark Brown59981022009-02-16 20:49:16 +0000727};
Mark Browna8035c82009-02-16 19:35:43 +0000728#endif /* CONFIG_SPI_MASTER */
729
Fabio Estevamb65ab732013-11-21 12:38:43 -0200730#if IS_ENABLED(CONFIG_I2C)
Bill Pemberton7a79e942012-12-07 09:26:37 -0500731static int wm8731_i2c_probe(struct i2c_client *i2c,
732 const struct i2c_device_id *id)
Mark Browna8035c82009-02-16 19:35:43 +0000733{
Mark Brown59981022009-02-16 20:49:16 +0000734 struct wm8731_priv *wm8731;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000735 int ret;
Mark Browna8035c82009-02-16 19:35:43 +0000736
Mark Brownf1992dd2012-05-12 20:08:43 +0100737 wm8731 = devm_kzalloc(&i2c->dev, sizeof(struct wm8731_priv),
738 GFP_KERNEL);
Mark Brown59981022009-02-16 20:49:16 +0000739 if (wm8731 == NULL)
740 return -ENOMEM;
741
Songjun Wu99d42232015-03-12 10:17:11 +0800742 wm8731->mclk = devm_clk_get(&i2c->dev, "mclk");
743 if (IS_ERR(wm8731->mclk)) {
744 ret = PTR_ERR(wm8731->mclk);
745 if (ret == -ENOENT) {
746 wm8731->mclk = NULL;
747 dev_warn(&i2c->dev, "Assuming static MCLK\n");
748 } else {
749 dev_err(&i2c->dev, "Failed to get MCLK: %d\n",
750 ret);
751 return ret;
752 }
753 }
754
Manuel Lauss8a6cf302015-01-19 08:23:43 +0100755 mutex_init(&wm8731->lock);
756
Mark Brownf1992dd2012-05-12 20:08:43 +0100757 wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap);
Mark Brown05d448e2011-11-21 12:10:03 +0000758 if (IS_ERR(wm8731->regmap)) {
759 ret = PTR_ERR(wm8731->regmap);
760 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
761 ret);
Mark Brownf1992dd2012-05-12 20:08:43 +0100762 return ret;
Mark Brown05d448e2011-11-21 12:10:03 +0000763 }
Mark Browna8035c82009-02-16 19:35:43 +0000764
Mark Brown05d448e2011-11-21 12:10:03 +0000765 i2c_set_clientdata(i2c, wm8731);
766
767 ret = snd_soc_register_codec(&i2c->dev,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000768 &soc_codec_dev_wm8731, &wm8731_dai, 1);
Mark Brown05d448e2011-11-21 12:10:03 +0000769 if (ret != 0) {
770 dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret);
Mark Brownf1992dd2012-05-12 20:08:43 +0100771 return ret;
Mark Brown05d448e2011-11-21 12:10:03 +0000772 }
773
774 return 0;
Mark Browna8035c82009-02-16 19:35:43 +0000775}
776
Bill Pemberton7a79e942012-12-07 09:26:37 -0500777static int wm8731_i2c_remove(struct i2c_client *client)
Mark Browna8035c82009-02-16 19:35:43 +0000778{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000779 snd_soc_unregister_codec(&client->dev);
Mark Browna8035c82009-02-16 19:35:43 +0000780 return 0;
781}
782
783static const struct i2c_device_id wm8731_i2c_id[] = {
784 { "wm8731", 0 },
785 { }
786};
787MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id);
788
789static struct i2c_driver wm8731_i2c_driver = {
790 .driver = {
Mark Brown99b59f32011-03-27 14:35:15 +0100791 .name = "wm8731",
Mark Browna8035c82009-02-16 19:35:43 +0000792 .owner = THIS_MODULE,
Mark Browna7f96e42011-07-26 21:00:13 +0100793 .of_match_table = wm8731_of_match,
Mark Browna8035c82009-02-16 19:35:43 +0000794 },
795 .probe = wm8731_i2c_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -0500796 .remove = wm8731_i2c_remove,
Mark Browna8035c82009-02-16 19:35:43 +0000797 .id_table = wm8731_i2c_id,
798};
799#endif
800
Takashi Iwaic9b3a402008-12-10 07:47:22 +0100801static int __init wm8731_modinit(void)
Mark Brown64089b82008-12-08 19:17:58 +0000802{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000803 int ret = 0;
Fabio Estevamb65ab732013-11-21 12:38:43 -0200804#if IS_ENABLED(CONFIG_I2C)
Mark Brown59981022009-02-16 20:49:16 +0000805 ret = i2c_add_driver(&wm8731_i2c_driver);
806 if (ret != 0) {
807 printk(KERN_ERR "Failed to register WM8731 I2C driver: %d\n",
808 ret);
809 }
810#endif
811#if defined(CONFIG_SPI_MASTER)
812 ret = spi_register_driver(&wm8731_spi_driver);
813 if (ret != 0) {
814 printk(KERN_ERR "Failed to register WM8731 SPI driver: %d\n",
815 ret);
816 }
817#endif
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000818 return ret;
Mark Brown64089b82008-12-08 19:17:58 +0000819}
820module_init(wm8731_modinit);
821
822static void __exit wm8731_exit(void)
823{
Fabio Estevamb65ab732013-11-21 12:38:43 -0200824#if IS_ENABLED(CONFIG_I2C)
Mark Brown59981022009-02-16 20:49:16 +0000825 i2c_del_driver(&wm8731_i2c_driver);
826#endif
827#if defined(CONFIG_SPI_MASTER)
828 spi_unregister_driver(&wm8731_spi_driver);
829#endif
Mark Brown64089b82008-12-08 19:17:58 +0000830}
831module_exit(wm8731_exit);
832
Richard Purdie40e0aa62006-10-06 18:36:07 +0200833MODULE_DESCRIPTION("ASoC WM8731 driver");
834MODULE_AUTHOR("Richard Purdie");
835MODULE_LICENSE("GPL");