blob: bba330e30162ddded0b1f7e8cd4d36d19b0242d6 [file] [log] [blame]
Mark Brown3a66d382010-02-11 13:27:19 +00001/*
2 * wm2000.c -- WM2000 ALSA Soc Audio driver
3 *
Mark Brown656baae2012-05-23 12:39:07 +01004 * Copyright 2008-2011 Wolfson Microelectronics PLC.
Mark Brown3a66d382010-02-11 13:27:19 +00005 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * The download image for the WM2000 will be requested as
13 * 'wm2000_anc.bin' by default (overridable via platform data) at
14 * runtime and is expected to be in flat binary format. This is
15 * generated by Wolfson configuration tools and includes
Markus Elfringcdbd9b02017-11-24 08:02:57 +010016 * system-specific calibration information. If supplied as a
Mark Brown3a66d382010-02-11 13:27:19 +000017 * sequence of ASCII-encoded hexidecimal bytes this can be converted
18 * into a flat binary with a command such as this on the command line:
19 *
20 * perl -e 'while (<>) { s/[\r\n]+// ; printf("%c", hex($_)); }'
21 * < file > wm2000_anc.bin
22 */
23
24#include <linux/module.h>
25#include <linux/moduleparam.h>
Mark Brown3a66d382010-02-11 13:27:19 +000026#include <linux/kernel.h>
27#include <linux/init.h>
28#include <linux/firmware.h>
Mark Brown514cfd62012-12-13 17:29:00 +090029#include <linux/clk.h>
Mark Brown3a66d382010-02-11 13:27:19 +000030#include <linux/delay.h>
31#include <linux/pm.h>
32#include <linux/i2c.h>
Mark Brown8aa1fe82011-12-02 21:57:19 +000033#include <linux/regmap.h>
Mark Brown3a66d382010-02-11 13:27:19 +000034#include <linux/debugfs.h>
Mark Browna89be932012-09-22 18:33:23 -040035#include <linux/regulator/consumer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090036#include <linux/slab.h>
Mark Brown3a66d382010-02-11 13:27:19 +000037#include <sound/core.h>
38#include <sound/pcm.h>
39#include <sound/pcm_params.h>
40#include <sound/soc.h>
Mark Brown3a66d382010-02-11 13:27:19 +000041#include <sound/initval.h>
42#include <sound/tlv.h>
43
44#include <sound/wm2000.h>
45
46#include "wm2000.h"
47
Mark Browna89be932012-09-22 18:33:23 -040048#define WM2000_NUM_SUPPLIES 3
49
50static const char *wm2000_supplies[WM2000_NUM_SUPPLIES] = {
51 "SPKVDD",
52 "DBVDD",
53 "DCVDD",
54};
55
Mark Brown3a66d382010-02-11 13:27:19 +000056enum wm2000_anc_mode {
57 ANC_ACTIVE = 0,
58 ANC_BYPASS = 1,
59 ANC_STANDBY = 2,
60 ANC_OFF = 3,
61};
62
63struct wm2000_priv {
64 struct i2c_client *i2c;
Mark Brown8aa1fe82011-12-02 21:57:19 +000065 struct regmap *regmap;
Mark Brown514cfd62012-12-13 17:29:00 +090066 struct clk *mclk;
Mark Brown3a66d382010-02-11 13:27:19 +000067
Mark Browna89be932012-09-22 18:33:23 -040068 struct regulator_bulk_data supplies[WM2000_NUM_SUPPLIES];
69
Mark Brown3a66d382010-02-11 13:27:19 +000070 enum wm2000_anc_mode anc_mode;
71
72 unsigned int anc_active:1;
73 unsigned int anc_eng_ena:1;
74 unsigned int spk_ena:1;
75
Mark Brown3a66d382010-02-11 13:27:19 +000076 unsigned int speech_clarity:1;
77
78 int anc_download_size;
79 char *anc_download;
Mark Brown8e9bb422013-01-23 18:38:54 +080080
81 struct mutex lock;
Mark Brown3a66d382010-02-11 13:27:19 +000082};
83
Mark Brown3a66d382010-02-11 13:27:19 +000084static int wm2000_write(struct i2c_client *i2c, unsigned int reg,
85 unsigned int value)
86{
Mark Brown8aa1fe82011-12-02 21:57:19 +000087 struct wm2000_priv *wm2000 = i2c_get_clientdata(i2c);
88 return regmap_write(wm2000->regmap, reg, value);
Mark Brown3a66d382010-02-11 13:27:19 +000089}
90
Mark Brown3a66d382010-02-11 13:27:19 +000091static void wm2000_reset(struct wm2000_priv *wm2000)
92{
93 struct i2c_client *i2c = wm2000->i2c;
94
95 wm2000_write(i2c, WM2000_REG_SYS_CTL2, WM2000_ANC_ENG_CLR);
96 wm2000_write(i2c, WM2000_REG_SYS_CTL2, WM2000_RAM_CLR);
97 wm2000_write(i2c, WM2000_REG_ID1, 0);
98
99 wm2000->anc_mode = ANC_OFF;
100}
101
102static int wm2000_poll_bit(struct i2c_client *i2c,
Mark Brown3ff1ec22012-06-08 06:53:48 +0800103 unsigned int reg, u8 mask)
Mark Brown3a66d382010-02-11 13:27:19 +0000104{
Lucas Tanurec5d09482018-10-19 17:44:22 +0100105 struct wm2000_priv *wm2000 = i2c_get_clientdata(i2c);
Mark Brown3ff1ec22012-06-08 06:53:48 +0800106 int timeout = 4000;
Lucas Tanurec5d09482018-10-19 17:44:22 +0100107 unsigned int val;
Mark Brown3a66d382010-02-11 13:27:19 +0000108
Lucas Tanurec5d09482018-10-19 17:44:22 +0100109 regmap_read(wm2000->regmap, reg, &val);
Mark Brown3a66d382010-02-11 13:27:19 +0000110
111 while (!(val & mask) && --timeout) {
112 msleep(1);
Lucas Tanurec5d09482018-10-19 17:44:22 +0100113 regmap_read(wm2000->regmap, reg, &val);
Mark Brown3a66d382010-02-11 13:27:19 +0000114 }
115
116 if (timeout == 0)
117 return 0;
118 else
119 return 1;
120}
121
122static int wm2000_power_up(struct i2c_client *i2c, int analogue)
123{
124 struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev);
Mark Brownd61100b2012-12-14 15:16:58 +0900125 unsigned long rate;
Lucas Tanurec5d09482018-10-19 17:44:22 +0100126 unsigned int val;
Mark Brown3ff1ec22012-06-08 06:53:48 +0800127 int ret;
Mark Brown3a66d382010-02-11 13:27:19 +0000128
Takashi Iwaibf90e892013-11-05 18:39:53 +0100129 if (WARN_ON(wm2000->anc_mode != ANC_OFF))
130 return -EINVAL;
Mark Brown3a66d382010-02-11 13:27:19 +0000131
132 dev_dbg(&i2c->dev, "Beginning power up\n");
133
Mark Browna89be932012-09-22 18:33:23 -0400134 ret = regulator_bulk_enable(WM2000_NUM_SUPPLIES, wm2000->supplies);
135 if (ret != 0) {
136 dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret);
137 return ret;
138 }
139
Mark Brownd61100b2012-12-14 15:16:58 +0900140 rate = clk_get_rate(wm2000->mclk);
141 if (rate <= 13500000) {
Mark Brown3a66d382010-02-11 13:27:19 +0000142 dev_dbg(&i2c->dev, "Disabling MCLK divider\n");
143 wm2000_write(i2c, WM2000_REG_SYS_CTL2,
144 WM2000_MCLK_DIV2_ENA_CLR);
145 } else {
146 dev_dbg(&i2c->dev, "Enabling MCLK divider\n");
147 wm2000_write(i2c, WM2000_REG_SYS_CTL2,
148 WM2000_MCLK_DIV2_ENA_SET);
149 }
150
151 wm2000_write(i2c, WM2000_REG_SYS_CTL2, WM2000_ANC_ENG_CLR);
152 wm2000_write(i2c, WM2000_REG_SYS_CTL2, WM2000_ANC_ENG_SET);
153
154 /* Wait for ANC engine to become ready */
155 if (!wm2000_poll_bit(i2c, WM2000_REG_ANC_STAT,
Mark Brown3ff1ec22012-06-08 06:53:48 +0800156 WM2000_ANC_ENG_IDLE)) {
Mark Brown3a66d382010-02-11 13:27:19 +0000157 dev_err(&i2c->dev, "ANC engine failed to reset\n");
Mark Browna89be932012-09-22 18:33:23 -0400158 regulator_bulk_disable(WM2000_NUM_SUPPLIES, wm2000->supplies);
Mark Brown3a66d382010-02-11 13:27:19 +0000159 return -ETIMEDOUT;
160 }
161
162 if (!wm2000_poll_bit(i2c, WM2000_REG_SYS_STATUS,
Mark Brown3ff1ec22012-06-08 06:53:48 +0800163 WM2000_STATUS_BOOT_COMPLETE)) {
Mark Brown3a66d382010-02-11 13:27:19 +0000164 dev_err(&i2c->dev, "ANC engine failed to initialise\n");
Mark Browna89be932012-09-22 18:33:23 -0400165 regulator_bulk_disable(WM2000_NUM_SUPPLIES, wm2000->supplies);
Mark Brown3a66d382010-02-11 13:27:19 +0000166 return -ETIMEDOUT;
167 }
168
169 wm2000_write(i2c, WM2000_REG_SYS_CTL2, WM2000_RAM_SET);
170
171 /* Open code download of the data since it is the only bulk
172 * write we do. */
173 dev_dbg(&i2c->dev, "Downloading %d bytes\n",
174 wm2000->anc_download_size - 2);
175
176 ret = i2c_master_send(i2c, wm2000->anc_download,
177 wm2000->anc_download_size);
178 if (ret < 0) {
179 dev_err(&i2c->dev, "i2c_transfer() failed: %d\n", ret);
Mark Browna89be932012-09-22 18:33:23 -0400180 regulator_bulk_disable(WM2000_NUM_SUPPLIES, wm2000->supplies);
Mark Brown3a66d382010-02-11 13:27:19 +0000181 return ret;
182 }
183 if (ret != wm2000->anc_download_size) {
184 dev_err(&i2c->dev, "i2c_transfer() failed, %d != %d\n",
185 ret, wm2000->anc_download_size);
Mark Browna89be932012-09-22 18:33:23 -0400186 regulator_bulk_disable(WM2000_NUM_SUPPLIES, wm2000->supplies);
Mark Brown3a66d382010-02-11 13:27:19 +0000187 return -EIO;
188 }
189
190 dev_dbg(&i2c->dev, "Download complete\n");
191
192 if (analogue) {
Mark Brown3ff1ec22012-06-08 06:53:48 +0800193 wm2000_write(i2c, WM2000_REG_ANA_VMID_PU_TIME, 248 / 4);
Mark Brown3a66d382010-02-11 13:27:19 +0000194
195 wm2000_write(i2c, WM2000_REG_SYS_MODE_CNTRL,
196 WM2000_MODE_ANA_SEQ_INCLUDE |
197 WM2000_MODE_MOUSE_ENABLE |
198 WM2000_MODE_THERMAL_ENABLE);
199 } else {
Mark Brown3a66d382010-02-11 13:27:19 +0000200 wm2000_write(i2c, WM2000_REG_SYS_MODE_CNTRL,
201 WM2000_MODE_MOUSE_ENABLE |
202 WM2000_MODE_THERMAL_ENABLE);
203 }
204
Lucas Tanurec5d09482018-10-19 17:44:22 +0100205 ret = regmap_read(wm2000->regmap, WM2000_REG_SPEECH_CLARITY, &val);
206 if (ret != 0) {
207 dev_err(&i2c->dev, "Unable to read Speech Clarity: %d\n", ret);
208 regulator_bulk_disable(WM2000_NUM_SUPPLIES, wm2000->supplies);
209 return ret;
210 }
Mark Brown3a66d382010-02-11 13:27:19 +0000211 if (wm2000->speech_clarity)
Lucas Tanurec5d09482018-10-19 17:44:22 +0100212 val |= WM2000_SPEECH_CLARITY;
Mark Brown267f8fa2013-01-04 21:18:12 +0000213 else
Lucas Tanurec5d09482018-10-19 17:44:22 +0100214 val &= ~WM2000_SPEECH_CLARITY;
215 wm2000_write(i2c, WM2000_REG_SPEECH_CLARITY, val);
Mark Brown3a66d382010-02-11 13:27:19 +0000216
217 wm2000_write(i2c, WM2000_REG_SYS_START0, 0x33);
218 wm2000_write(i2c, WM2000_REG_SYS_START1, 0x02);
219
220 wm2000_write(i2c, WM2000_REG_SYS_CTL2, WM2000_ANC_INT_N_CLR);
221
222 if (!wm2000_poll_bit(i2c, WM2000_REG_SYS_STATUS,
Mark Brown3ff1ec22012-06-08 06:53:48 +0800223 WM2000_STATUS_MOUSE_ACTIVE)) {
224 dev_err(&i2c->dev, "Timed out waiting for device\n");
Mark Browna89be932012-09-22 18:33:23 -0400225 regulator_bulk_disable(WM2000_NUM_SUPPLIES, wm2000->supplies);
Mark Brown3a66d382010-02-11 13:27:19 +0000226 return -ETIMEDOUT;
227 }
228
229 dev_dbg(&i2c->dev, "ANC active\n");
230 if (analogue)
231 dev_dbg(&i2c->dev, "Analogue active\n");
232 wm2000->anc_mode = ANC_ACTIVE;
233
234 return 0;
235}
236
237static int wm2000_power_down(struct i2c_client *i2c, int analogue)
238{
239 struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev);
Mark Brown3a66d382010-02-11 13:27:19 +0000240
241 if (analogue) {
Mark Brown3ff1ec22012-06-08 06:53:48 +0800242 wm2000_write(i2c, WM2000_REG_ANA_VMID_PD_TIME, 248 / 4);
Mark Brown3a66d382010-02-11 13:27:19 +0000243 wm2000_write(i2c, WM2000_REG_SYS_MODE_CNTRL,
244 WM2000_MODE_ANA_SEQ_INCLUDE |
245 WM2000_MODE_POWER_DOWN);
246 } else {
Mark Brown3a66d382010-02-11 13:27:19 +0000247 wm2000_write(i2c, WM2000_REG_SYS_MODE_CNTRL,
248 WM2000_MODE_POWER_DOWN);
249 }
250
251 if (!wm2000_poll_bit(i2c, WM2000_REG_SYS_STATUS,
Mark Brown3ff1ec22012-06-08 06:53:48 +0800252 WM2000_STATUS_POWER_DOWN_COMPLETE)) {
Mark Brown3a66d382010-02-11 13:27:19 +0000253 dev_err(&i2c->dev, "Timeout waiting for ANC power down\n");
254 return -ETIMEDOUT;
255 }
256
257 if (!wm2000_poll_bit(i2c, WM2000_REG_ANC_STAT,
Mark Brown3ff1ec22012-06-08 06:53:48 +0800258 WM2000_ANC_ENG_IDLE)) {
Mark Brown3a66d382010-02-11 13:27:19 +0000259 dev_err(&i2c->dev, "Timeout waiting for ANC engine idle\n");
260 return -ETIMEDOUT;
261 }
262
Mark Browna89be932012-09-22 18:33:23 -0400263 regulator_bulk_disable(WM2000_NUM_SUPPLIES, wm2000->supplies);
264
Mark Brown3a66d382010-02-11 13:27:19 +0000265 dev_dbg(&i2c->dev, "powered off\n");
266 wm2000->anc_mode = ANC_OFF;
267
268 return 0;
269}
270
271static int wm2000_enter_bypass(struct i2c_client *i2c, int analogue)
272{
273 struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev);
274
Takashi Iwaibf90e892013-11-05 18:39:53 +0100275 if (WARN_ON(wm2000->anc_mode != ANC_ACTIVE))
276 return -EINVAL;
Mark Brown3a66d382010-02-11 13:27:19 +0000277
278 if (analogue) {
279 wm2000_write(i2c, WM2000_REG_SYS_MODE_CNTRL,
280 WM2000_MODE_ANA_SEQ_INCLUDE |
281 WM2000_MODE_THERMAL_ENABLE |
282 WM2000_MODE_BYPASS_ENTRY);
283 } else {
284 wm2000_write(i2c, WM2000_REG_SYS_MODE_CNTRL,
285 WM2000_MODE_THERMAL_ENABLE |
286 WM2000_MODE_BYPASS_ENTRY);
287 }
288
289 if (!wm2000_poll_bit(i2c, WM2000_REG_SYS_STATUS,
Mark Brown3ff1ec22012-06-08 06:53:48 +0800290 WM2000_STATUS_ANC_DISABLED)) {
Mark Brown3a66d382010-02-11 13:27:19 +0000291 dev_err(&i2c->dev, "Timeout waiting for ANC disable\n");
292 return -ETIMEDOUT;
293 }
294
295 if (!wm2000_poll_bit(i2c, WM2000_REG_ANC_STAT,
Mark Brown3ff1ec22012-06-08 06:53:48 +0800296 WM2000_ANC_ENG_IDLE)) {
Mark Brown3a66d382010-02-11 13:27:19 +0000297 dev_err(&i2c->dev, "Timeout waiting for ANC engine idle\n");
298 return -ETIMEDOUT;
299 }
300
301 wm2000_write(i2c, WM2000_REG_SYS_CTL1, WM2000_SYS_STBY);
302 wm2000_write(i2c, WM2000_REG_SYS_CTL2, WM2000_RAM_CLR);
303
304 wm2000->anc_mode = ANC_BYPASS;
305 dev_dbg(&i2c->dev, "bypass enabled\n");
306
307 return 0;
308}
309
310static int wm2000_exit_bypass(struct i2c_client *i2c, int analogue)
311{
312 struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev);
313
Takashi Iwaibf90e892013-11-05 18:39:53 +0100314 if (WARN_ON(wm2000->anc_mode != ANC_BYPASS))
315 return -EINVAL;
Mark Brown3a66d382010-02-11 13:27:19 +0000316
317 wm2000_write(i2c, WM2000_REG_SYS_CTL1, 0);
318
319 if (analogue) {
320 wm2000_write(i2c, WM2000_REG_SYS_MODE_CNTRL,
321 WM2000_MODE_ANA_SEQ_INCLUDE |
322 WM2000_MODE_MOUSE_ENABLE |
323 WM2000_MODE_THERMAL_ENABLE);
324 } else {
325 wm2000_write(i2c, WM2000_REG_SYS_MODE_CNTRL,
326 WM2000_MODE_MOUSE_ENABLE |
327 WM2000_MODE_THERMAL_ENABLE);
328 }
329
330 wm2000_write(i2c, WM2000_REG_SYS_CTL2, WM2000_RAM_SET);
331 wm2000_write(i2c, WM2000_REG_SYS_CTL2, WM2000_ANC_INT_N_CLR);
332
333 if (!wm2000_poll_bit(i2c, WM2000_REG_SYS_STATUS,
Mark Brown3ff1ec22012-06-08 06:53:48 +0800334 WM2000_STATUS_MOUSE_ACTIVE)) {
Mark Brown3a66d382010-02-11 13:27:19 +0000335 dev_err(&i2c->dev, "Timed out waiting for MOUSE\n");
336 return -ETIMEDOUT;
337 }
338
339 wm2000->anc_mode = ANC_ACTIVE;
340 dev_dbg(&i2c->dev, "MOUSE active\n");
341
342 return 0;
343}
344
345static int wm2000_enter_standby(struct i2c_client *i2c, int analogue)
346{
347 struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev);
Mark Brown3a66d382010-02-11 13:27:19 +0000348
Takashi Iwaibf90e892013-11-05 18:39:53 +0100349 if (WARN_ON(wm2000->anc_mode != ANC_ACTIVE))
350 return -EINVAL;
Mark Brown3a66d382010-02-11 13:27:19 +0000351
352 if (analogue) {
Mark Brown3ff1ec22012-06-08 06:53:48 +0800353 wm2000_write(i2c, WM2000_REG_ANA_VMID_PD_TIME, 248 / 4);
Mark Brown3a66d382010-02-11 13:27:19 +0000354
355 wm2000_write(i2c, WM2000_REG_SYS_MODE_CNTRL,
356 WM2000_MODE_ANA_SEQ_INCLUDE |
357 WM2000_MODE_THERMAL_ENABLE |
358 WM2000_MODE_STANDBY_ENTRY);
359 } else {
Mark Brown3a66d382010-02-11 13:27:19 +0000360 wm2000_write(i2c, WM2000_REG_SYS_MODE_CNTRL,
361 WM2000_MODE_THERMAL_ENABLE |
362 WM2000_MODE_STANDBY_ENTRY);
363 }
364
365 if (!wm2000_poll_bit(i2c, WM2000_REG_SYS_STATUS,
Mark Brown3ff1ec22012-06-08 06:53:48 +0800366 WM2000_STATUS_ANC_DISABLED)) {
Mark Brown3a66d382010-02-11 13:27:19 +0000367 dev_err(&i2c->dev,
368 "Timed out waiting for ANC disable after 1ms\n");
369 return -ETIMEDOUT;
370 }
371
Mark Brown3ff1ec22012-06-08 06:53:48 +0800372 if (!wm2000_poll_bit(i2c, WM2000_REG_ANC_STAT, WM2000_ANC_ENG_IDLE)) {
Mark Brown3a66d382010-02-11 13:27:19 +0000373 dev_err(&i2c->dev,
Mark Brown3ff1ec22012-06-08 06:53:48 +0800374 "Timed out waiting for standby\n");
Mark Brown3a66d382010-02-11 13:27:19 +0000375 return -ETIMEDOUT;
376 }
377
378 wm2000_write(i2c, WM2000_REG_SYS_CTL1, WM2000_SYS_STBY);
379 wm2000_write(i2c, WM2000_REG_SYS_CTL2, WM2000_RAM_CLR);
380
381 wm2000->anc_mode = ANC_STANDBY;
382 dev_dbg(&i2c->dev, "standby\n");
383 if (analogue)
384 dev_dbg(&i2c->dev, "Analogue disabled\n");
385
386 return 0;
387}
388
389static int wm2000_exit_standby(struct i2c_client *i2c, int analogue)
390{
391 struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev);
Mark Brown3a66d382010-02-11 13:27:19 +0000392
Takashi Iwaibf90e892013-11-05 18:39:53 +0100393 if (WARN_ON(wm2000->anc_mode != ANC_STANDBY))
394 return -EINVAL;
Mark Brown3a66d382010-02-11 13:27:19 +0000395
396 wm2000_write(i2c, WM2000_REG_SYS_CTL1, 0);
397
398 if (analogue) {
Mark Brown3ff1ec22012-06-08 06:53:48 +0800399 wm2000_write(i2c, WM2000_REG_ANA_VMID_PU_TIME, 248 / 4);
Mark Brown3a66d382010-02-11 13:27:19 +0000400
401 wm2000_write(i2c, WM2000_REG_SYS_MODE_CNTRL,
402 WM2000_MODE_ANA_SEQ_INCLUDE |
403 WM2000_MODE_THERMAL_ENABLE |
404 WM2000_MODE_MOUSE_ENABLE);
405 } else {
Mark Brown3a66d382010-02-11 13:27:19 +0000406 wm2000_write(i2c, WM2000_REG_SYS_MODE_CNTRL,
407 WM2000_MODE_THERMAL_ENABLE |
408 WM2000_MODE_MOUSE_ENABLE);
409 }
410
411 wm2000_write(i2c, WM2000_REG_SYS_CTL2, WM2000_RAM_SET);
412 wm2000_write(i2c, WM2000_REG_SYS_CTL2, WM2000_ANC_INT_N_CLR);
413
414 if (!wm2000_poll_bit(i2c, WM2000_REG_SYS_STATUS,
Mark Brown3ff1ec22012-06-08 06:53:48 +0800415 WM2000_STATUS_MOUSE_ACTIVE)) {
416 dev_err(&i2c->dev, "Timed out waiting for MOUSE\n");
Mark Brown3a66d382010-02-11 13:27:19 +0000417 return -ETIMEDOUT;
418 }
419
420 wm2000->anc_mode = ANC_ACTIVE;
421 dev_dbg(&i2c->dev, "MOUSE active\n");
422 if (analogue)
423 dev_dbg(&i2c->dev, "Analogue enabled\n");
424
425 return 0;
426}
427
428typedef int (*wm2000_mode_fn)(struct i2c_client *i2c, int analogue);
429
430static struct {
431 enum wm2000_anc_mode source;
432 enum wm2000_anc_mode dest;
433 int analogue;
434 wm2000_mode_fn step[2];
435} anc_transitions[] = {
436 {
437 .source = ANC_OFF,
438 .dest = ANC_ACTIVE,
439 .analogue = 1,
440 .step = {
441 wm2000_power_up,
442 },
443 },
444 {
445 .source = ANC_OFF,
446 .dest = ANC_STANDBY,
447 .step = {
448 wm2000_power_up,
449 wm2000_enter_standby,
450 },
451 },
452 {
453 .source = ANC_OFF,
454 .dest = ANC_BYPASS,
455 .analogue = 1,
456 .step = {
457 wm2000_power_up,
458 wm2000_enter_bypass,
459 },
460 },
461 {
462 .source = ANC_ACTIVE,
463 .dest = ANC_BYPASS,
464 .analogue = 1,
465 .step = {
466 wm2000_enter_bypass,
467 },
468 },
469 {
470 .source = ANC_ACTIVE,
471 .dest = ANC_STANDBY,
472 .analogue = 1,
473 .step = {
474 wm2000_enter_standby,
475 },
476 },
477 {
478 .source = ANC_ACTIVE,
479 .dest = ANC_OFF,
480 .analogue = 1,
481 .step = {
482 wm2000_power_down,
483 },
484 },
485 {
486 .source = ANC_BYPASS,
487 .dest = ANC_ACTIVE,
488 .analogue = 1,
489 .step = {
490 wm2000_exit_bypass,
491 },
492 },
493 {
494 .source = ANC_BYPASS,
495 .dest = ANC_STANDBY,
496 .analogue = 1,
497 .step = {
498 wm2000_exit_bypass,
499 wm2000_enter_standby,
500 },
501 },
502 {
503 .source = ANC_BYPASS,
504 .dest = ANC_OFF,
505 .step = {
506 wm2000_exit_bypass,
507 wm2000_power_down,
508 },
509 },
510 {
511 .source = ANC_STANDBY,
512 .dest = ANC_ACTIVE,
513 .analogue = 1,
514 .step = {
515 wm2000_exit_standby,
516 },
517 },
518 {
519 .source = ANC_STANDBY,
520 .dest = ANC_BYPASS,
521 .analogue = 1,
522 .step = {
523 wm2000_exit_standby,
524 wm2000_enter_bypass,
525 },
526 },
527 {
528 .source = ANC_STANDBY,
529 .dest = ANC_OFF,
530 .step = {
531 wm2000_exit_standby,
532 wm2000_power_down,
533 },
534 },
535};
536
537static int wm2000_anc_transition(struct wm2000_priv *wm2000,
538 enum wm2000_anc_mode mode)
539{
540 struct i2c_client *i2c = wm2000->i2c;
541 int i, j;
542 int ret;
543
544 if (wm2000->anc_mode == mode)
545 return 0;
546
547 for (i = 0; i < ARRAY_SIZE(anc_transitions); i++)
548 if (anc_transitions[i].source == wm2000->anc_mode &&
549 anc_transitions[i].dest == mode)
550 break;
551 if (i == ARRAY_SIZE(anc_transitions)) {
552 dev_err(&i2c->dev, "No transition for %d->%d\n",
553 wm2000->anc_mode, mode);
554 return -EINVAL;
555 }
556
Mark Brown514cfd62012-12-13 17:29:00 +0900557 /* Maintain clock while active */
558 if (anc_transitions[i].source == ANC_OFF) {
559 ret = clk_prepare_enable(wm2000->mclk);
560 if (ret != 0) {
561 dev_err(&i2c->dev, "Failed to enable MCLK: %d\n", ret);
562 return ret;
563 }
564 }
565
Mark Brown3a66d382010-02-11 13:27:19 +0000566 for (j = 0; j < ARRAY_SIZE(anc_transitions[j].step); j++) {
567 if (!anc_transitions[i].step[j])
568 break;
569 ret = anc_transitions[i].step[j](i2c,
570 anc_transitions[i].analogue);
571 if (ret != 0)
572 return ret;
573 }
574
Mark Brown514cfd62012-12-13 17:29:00 +0900575 if (anc_transitions[i].dest == ANC_OFF)
576 clk_disable_unprepare(wm2000->mclk);
577
Charles Keepaxfa54aad2016-08-11 14:40:04 +0100578 return 0;
Mark Brown3a66d382010-02-11 13:27:19 +0000579}
580
581static int wm2000_anc_set_mode(struct wm2000_priv *wm2000)
582{
583 struct i2c_client *i2c = wm2000->i2c;
584 enum wm2000_anc_mode mode;
585
586 if (wm2000->anc_eng_ena && wm2000->spk_ena)
587 if (wm2000->anc_active)
588 mode = ANC_ACTIVE;
589 else
590 mode = ANC_BYPASS;
591 else
592 mode = ANC_STANDBY;
593
594 dev_dbg(&i2c->dev, "Set mode %d (enabled %d, mute %d, active %d)\n",
595 mode, wm2000->anc_eng_ena, !wm2000->spk_ena,
596 wm2000->anc_active);
597
598 return wm2000_anc_transition(wm2000, mode);
599}
600
601static int wm2000_anc_mode_get(struct snd_kcontrol *kcontrol,
602 struct snd_ctl_elem_value *ucontrol)
603{
Kuninori Morimotoe5449af2018-01-29 02:59:05 +0000604 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
605 struct wm2000_priv *wm2000 = dev_get_drvdata(component->dev);
Mark Brown3a66d382010-02-11 13:27:19 +0000606
Takashi Iwai00a14c22015-03-10 12:39:09 +0100607 ucontrol->value.integer.value[0] = wm2000->anc_active;
Mark Brown3a66d382010-02-11 13:27:19 +0000608
609 return 0;
610}
611
612static int wm2000_anc_mode_put(struct snd_kcontrol *kcontrol,
613 struct snd_ctl_elem_value *ucontrol)
614{
Kuninori Morimotoe5449af2018-01-29 02:59:05 +0000615 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
616 struct wm2000_priv *wm2000 = dev_get_drvdata(component->dev);
Dan Carpenter8444f592015-10-13 10:12:45 +0300617 unsigned int anc_active = ucontrol->value.integer.value[0];
Mark Brown8e9bb422013-01-23 18:38:54 +0800618 int ret;
Mark Brown3a66d382010-02-11 13:27:19 +0000619
620 if (anc_active > 1)
621 return -EINVAL;
622
Mark Brown8e9bb422013-01-23 18:38:54 +0800623 mutex_lock(&wm2000->lock);
624
Mark Brown3a66d382010-02-11 13:27:19 +0000625 wm2000->anc_active = anc_active;
626
Mark Brown8e9bb422013-01-23 18:38:54 +0800627 ret = wm2000_anc_set_mode(wm2000);
628
629 mutex_unlock(&wm2000->lock);
630
631 return ret;
Mark Brown3a66d382010-02-11 13:27:19 +0000632}
633
634static int wm2000_speaker_get(struct snd_kcontrol *kcontrol,
635 struct snd_ctl_elem_value *ucontrol)
636{
Kuninori Morimotoe5449af2018-01-29 02:59:05 +0000637 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
638 struct wm2000_priv *wm2000 = dev_get_drvdata(component->dev);
Mark Brown3a66d382010-02-11 13:27:19 +0000639
Takashi Iwai00a14c22015-03-10 12:39:09 +0100640 ucontrol->value.integer.value[0] = wm2000->spk_ena;
Mark Brown3a66d382010-02-11 13:27:19 +0000641
642 return 0;
643}
644
645static int wm2000_speaker_put(struct snd_kcontrol *kcontrol,
646 struct snd_ctl_elem_value *ucontrol)
647{
Kuninori Morimotoe5449af2018-01-29 02:59:05 +0000648 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
649 struct wm2000_priv *wm2000 = dev_get_drvdata(component->dev);
Dan Carpenter8444f592015-10-13 10:12:45 +0300650 unsigned int val = ucontrol->value.integer.value[0];
Mark Brown8e9bb422013-01-23 18:38:54 +0800651 int ret;
Mark Brown3a66d382010-02-11 13:27:19 +0000652
653 if (val > 1)
654 return -EINVAL;
655
Mark Brown8e9bb422013-01-23 18:38:54 +0800656 mutex_lock(&wm2000->lock);
657
Mark Brown3a66d382010-02-11 13:27:19 +0000658 wm2000->spk_ena = val;
659
Mark Brown8e9bb422013-01-23 18:38:54 +0800660 ret = wm2000_anc_set_mode(wm2000);
661
662 mutex_unlock(&wm2000->lock);
663
664 return ret;
Mark Brown3a66d382010-02-11 13:27:19 +0000665}
666
667static const struct snd_kcontrol_new wm2000_controls[] = {
Mark Brown3f3af6e2013-01-30 21:35:44 +0800668 SOC_SINGLE("ANC Volume", WM2000_REG_ANC_GAIN_CTRL, 0, 255, 0),
Mark Brown3a66d382010-02-11 13:27:19 +0000669 SOC_SINGLE_BOOL_EXT("WM2000 ANC Switch", 0,
670 wm2000_anc_mode_get,
671 wm2000_anc_mode_put),
672 SOC_SINGLE_BOOL_EXT("WM2000 Switch", 0,
673 wm2000_speaker_get,
674 wm2000_speaker_put),
675};
676
677static int wm2000_anc_power_event(struct snd_soc_dapm_widget *w,
678 struct snd_kcontrol *kcontrol, int event)
679{
Kuninori Morimotoe5449af2018-01-29 02:59:05 +0000680 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
681 struct wm2000_priv *wm2000 = dev_get_drvdata(component->dev);
Mark Brown8e9bb422013-01-23 18:38:54 +0800682 int ret;
683
684 mutex_lock(&wm2000->lock);
Mark Brown3a66d382010-02-11 13:27:19 +0000685
686 if (SND_SOC_DAPM_EVENT_ON(event))
687 wm2000->anc_eng_ena = 1;
688
689 if (SND_SOC_DAPM_EVENT_OFF(event))
690 wm2000->anc_eng_ena = 0;
691
Mark Brown8e9bb422013-01-23 18:38:54 +0800692 ret = wm2000_anc_set_mode(wm2000);
693
694 mutex_unlock(&wm2000->lock);
695
696 return ret;
Mark Brown3a66d382010-02-11 13:27:19 +0000697}
698
699static const struct snd_soc_dapm_widget wm2000_dapm_widgets[] = {
700/* Externally visible pins */
Mark Brown4911ccd2011-12-02 21:59:18 +0000701SND_SOC_DAPM_OUTPUT("SPKN"),
702SND_SOC_DAPM_OUTPUT("SPKP"),
Mark Brown3a66d382010-02-11 13:27:19 +0000703
Mark Brown4911ccd2011-12-02 21:59:18 +0000704SND_SOC_DAPM_INPUT("LINN"),
705SND_SOC_DAPM_INPUT("LINP"),
Mark Brown3a66d382010-02-11 13:27:19 +0000706
707SND_SOC_DAPM_PGA_E("ANC Engine", SND_SOC_NOPM, 0, 0, NULL, 0,
708 wm2000_anc_power_event,
709 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
710};
711
712/* Target, Path, Source */
Mark Brown4911ccd2011-12-02 21:59:18 +0000713static const struct snd_soc_dapm_route wm2000_audio_map[] = {
714 { "SPKN", NULL, "ANC Engine" },
715 { "SPKP", NULL, "ANC Engine" },
716 { "ANC Engine", NULL, "LINN" },
717 { "ANC Engine", NULL, "LINP" },
Mark Brown3a66d382010-02-11 13:27:19 +0000718};
719
Mark Brown4911ccd2011-12-02 21:59:18 +0000720#ifdef CONFIG_PM
Kuninori Morimotoe5449af2018-01-29 02:59:05 +0000721static int wm2000_suspend(struct snd_soc_component *component)
Mark Brown3a66d382010-02-11 13:27:19 +0000722{
Kuninori Morimotoe5449af2018-01-29 02:59:05 +0000723 struct wm2000_priv *wm2000 = dev_get_drvdata(component->dev);
Mark Brown3a66d382010-02-11 13:27:19 +0000724
Mark Brown4911ccd2011-12-02 21:59:18 +0000725 return wm2000_anc_transition(wm2000, ANC_OFF);
Mark Brown3a66d382010-02-11 13:27:19 +0000726}
Mark Brown4911ccd2011-12-02 21:59:18 +0000727
Kuninori Morimotoe5449af2018-01-29 02:59:05 +0000728static int wm2000_resume(struct snd_soc_component *component)
Mark Brown4911ccd2011-12-02 21:59:18 +0000729{
Kuninori Morimotoe5449af2018-01-29 02:59:05 +0000730 struct wm2000_priv *wm2000 = dev_get_drvdata(component->dev);
Mark Brown4911ccd2011-12-02 21:59:18 +0000731
732 return wm2000_anc_set_mode(wm2000);
733}
734#else
735#define wm2000_suspend NULL
736#define wm2000_resume NULL
737#endif
Mark Brown3a66d382010-02-11 13:27:19 +0000738
Mark Brown51cc7ed2012-05-31 14:48:07 +0100739static bool wm2000_readable_reg(struct device *dev, unsigned int reg)
740{
741 switch (reg) {
742 case WM2000_REG_SYS_START:
Mark Brown33e75462013-01-22 15:51:08 +0900743 case WM2000_REG_ANC_GAIN_CTRL:
744 case WM2000_REG_MSE_TH1:
745 case WM2000_REG_MSE_TH2:
Mark Brown51cc7ed2012-05-31 14:48:07 +0100746 case WM2000_REG_SPEECH_CLARITY:
747 case WM2000_REG_SYS_WATCHDOG:
748 case WM2000_REG_ANA_VMID_PD_TIME:
749 case WM2000_REG_ANA_VMID_PU_TIME:
750 case WM2000_REG_CAT_FLTR_INDX:
751 case WM2000_REG_CAT_GAIN_0:
752 case WM2000_REG_SYS_STATUS:
753 case WM2000_REG_SYS_MODE_CNTRL:
754 case WM2000_REG_SYS_START0:
755 case WM2000_REG_SYS_START1:
756 case WM2000_REG_ID1:
757 case WM2000_REG_ID2:
758 case WM2000_REG_REVISON:
759 case WM2000_REG_SYS_CTL1:
760 case WM2000_REG_SYS_CTL2:
761 case WM2000_REG_ANC_STAT:
762 case WM2000_REG_IF_CTL:
Mark Brown939dc512013-03-29 13:03:39 +0800763 case WM2000_REG_ANA_MIC_CTL:
764 case WM2000_REG_SPK_CTL:
Mark Brown51cc7ed2012-05-31 14:48:07 +0100765 return true;
766 default:
767 return false;
768 }
769}
770
Mark Brown8aa1fe82011-12-02 21:57:19 +0000771static const struct regmap_config wm2000_regmap = {
Mark Brownd0e12f32012-09-26 11:57:30 +0100772 .reg_bits = 16,
Mark Brown8aa1fe82011-12-02 21:57:19 +0000773 .val_bits = 8,
Mark Brown51cc7ed2012-05-31 14:48:07 +0100774
Mark Brown939dc512013-03-29 13:03:39 +0800775 .max_register = WM2000_REG_SPK_CTL,
Mark Brown51cc7ed2012-05-31 14:48:07 +0100776 .readable_reg = wm2000_readable_reg,
Mark Brown8aa1fe82011-12-02 21:57:19 +0000777};
778
Kuninori Morimotoe5449af2018-01-29 02:59:05 +0000779static int wm2000_probe(struct snd_soc_component *component)
Mark Brown4911ccd2011-12-02 21:59:18 +0000780{
Kuninori Morimotoe5449af2018-01-29 02:59:05 +0000781 struct wm2000_priv *wm2000 = dev_get_drvdata(component->dev);
Mark Brown4911ccd2011-12-02 21:59:18 +0000782
783 /* This will trigger a transition to standby mode by default */
784 wm2000_anc_set_mode(wm2000);
785
786 return 0;
787}
788
Kuninori Morimotoe5449af2018-01-29 02:59:05 +0000789static void wm2000_remove(struct snd_soc_component *component)
Mark Brown4911ccd2011-12-02 21:59:18 +0000790{
Kuninori Morimotoe5449af2018-01-29 02:59:05 +0000791 struct wm2000_priv *wm2000 = dev_get_drvdata(component->dev);
Mark Brown4911ccd2011-12-02 21:59:18 +0000792
Kuninori Morimotoe5449af2018-01-29 02:59:05 +0000793 wm2000_anc_transition(wm2000, ANC_OFF);
Mark Brown4911ccd2011-12-02 21:59:18 +0000794}
795
Kuninori Morimotoe5449af2018-01-29 02:59:05 +0000796static const struct snd_soc_component_driver soc_component_dev_wm2000 = {
797 .probe = wm2000_probe,
798 .remove = wm2000_remove,
799 .suspend = wm2000_suspend,
800 .resume = wm2000_resume,
801 .controls = wm2000_controls,
802 .num_controls = ARRAY_SIZE(wm2000_controls),
803 .dapm_widgets = wm2000_dapm_widgets,
804 .num_dapm_widgets = ARRAY_SIZE(wm2000_dapm_widgets),
805 .dapm_routes = wm2000_audio_map,
806 .num_dapm_routes = ARRAY_SIZE(wm2000_audio_map),
807 .idle_bias_on = 1,
808 .use_pmdown_time = 1,
809 .endianness = 1,
810 .non_legacy_dai_naming = 1,
Mark Brown4911ccd2011-12-02 21:59:18 +0000811};
812
Bill Pemberton7a79e942012-12-07 09:26:37 -0500813static int wm2000_i2c_probe(struct i2c_client *i2c,
814 const struct i2c_device_id *i2c_id)
Mark Brown3a66d382010-02-11 13:27:19 +0000815{
816 struct wm2000_priv *wm2000;
817 struct wm2000_platform_data *pdata;
818 const char *filename;
Jesper Juhlc83f1d72012-01-23 22:28:44 +0100819 const struct firmware *fw = NULL;
Mark Browna89be932012-09-22 18:33:23 -0400820 int ret, i;
Lucas Tanurec5d09482018-10-19 17:44:22 +0100821 unsigned int reg;
Mark Brown3a66d382010-02-11 13:27:19 +0000822 u16 id;
823
Markus Elfringbf0842b2017-11-24 08:18:14 +0100824 wm2000 = devm_kzalloc(&i2c->dev, sizeof(*wm2000), GFP_KERNEL);
Sachin Kamata0f62112014-06-20 15:29:07 +0530825 if (!wm2000)
Mark Brown3a66d382010-02-11 13:27:19 +0000826 return -ENOMEM;
Mark Brown3a66d382010-02-11 13:27:19 +0000827
Mark Brown8e9bb422013-01-23 18:38:54 +0800828 mutex_init(&wm2000->lock);
829
Mark Brown8aa1fe82011-12-02 21:57:19 +0000830 dev_set_drvdata(&i2c->dev, wm2000);
831
Mark Brown8fed54a2012-09-22 18:32:08 -0400832 wm2000->regmap = devm_regmap_init_i2c(i2c, &wm2000_regmap);
Mark Brown8aa1fe82011-12-02 21:57:19 +0000833 if (IS_ERR(wm2000->regmap)) {
834 ret = PTR_ERR(wm2000->regmap);
835 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
836 ret);
Jesper Juhlc83f1d72012-01-23 22:28:44 +0100837 goto out;
Mark Brown8aa1fe82011-12-02 21:57:19 +0000838 }
839
Mark Browna89be932012-09-22 18:33:23 -0400840 for (i = 0; i < WM2000_NUM_SUPPLIES; i++)
841 wm2000->supplies[i].supply = wm2000_supplies[i];
842
843 ret = devm_regulator_bulk_get(&i2c->dev, WM2000_NUM_SUPPLIES,
844 wm2000->supplies);
845 if (ret != 0) {
846 dev_err(&i2c->dev, "Failed to get supplies: %d\n", ret);
847 return ret;
848 }
849
850 ret = regulator_bulk_enable(WM2000_NUM_SUPPLIES, wm2000->supplies);
851 if (ret != 0) {
852 dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret);
853 return ret;
854 }
855
Mark Brown3a66d382010-02-11 13:27:19 +0000856 /* Verify that this is a WM2000 */
Lucas Tanurec5d09482018-10-19 17:44:22 +0100857 ret = regmap_read(wm2000->regmap, WM2000_REG_ID1, &reg);
858 if (ret != 0) {
859 dev_err(&i2c->dev, "Unable to read ID1: %d\n", ret);
860 return ret;
861 }
Mark Brown3a66d382010-02-11 13:27:19 +0000862 id = reg << 8;
Lucas Tanurec5d09482018-10-19 17:44:22 +0100863 ret = regmap_read(wm2000->regmap, WM2000_REG_ID2, &reg);
864 if (ret != 0) {
865 dev_err(&i2c->dev, "Unable to read ID2: %d\n", ret);
866 return ret;
867 }
Mark Brown3a66d382010-02-11 13:27:19 +0000868 id |= reg & 0xff;
869
870 if (id != 0x2000) {
871 dev_err(&i2c->dev, "Device is not a WM2000 - ID %x\n", id);
872 ret = -ENODEV;
Mark Browna89be932012-09-22 18:33:23 -0400873 goto err_supplies;
Mark Brown3a66d382010-02-11 13:27:19 +0000874 }
875
Lucas Tanurec5d09482018-10-19 17:44:22 +0100876 ret = regmap_read(wm2000->regmap, WM2000_REG_REVISON, &reg);
877 if (ret != 0) {
878 dev_err(&i2c->dev, "Unable to read Revision: %d\n", ret);
879 return ret;
880 }
Mark Brown3a66d382010-02-11 13:27:19 +0000881 dev_info(&i2c->dev, "revision %c\n", reg + 'A');
882
Mark Brown514cfd62012-12-13 17:29:00 +0900883 wm2000->mclk = devm_clk_get(&i2c->dev, "MCLK");
884 if (IS_ERR(wm2000->mclk)) {
885 ret = PTR_ERR(wm2000->mclk);
886 dev_err(&i2c->dev, "Failed to get MCLK: %d\n", ret);
887 goto err_supplies;
888 }
889
Mark Brown3a66d382010-02-11 13:27:19 +0000890 filename = "wm2000_anc.bin";
891 pdata = dev_get_platdata(&i2c->dev);
892 if (pdata) {
Mark Brown3a66d382010-02-11 13:27:19 +0000893 wm2000->speech_clarity = !pdata->speech_enh_disable;
894
895 if (pdata->download_file)
896 filename = pdata->download_file;
897 }
898
899 ret = request_firmware(&fw, filename, &i2c->dev);
900 if (ret != 0) {
901 dev_err(&i2c->dev, "Failed to acquire ANC data: %d\n", ret);
Mark Browna89be932012-09-22 18:33:23 -0400902 goto err_supplies;
Mark Brown3a66d382010-02-11 13:27:19 +0000903 }
904
905 /* Pre-cook the concatenation of the register address onto the image */
906 wm2000->anc_download_size = fw->size + 2;
Mark Brownb03e96e2011-12-02 21:28:31 +0000907 wm2000->anc_download = devm_kzalloc(&i2c->dev,
908 wm2000->anc_download_size,
909 GFP_KERNEL);
Mark Brown3a66d382010-02-11 13:27:19 +0000910 if (wm2000->anc_download == NULL) {
Mark Brown3a66d382010-02-11 13:27:19 +0000911 ret = -ENOMEM;
Mark Browna89be932012-09-22 18:33:23 -0400912 goto err_supplies;
Mark Brown3a66d382010-02-11 13:27:19 +0000913 }
914
915 wm2000->anc_download[0] = 0x80;
916 wm2000->anc_download[1] = 0x00;
917 memcpy(wm2000->anc_download + 2, fw->data, fw->size);
918
Mark Brown3a66d382010-02-11 13:27:19 +0000919 wm2000->anc_eng_ena = 1;
Mark Browne71fa372010-06-15 15:14:00 +0100920 wm2000->anc_active = 1;
921 wm2000->spk_ena = 1;
Mark Brown3a66d382010-02-11 13:27:19 +0000922 wm2000->i2c = i2c;
923
924 wm2000_reset(wm2000);
925
Kuninori Morimotoe5449af2018-01-29 02:59:05 +0000926 ret = devm_snd_soc_register_component(&i2c->dev,
927 &soc_component_dev_wm2000, NULL, 0);
Mark Brown3a66d382010-02-11 13:27:19 +0000928
Mark Browna89be932012-09-22 18:33:23 -0400929err_supplies:
930 regulator_bulk_disable(WM2000_NUM_SUPPLIES, wm2000->supplies);
Mark Brown3a66d382010-02-11 13:27:19 +0000931
Jesper Juhlc83f1d72012-01-23 22:28:44 +0100932out:
933 release_firmware(fw);
Mark Brown3a66d382010-02-11 13:27:19 +0000934 return ret;
935}
936
Mark Brown3a66d382010-02-11 13:27:19 +0000937static const struct i2c_device_id wm2000_i2c_id[] = {
938 { "wm2000", 0 },
939 { }
940};
941MODULE_DEVICE_TABLE(i2c, wm2000_i2c_id);
942
943static struct i2c_driver wm2000_i2c_driver = {
944 .driver = {
945 .name = "wm2000",
Mark Brown3a66d382010-02-11 13:27:19 +0000946 },
947 .probe = wm2000_i2c_probe,
Mark Brown3a66d382010-02-11 13:27:19 +0000948 .id_table = wm2000_i2c_id,
949};
950
Sachin Kamat3a4bfd82012-08-06 17:25:54 +0530951module_i2c_driver(wm2000_i2c_driver);
Mark Brown3a66d382010-02-11 13:27:19 +0000952
953MODULE_DESCRIPTION("ASoC WM2000 driver");
954MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfonmicro.com>");
955MODULE_LICENSE("GPL");