Blame view

sound/soc/codecs/wm8711.c 11.9 KB
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
1
2
3
4
5
  /*
   * wm8711.c  --  WM8711 ALSA SoC Audio driver
   *
   * Copyright 2006 Wolfson Microelectronics
   *
9a185b9ab   Mark Brown   ASoC: Remove refe...
6
   * Author: Mike Arthur <Mike.Arthur@wolfsonmicro.com>
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
7
8
9
10
11
12
13
14
15
16
17
18
19
20
   *
   * Based on wm8731.c by Richard Purdie
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   */
  
  #include <linux/module.h>
  #include <linux/moduleparam.h>
  #include <linux/init.h>
  #include <linux/delay.h>
  #include <linux/pm.h>
  #include <linux/i2c.h>
5aa5fa9fd   Mark Brown   ASoC: wm8711: Con...
21
  #include <linux/regmap.h>
bb2627674   Takashi Iwai   ASoC: Fix build e...
22
  #include <linux/spi/spi.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
23
  #include <linux/slab.h>
1552c8f67   Mark Brown   ASoC: Add device ...
24
  #include <linux/of_device.h>
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
25
26
27
28
  #include <sound/core.h>
  #include <sound/pcm.h>
  #include <sound/pcm_params.h>
  #include <sound/soc.h>
b5ab887e6   Mark Brown   ASoC: Add TLV inf...
29
  #include <sound/tlv.h>
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
30
31
32
  #include <sound/initval.h>
  
  #include "wm8711.h"
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
33
34
  /* codec private data */
  struct wm8711_priv {
5aa5fa9fd   Mark Brown   ASoC: wm8711: Con...
35
  	struct regmap *regmap;
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
36
37
38
39
40
41
42
43
44
  	unsigned int sysclk;
  };
  
  /*
   * wm8711 register cache
   * We can't read the WM8711 register space when we are
   * using 2 wire for device control, so we cache them instead.
   * There is no point in caching the reset register
   */
5aa5fa9fd   Mark Brown   ASoC: wm8711: Con...
45
46
47
  static const struct reg_default wm8711_reg_defaults[] = {
  	{ 0, 0x0079 }, { 1, 0x0079 }, { 2, 0x000a }, { 3, 0x0008 },
  	{ 4, 0x009f }, { 5, 0x000a }, { 6, 0x0000 }, { 7, 0x0000 },
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
48
  };
5aa5fa9fd   Mark Brown   ASoC: wm8711: Con...
49
50
51
52
53
54
55
56
57
  static bool wm8711_volatile(struct device *dev, unsigned int reg)
  {
  	switch (reg) {
  	case WM8711_RESET:
  		return true;
  	default:
  		return false;
  	}
  }
d97d2e35b   Mark Brown   ASoC: Factor out ...
58
  #define wm8711_reset(c)	snd_soc_write(c, WM8711_RESET, 0)
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
59

b5ab887e6   Mark Brown   ASoC: Add TLV inf...
60
  static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1);
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
61
  static const struct snd_kcontrol_new wm8711_snd_controls[] = {
b5ab887e6   Mark Brown   ASoC: Add TLV inf...
62
63
  SOC_DOUBLE_R_TLV("Master Playback Volume", WM8711_LOUT1V, WM8711_ROUT1V,
  		 0, 127, 0, out_tlv),
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
64
65
66
67
  SOC_DOUBLE_R("Master Playback ZC Switch", WM8711_LOUT1V, WM8711_ROUT1V,
  	7, 1, 0),
  
  };
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  /* Output Mixer */
  static const struct snd_kcontrol_new wm8711_output_mixer_controls[] = {
  SOC_DAPM_SINGLE("Line Bypass Switch", WM8711_APANA, 3, 1, 0),
  SOC_DAPM_SINGLE("HiFi Playback Switch", WM8711_APANA, 4, 1, 0),
  };
  
  static const struct snd_soc_dapm_widget wm8711_dapm_widgets[] = {
  SND_SOC_DAPM_MIXER("Output Mixer", WM8711_PWR, 4, 1,
  	&wm8711_output_mixer_controls[0],
  	ARRAY_SIZE(wm8711_output_mixer_controls)),
  SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM8711_PWR, 3, 1),
  SND_SOC_DAPM_OUTPUT("LOUT"),
  SND_SOC_DAPM_OUTPUT("LHPOUT"),
  SND_SOC_DAPM_OUTPUT("ROUT"),
  SND_SOC_DAPM_OUTPUT("RHPOUT"),
  };
203140006   Lu Guanqun   ASoC: Use data ba...
84
  static const struct snd_soc_dapm_route wm8711_intercon[] = {
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
85
86
87
88
89
90
91
92
93
94
  	/* output mixer */
  	{"Output Mixer", "Line Bypass Switch", "Line Input"},
  	{"Output Mixer", "HiFi Playback Switch", "DAC"},
  
  	/* outputs */
  	{"RHPOUT", NULL, "Output Mixer"},
  	{"ROUT", NULL, "Output Mixer"},
  	{"LHPOUT", NULL, "Output Mixer"},
  	{"LOUT", NULL, "Output Mixer"},
  };
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
  struct _coeff_div {
  	u32 mclk;
  	u32 rate;
  	u16 fs;
  	u8 sr:4;
  	u8 bosr:1;
  	u8 usb:1;
  };
  
  /* codec mclk clock divider coefficients */
  static const struct _coeff_div coeff_div[] = {
  	/* 48k */
  	{12288000, 48000, 256, 0x0, 0x0, 0x0},
  	{18432000, 48000, 384, 0x0, 0x1, 0x0},
  	{12000000, 48000, 250, 0x0, 0x0, 0x1},
  
  	/* 32k */
  	{12288000, 32000, 384, 0x6, 0x0, 0x0},
  	{18432000, 32000, 576, 0x6, 0x1, 0x0},
  	{12000000, 32000, 375, 0x6, 0x0, 0x1},
  
  	/* 8k */
  	{12288000, 8000, 1536, 0x3, 0x0, 0x0},
  	{18432000, 8000, 2304, 0x3, 0x1, 0x0},
  	{11289600, 8000, 1408, 0xb, 0x0, 0x0},
  	{16934400, 8000, 2112, 0xb, 0x1, 0x0},
  	{12000000, 8000, 1500, 0x3, 0x0, 0x1},
  
  	/* 96k */
  	{12288000, 96000, 128, 0x7, 0x0, 0x0},
  	{18432000, 96000, 192, 0x7, 0x1, 0x0},
  	{12000000, 96000, 125, 0x7, 0x0, 0x1},
  
  	/* 44.1k */
  	{11289600, 44100, 256, 0x8, 0x0, 0x0},
  	{16934400, 44100, 384, 0x8, 0x1, 0x0},
  	{12000000, 44100, 272, 0x8, 0x1, 0x1},
  
  	/* 88.2k */
  	{11289600, 88200, 128, 0xf, 0x0, 0x0},
  	{16934400, 88200, 192, 0xf, 0x1, 0x0},
  	{12000000, 88200, 136, 0xf, 0x1, 0x1},
  };
  
  static inline int get_coeff(int mclk, int rate)
  {
  	int i;
  
  	for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
  		if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk)
  			return i;
  	}
  	return 0;
  }
  
  static int wm8711_hw_params(struct snd_pcm_substream *substream,
  	struct snd_pcm_hw_params *params,
  	struct snd_soc_dai *dai)
  {
  	struct snd_soc_codec *codec = dai->codec;
f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
155
  	struct wm8711_priv *wm8711 =  snd_soc_codec_get_drvdata(codec);
04c57163c   Axel Lin   ASoC: wm8711: Fix...
156
  	u16 iface = snd_soc_read(codec, WM8711_IFACE) & 0xfff3;
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
157
158
159
  	int i = get_coeff(wm8711->sysclk, params_rate(params));
  	u16 srate = (coeff_div[i].sr << 2) |
  		(coeff_div[i].bosr << 1) | coeff_div[i].usb;
d97d2e35b   Mark Brown   ASoC: Factor out ...
160
  	snd_soc_write(codec, WM8711_SRATE, srate);
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
161
162
  
  	/* bit size */
b9abb5485   Mark Brown   ASoC: wm8711: Con...
163
164
  	switch (params_width(params)) {
  	case 16:
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
165
  		break;
b9abb5485   Mark Brown   ASoC: wm8711: Con...
166
  	case 20:
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
167
168
  		iface |= 0x0004;
  		break;
b9abb5485   Mark Brown   ASoC: wm8711: Con...
169
  	case 24:
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
170
171
172
  		iface |= 0x0008;
  		break;
  	}
d97d2e35b   Mark Brown   ASoC: Factor out ...
173
  	snd_soc_write(codec, WM8711_IFACE, iface);
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
174
175
176
177
178
179
180
181
182
  	return 0;
  }
  
  static int wm8711_pcm_prepare(struct snd_pcm_substream *substream,
  			      struct snd_soc_dai *dai)
  {
  	struct snd_soc_codec *codec = dai->codec;
  
  	/* set active */
d97d2e35b   Mark Brown   ASoC: Factor out ...
183
  	snd_soc_write(codec, WM8711_ACTIVE, 0x0001);
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
184
185
186
187
188
189
190
191
192
193
  
  	return 0;
  }
  
  static void wm8711_shutdown(struct snd_pcm_substream *substream,
  			    struct snd_soc_dai *dai)
  {
  	struct snd_soc_codec *codec = dai->codec;
  
  	/* deactivate */
5c898e74d   Lars-Peter Clausen   ASoC: Add helper ...
194
  	if (!snd_soc_codec_is_active(codec)) {
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
195
  		udelay(50);
d97d2e35b   Mark Brown   ASoC: Factor out ...
196
  		snd_soc_write(codec, WM8711_ACTIVE, 0x0);
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
197
198
199
200
201
202
  	}
  }
  
  static int wm8711_mute(struct snd_soc_dai *dai, int mute)
  {
  	struct snd_soc_codec *codec = dai->codec;
d97d2e35b   Mark Brown   ASoC: Factor out ...
203
  	u16 mute_reg = snd_soc_read(codec, WM8711_APDIGI) & 0xfff7;
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
204
205
  
  	if (mute)
d97d2e35b   Mark Brown   ASoC: Factor out ...
206
  		snd_soc_write(codec, WM8711_APDIGI, mute_reg | 0x8);
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
207
  	else
d97d2e35b   Mark Brown   ASoC: Factor out ...
208
  		snd_soc_write(codec, WM8711_APDIGI, mute_reg);
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
209
210
211
212
213
214
215
216
  
  	return 0;
  }
  
  static int wm8711_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  		int clk_id, unsigned int freq, int dir)
  {
  	struct snd_soc_codec *codec = codec_dai->codec;
f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
217
  	struct wm8711_priv *wm8711 =  snd_soc_codec_get_drvdata(codec);
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
  
  	switch (freq) {
  	case 11289600:
  	case 12000000:
  	case 12288000:
  	case 16934400:
  	case 18432000:
  		wm8711->sysclk = freq;
  		return 0;
  	}
  	return -EINVAL;
  }
  
  static int wm8711_set_dai_fmt(struct snd_soc_dai *codec_dai,
  		unsigned int fmt)
  {
  	struct snd_soc_codec *codec = codec_dai->codec;
d558cfc30   Axel Lin   ASoC: Leave input...
235
  	u16 iface = snd_soc_read(codec, WM8711_IFACE) & 0x000c;
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
  
  	/* set master/slave audio interface */
  	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  	case SND_SOC_DAIFMT_CBM_CFM:
  		iface |= 0x0040;
  		break;
  	case SND_SOC_DAIFMT_CBS_CFS:
  		break;
  	default:
  		return -EINVAL;
  	}
  
  	/* interface format */
  	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  	case SND_SOC_DAIFMT_I2S:
  		iface |= 0x0002;
  		break;
  	case SND_SOC_DAIFMT_RIGHT_J:
  		break;
  	case SND_SOC_DAIFMT_LEFT_J:
  		iface |= 0x0001;
  		break;
  	case SND_SOC_DAIFMT_DSP_A:
  		iface |= 0x0003;
  		break;
  	case SND_SOC_DAIFMT_DSP_B:
  		iface |= 0x0013;
  		break;
  	default:
  		return -EINVAL;
  	}
  
  	/* clock inversion */
  	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  	case SND_SOC_DAIFMT_NB_NF:
  		break;
  	case SND_SOC_DAIFMT_IB_IF:
  		iface |= 0x0090;
  		break;
  	case SND_SOC_DAIFMT_IB_NF:
  		iface |= 0x0080;
  		break;
  	case SND_SOC_DAIFMT_NB_IF:
  		iface |= 0x0010;
  		break;
  	default:
  		return -EINVAL;
  	}
  
  	/* set iface */
d97d2e35b   Mark Brown   ASoC: Factor out ...
286
  	snd_soc_write(codec, WM8711_IFACE, iface);
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
287
288
  	return 0;
  }
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
289
290
291
  static int wm8711_set_bias_level(struct snd_soc_codec *codec,
  	enum snd_soc_bias_level level)
  {
5aa5fa9fd   Mark Brown   ASoC: wm8711: Con...
292
  	struct wm8711_priv *wm8711 = snd_soc_codec_get_drvdata(codec);
d97d2e35b   Mark Brown   ASoC: Factor out ...
293
  	u16 reg = snd_soc_read(codec, WM8711_PWR) & 0xff7f;
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
294
295
296
  
  	switch (level) {
  	case SND_SOC_BIAS_ON:
d97d2e35b   Mark Brown   ASoC: Factor out ...
297
  		snd_soc_write(codec, WM8711_PWR, reg);
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
298
299
300
301
  		break;
  	case SND_SOC_BIAS_PREPARE:
  		break;
  	case SND_SOC_BIAS_STANDBY:
f235d94fc   Lars-Peter Clausen   ASoC: wm8711: Rep...
302
  		if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF)
5aa5fa9fd   Mark Brown   ASoC: wm8711: Con...
303
  			regcache_sync(wm8711->regmap);
960622da0   Axel Lin   ASoC: wm8711: Con...
304

d97d2e35b   Mark Brown   ASoC: Factor out ...
305
  		snd_soc_write(codec, WM8711_PWR, reg | 0x0040);
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
306
307
  		break;
  	case SND_SOC_BIAS_OFF:
d97d2e35b   Mark Brown   ASoC: Factor out ...
308
309
  		snd_soc_write(codec, WM8711_ACTIVE, 0x0);
  		snd_soc_write(codec, WM8711_PWR, 0xffff);
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
310
311
  		break;
  	}
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
312
313
  	return 0;
  }
431f77717   Mark Brown   ASoC: WM8711 mino...
314
  #define WM8711_RATES SNDRV_PCM_RATE_8000_96000
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
315
316
317
  
  #define WM8711_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  	SNDRV_PCM_FMTBIT_S24_LE)
85e7652d8   Lars-Peter Clausen   ASoC: Constify sn...
318
  static const struct snd_soc_dai_ops wm8711_ops = {
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
319
320
321
322
323
324
325
  	.prepare = wm8711_pcm_prepare,
  	.hw_params = wm8711_hw_params,
  	.shutdown = wm8711_shutdown,
  	.digital_mute = wm8711_mute,
  	.set_sysclk = wm8711_set_dai_sysclk,
  	.set_fmt = wm8711_set_dai_fmt,
  };
f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
326
327
  static struct snd_soc_dai_driver wm8711_dai = {
  	.name = "wm8711-hifi",
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
328
329
330
331
332
  	.playback = {
  		.stream_name = "Playback",
  		.channels_min = 1,
  		.channels_max = 2,
  		.rates = WM8711_RATES,
431f77717   Mark Brown   ASoC: WM8711 mino...
333
334
  		.formats = WM8711_FORMATS,
  	},
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
335
336
  	.ops = &wm8711_ops,
  };
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
337

f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
338
  static int wm8711_probe(struct snd_soc_codec *codec)
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
339
  {
d434bc32d   Axel Lin   ASoC: wm8711: Use...
340
  	int ret;
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
341

318b0b8d9   Mark Brown   ASoC: Update WM87...
342
  	ret = wm8711_reset(codec);
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
343
  	if (ret < 0) {
318b0b8d9   Mark Brown   ASoC: Update WM87...
344
345
  		dev_err(codec->dev, "Failed to issue reset
  ");
f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
346
  		return ret;
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
347
  	}
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
348

318b0b8d9   Mark Brown   ASoC: Update WM87...
349
  	/* Latch the update bits */
11b9ce622   Axel Lin   ASoC: wm8711: Use...
350
351
  	snd_soc_update_bits(codec, WM8711_LOUT1V, 0x0100, 0x0100);
  	snd_soc_update_bits(codec, WM8711_ROUT1V, 0x0100, 0x0100);
318b0b8d9   Mark Brown   ASoC: Update WM87...
352

d97d2e35b   Mark Brown   ASoC: Factor out ...
353
  	return ret;
f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
354

bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
355
  }
f802d6c02   Julia Lawall   ASoC: constify sn...
356
  static const struct snd_soc_codec_driver soc_codec_dev_wm8711 = {
f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
357
  	.probe =	wm8711_probe,
f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
358
  	.set_bias_level = wm8711_set_bias_level,
0bd324b1a   Lars-Peter Clausen   ASoC: wm8711: Cle...
359
  	.suspend_bias_off = true,
e324d8fa4   Kuninori Morimoto   ASoC: codec dupli...
360
361
362
363
364
365
366
367
  	.component_driver = {
  		.controls		= wm8711_snd_controls,
  		.num_controls		= ARRAY_SIZE(wm8711_snd_controls),
  		.dapm_widgets		= wm8711_dapm_widgets,
  		.num_dapm_widgets	= ARRAY_SIZE(wm8711_dapm_widgets),
  		.dapm_routes		= wm8711_intercon,
  		.num_dapm_routes	= ARRAY_SIZE(wm8711_intercon),
  	},
f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
368
  };
1552c8f67   Mark Brown   ASoC: Add device ...
369
370
371
372
373
  static const struct of_device_id wm8711_of_match[] = {
  	{ .compatible = "wlf,wm8711", },
  	{ }
  };
  MODULE_DEVICE_TABLE(of, wm8711_of_match);
5aa5fa9fd   Mark Brown   ASoC: wm8711: Con...
374
375
376
377
378
379
380
381
382
383
384
  static const struct regmap_config wm8711_regmap = {
  	.reg_bits = 7,
  	.val_bits = 9,
  	.max_register = WM8711_RESET,
  
  	.reg_defaults = wm8711_reg_defaults,
  	.num_reg_defaults = ARRAY_SIZE(wm8711_reg_defaults),
  	.cache_type = REGCACHE_RBTREE,
  
  	.volatile_reg = wm8711_volatile,
  };
08aff8cd7   Mark Brown   ASoC: Add SPI sup...
385
  #if defined(CONFIG_SPI_MASTER)
7a79e94e9   Bill Pemberton   ASoC: codecs: rem...
386
  static int wm8711_spi_probe(struct spi_device *spi)
08aff8cd7   Mark Brown   ASoC: Add SPI sup...
387
  {
08aff8cd7   Mark Brown   ASoC: Add SPI sup...
388
  	struct wm8711_priv *wm8711;
f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
389
  	int ret;
08aff8cd7   Mark Brown   ASoC: Add SPI sup...
390

e908ef40e   Mark Brown   ASoC: wm8711: Con...
391
392
  	wm8711 = devm_kzalloc(&spi->dev, sizeof(struct wm8711_priv),
  			      GFP_KERNEL);
08aff8cd7   Mark Brown   ASoC: Add SPI sup...
393
394
  	if (wm8711 == NULL)
  		return -ENOMEM;
5aa5fa9fd   Mark Brown   ASoC: wm8711: Con...
395
396
397
  	wm8711->regmap = devm_regmap_init_spi(spi, &wm8711_regmap);
  	if (IS_ERR(wm8711->regmap))
  		return PTR_ERR(wm8711->regmap);
f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
398
  	spi_set_drvdata(spi, wm8711);
08aff8cd7   Mark Brown   ASoC: Add SPI sup...
399

f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
400
401
  	ret = snd_soc_register_codec(&spi->dev,
  			&soc_codec_dev_wm8711, &wm8711_dai, 1);
e908ef40e   Mark Brown   ASoC: wm8711: Con...
402

f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
403
  	return ret;
08aff8cd7   Mark Brown   ASoC: Add SPI sup...
404
  }
7a79e94e9   Bill Pemberton   ASoC: codecs: rem...
405
  static int wm8711_spi_remove(struct spi_device *spi)
08aff8cd7   Mark Brown   ASoC: Add SPI sup...
406
  {
f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
407
  	snd_soc_unregister_codec(&spi->dev);
e908ef40e   Mark Brown   ASoC: wm8711: Con...
408

08aff8cd7   Mark Brown   ASoC: Add SPI sup...
409
410
  	return 0;
  }
08aff8cd7   Mark Brown   ASoC: Add SPI sup...
411
412
  static struct spi_driver wm8711_spi_driver = {
  	.driver = {
0473e61b9   Mark Brown   ASoC: Remove some...
413
  		.name	= "wm8711",
1552c8f67   Mark Brown   ASoC: Add device ...
414
  		.of_match_table = wm8711_of_match,
08aff8cd7   Mark Brown   ASoC: Add SPI sup...
415
416
  	},
  	.probe		= wm8711_spi_probe,
7a79e94e9   Bill Pemberton   ASoC: codecs: rem...
417
  	.remove		= wm8711_spi_remove,
08aff8cd7   Mark Brown   ASoC: Add SPI sup...
418
419
  };
  #endif /* CONFIG_SPI_MASTER */
2309d6757   Fabio Estevam   ASoC: wm8711: Use...
420
  #if IS_ENABLED(CONFIG_I2C)
7a79e94e9   Bill Pemberton   ASoC: codecs: rem...
421
422
  static int wm8711_i2c_probe(struct i2c_client *client,
  			    const struct i2c_device_id *id)
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
423
  {
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
424
  	struct wm8711_priv *wm8711;
f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
425
  	int ret;
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
426

e908ef40e   Mark Brown   ASoC: wm8711: Con...
427
428
  	wm8711 = devm_kzalloc(&client->dev, sizeof(struct wm8711_priv),
  			      GFP_KERNEL);
318b0b8d9   Mark Brown   ASoC: Update WM87...
429
  	if (wm8711 == NULL)
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
430
  		return -ENOMEM;
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
431

5aa5fa9fd   Mark Brown   ASoC: wm8711: Con...
432
433
434
  	wm8711->regmap = devm_regmap_init_i2c(client, &wm8711_regmap);
  	if (IS_ERR(wm8711->regmap))
  		return PTR_ERR(wm8711->regmap);
f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
435
  	i2c_set_clientdata(client, wm8711);
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
436

f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
437
438
  	ret =  snd_soc_register_codec(&client->dev,
  			&soc_codec_dev_wm8711, &wm8711_dai, 1);
e908ef40e   Mark Brown   ASoC: wm8711: Con...
439

f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
440
  	return ret;
318b0b8d9   Mark Brown   ASoC: Update WM87...
441
  }
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
442

7a79e94e9   Bill Pemberton   ASoC: codecs: rem...
443
  static int wm8711_i2c_remove(struct i2c_client *client)
318b0b8d9   Mark Brown   ASoC: Update WM87...
444
  {
f0fba2ad1   Liam Girdwood   ASoC: multi-compo...
445
  	snd_soc_unregister_codec(&client->dev);
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
446
447
  	return 0;
  }
318b0b8d9   Mark Brown   ASoC: Update WM87...
448
449
450
  static const struct i2c_device_id wm8711_i2c_id[] = {
  	{ "wm8711", 0 },
  	{ }
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
451
  };
318b0b8d9   Mark Brown   ASoC: Update WM87...
452
453
454
455
  MODULE_DEVICE_TABLE(i2c, wm8711_i2c_id);
  
  static struct i2c_driver wm8711_i2c_driver = {
  	.driver = {
0473e61b9   Mark Brown   ASoC: Remove some...
456
  		.name = "wm8711",
1552c8f67   Mark Brown   ASoC: Add device ...
457
  		.of_match_table = wm8711_of_match,
318b0b8d9   Mark Brown   ASoC: Update WM87...
458
459
  	},
  	.probe =    wm8711_i2c_probe,
7a79e94e9   Bill Pemberton   ASoC: codecs: rem...
460
  	.remove =   wm8711_i2c_remove,
318b0b8d9   Mark Brown   ASoC: Update WM87...
461
462
463
  	.id_table = wm8711_i2c_id,
  };
  #endif
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
464
465
466
  
  static int __init wm8711_modinit(void)
  {
318b0b8d9   Mark Brown   ASoC: Update WM87...
467
  	int ret;
2309d6757   Fabio Estevam   ASoC: wm8711: Use...
468
  #if IS_ENABLED(CONFIG_I2C)
318b0b8d9   Mark Brown   ASoC: Update WM87...
469
470
471
472
473
474
475
  	ret = i2c_add_driver(&wm8711_i2c_driver);
  	if (ret != 0) {
  		printk(KERN_ERR "Failed to register WM8711 I2C driver: %d
  ",
  		       ret);
  	}
  #endif
08aff8cd7   Mark Brown   ASoC: Add SPI sup...
476
  #if defined(CONFIG_SPI_MASTER)
bb2627674   Takashi Iwai   ASoC: Fix build e...
477
  	ret = spi_register_driver(&wm8711_spi_driver);
08aff8cd7   Mark Brown   ASoC: Add SPI sup...
478
  	if (ret != 0) {
bb2627674   Takashi Iwai   ASoC: Fix build e...
479
480
  		printk(KERN_ERR "Failed to register WM8711 SPI driver: %d
  ",
08aff8cd7   Mark Brown   ASoC: Add SPI sup...
481
482
483
  		       ret);
  	}
  #endif
318b0b8d9   Mark Brown   ASoC: Update WM87...
484
  	return 0;
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
485
486
487
488
489
  }
  module_init(wm8711_modinit);
  
  static void __exit wm8711_exit(void)
  {
2309d6757   Fabio Estevam   ASoC: wm8711: Use...
490
  #if IS_ENABLED(CONFIG_I2C)
318b0b8d9   Mark Brown   ASoC: Update WM87...
491
492
  	i2c_del_driver(&wm8711_i2c_driver);
  #endif
08aff8cd7   Mark Brown   ASoC: Add SPI sup...
493
  #if defined(CONFIG_SPI_MASTER)
bb2627674   Takashi Iwai   ASoC: Fix build e...
494
  	spi_unregister_driver(&wm8711_spi_driver);
08aff8cd7   Mark Brown   ASoC: Add SPI sup...
495
  #endif
bd6d41774   Mike Arthur   ASoC: Add WM8711 ...
496
497
498
499
500
501
  }
  module_exit(wm8711_exit);
  
  MODULE_DESCRIPTION("ASoC WM8711 driver");
  MODULE_AUTHOR("Mike Arthur");
  MODULE_LICENSE("GPL");