blob: da9caf0d5317187292e173037b343090325bc281 [file] [log] [blame]
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +09001/*
2 * ak4642.c -- AK4642/AK4643 ALSA Soc Audio driver
3 *
4 * Copyright (C) 2009 Renesas Solutions Corp.
5 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
6 *
7 * Based on wm8731.c by Richard Purdie
8 * Based on ak4535.c by Richard Purdie
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/* ** CAUTION **
17 *
18 * This is very simple driver.
19 * It can use headphone output / stereo input only
20 *
Kuninori Morimoto20211392011-11-06 22:04:53 -080021 * AK4642 is tested.
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +090022 * AK4643 is tested.
23 */
24
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +090025#include <linux/delay.h>
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +090026#include <linux/i2c.h>
27#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040029#include <linux/module.h>
Liam Girdwoodce6120c2010-11-05 15:53:46 +020030#include <sound/soc.h>
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +090031#include <sound/initval.h>
Kuninori Morimotoa300de32010-07-01 14:23:45 +090032#include <sound/tlv.h>
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +090033
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +090034#define AK4642_VERSION "0.0.1"
35
36#define PW_MGMT1 0x00
37#define PW_MGMT2 0x01
38#define SG_SL1 0x02
39#define SG_SL2 0x03
40#define MD_CTL1 0x04
41#define MD_CTL2 0x05
42#define TIMER 0x06
43#define ALC_CTL1 0x07
44#define ALC_CTL2 0x08
45#define L_IVC 0x09
46#define L_DVC 0x0a
47#define ALC_CTL3 0x0b
48#define R_IVC 0x0c
49#define R_DVC 0x0d
50#define MD_CTL3 0x0e
51#define MD_CTL4 0x0f
52#define PW_MGMT3 0x10
53#define DF_S 0x11
54#define FIL3_0 0x12
55#define FIL3_1 0x13
56#define FIL3_2 0x14
57#define FIL3_3 0x15
58#define EQ_0 0x16
59#define EQ_1 0x17
60#define EQ_2 0x18
61#define EQ_3 0x19
62#define EQ_4 0x1a
63#define EQ_5 0x1b
64#define FIL1_0 0x1c
65#define FIL1_1 0x1d
66#define FIL1_2 0x1e
67#define FIL1_3 0x1f
68#define PW_MGMT4 0x20
69#define MD_CTL5 0x21
70#define LO_MS 0x22
71#define HP_MS 0x23
72#define SPK_MS 0x24
73
74#define AK4642_CACHEREGNUM 0x25
75
Kuninori Morimotoa3471232010-10-15 14:23:18 +090076/* PW_MGMT1*/
77#define PMVCM (1 << 6) /* VCOM Power Management */
78#define PMMIN (1 << 5) /* MIN Input Power Management */
79#define PMDAC (1 << 2) /* DAC Power Management */
80#define PMADL (1 << 0) /* MIC Amp Lch and ADC Lch Power Management */
81
Kuninori Morimoto0643ce82010-03-15 18:10:50 +090082/* PW_MGMT2 */
83#define HPMTN (1 << 6)
84#define PMHPL (1 << 5)
85#define PMHPR (1 << 4)
86#define MS (1 << 3) /* master/slave select */
87#define MCKO (1 << 1)
88#define PMPLL (1 << 0)
89
90#define PMHP_MASK (PMHPL | PMHPR)
91#define PMHP PMHP_MASK
92
Kuninori Morimotoa3471232010-10-15 14:23:18 +090093/* PW_MGMT3 */
94#define PMADR (1 << 0) /* MIC L / ADC R Power Management */
95
96/* SG_SL1 */
97#define MINS (1 << 6) /* Switch from MIN to Speaker */
98#define DACL (1 << 4) /* Switch from DAC to Stereo or Receiver */
99#define PMMP (1 << 2) /* MPWR pin Power Management */
100#define MGAIN0 (1 << 0) /* MIC amp gain*/
101
102/* TIMER */
103#define ZTM(param) ((param & 0x3) << 4) /* ALC Zoro Crossing TimeOut */
104#define WTM(param) (((param & 0x4) << 4) | ((param & 0x3) << 2))
105
106/* ALC_CTL1 */
107#define ALC (1 << 5) /* ALC Enable */
108#define LMTH0 (1 << 0) /* ALC Limiter / Recovery Level */
109
Kuninori Morimoto4b6316b2010-03-23 16:27:28 +0900110/* MD_CTL1 */
111#define PLL3 (1 << 7)
112#define PLL2 (1 << 6)
113#define PLL1 (1 << 5)
114#define PLL0 (1 << 4)
115#define PLL_MASK (PLL3 | PLL2 | PLL1 | PLL0)
116
Kuninori Morimoto0643ce82010-03-15 18:10:50 +0900117#define BCKO_MASK (1 << 3)
118#define BCKO_64 BCKO_MASK
119
Kuninori Morimotocb9c1302011-01-20 11:45:34 +0900120#define DIF_MASK (3 << 0)
121#define DSP (0 << 0)
122#define RIGHT_J (1 << 0)
123#define LEFT_J (2 << 0)
124#define I2S (3 << 0)
125
Kuninori Morimoto1ad747c2010-03-23 16:27:38 +0900126/* MD_CTL2 */
127#define FS0 (1 << 0)
128#define FS1 (1 << 1)
129#define FS2 (1 << 2)
130#define FS3 (1 << 5)
131#define FS_MASK (FS0 | FS1 | FS2 | FS3)
132
Kuninori Morimotoa3471232010-10-15 14:23:18 +0900133/* MD_CTL3 */
134#define BST1 (1 << 3)
135
136/* MD_CTL4 */
137#define DACH (1 << 0)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900138
Kuninori Morimotoa300de32010-07-01 14:23:45 +0900139/*
140 * Playback Volume (table 39)
141 *
142 * max : 0x00 : +12.0 dB
143 * ( 0.5 dB step )
144 * min : 0xFE : -115.0 dB
145 * mute: 0xFF
146 */
147static const DECLARE_TLV_DB_SCALE(out_tlv, -11500, 50, 1);
148
149static const struct snd_kcontrol_new ak4642_snd_controls[] = {
150
151 SOC_DOUBLE_R_TLV("Digital Playback Volume", L_DVC, R_DVC,
152 0, 0xFF, 1, out_tlv),
153};
154
Kuninori Morimoto24747da2011-11-10 16:21:31 -0800155static const struct snd_kcontrol_new ak4642_hpout_mixer_controls[] = {
156 SOC_DAPM_SINGLE("DACH", MD_CTL4, 0, 1, 0),
157};
158
159static const struct snd_soc_dapm_widget ak4642_dapm_widgets[] = {
160
161 /* Outputs */
162 SND_SOC_DAPM_OUTPUT("HPOUTL"),
163 SND_SOC_DAPM_OUTPUT("HPOUTR"),
164
165 SND_SOC_DAPM_MIXER("HPOUTL Mixer", PW_MGMT2, 5, 0,
166 &ak4642_hpout_mixer_controls[0],
167 ARRAY_SIZE(ak4642_hpout_mixer_controls)),
168
169 SND_SOC_DAPM_MIXER("HPOUTR Mixer", PW_MGMT2, 4, 0,
170 &ak4642_hpout_mixer_controls[0],
171 ARRAY_SIZE(ak4642_hpout_mixer_controls)),
172
173 /* DAC */
174 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", PW_MGMT1, 2, 0),
175};
176
177static const struct snd_soc_dapm_route ak4642_intercon[] = {
178
179 /* Outputs */
180 {"HPOUTL", NULL, "HPOUTL Mixer"},
181 {"HPOUTR", NULL, "HPOUTR Mixer"},
182
183 {"HPOUTL Mixer", "DACH", "DAC"},
184 {"HPOUTR Mixer", "DACH", "DAC"},
185};
Kuninori Morimotoa300de32010-07-01 14:23:45 +0900186
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900187/* codec private data */
188struct ak4642_priv {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000189 unsigned int sysclk;
190 enum snd_soc_control_type control_type;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900191};
192
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900193/*
194 * ak4642 register cache
195 */
Kuninori Morimoto19b115e2011-10-13 02:03:54 -0700196static const u8 ak4642_reg[AK4642_CACHEREGNUM] = {
197 0x00, 0x00, 0x01, 0x00,
198 0x02, 0x00, 0x00, 0x00,
199 0xe1, 0xe1, 0x18, 0x00,
200 0xe1, 0x18, 0x11, 0x08,
201 0x00, 0x00, 0x00, 0x00,
202 0x00, 0x00, 0x00, 0x00,
203 0x00, 0x00, 0x00, 0x00,
204 0x00, 0x00, 0x00, 0x00,
205 0x00, 0x00, 0x00, 0x00,
206 0x00,
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900207};
208
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900209static int ak4642_dai_startup(struct snd_pcm_substream *substream,
210 struct snd_soc_dai *dai)
211{
212 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
213 struct snd_soc_codec *codec = dai->codec;
214
215 if (is_play) {
216 /*
217 * start headphone output
218 *
219 * PLL, Master Mode
220 * Audio I/F Format :MSB justified (ADC & DAC)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900221 * Bass Boost Level : Middle
222 *
223 * This operation came from example code of
224 * "ASAHI KASEI AK4642" (japanese) manual p97.
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900225 */
Axel Linb91470b2011-10-11 20:20:53 +0800226 snd_soc_write(codec, L_IVC, 0x91); /* volume */
227 snd_soc_write(codec, R_IVC, 0x91); /* volume */
Kuninori Morimoto0643ce82010-03-15 18:10:50 +0900228 snd_soc_update_bits(codec, PW_MGMT2, HPMTN, HPMTN);
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900229 } else {
230 /*
231 * start stereo input
232 *
233 * PLL Master Mode
234 * Audio I/F Format:MSB justified (ADC & DAC)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900235 * Pre MIC AMP:+20dB
236 * MIC Power On
237 * ALC setting:Refer to Table 35
238 * ALC bit=“1”
239 *
240 * This operation came from example code of
241 * "ASAHI KASEI AK4642" (japanese) manual p94.
242 */
Axel Linb91470b2011-10-11 20:20:53 +0800243 snd_soc_write(codec, SG_SL1, PMMP | MGAIN0);
244 snd_soc_write(codec, TIMER, ZTM(0x3) | WTM(0x3));
245 snd_soc_write(codec, ALC_CTL1, ALC | LMTH0);
Kuninori Morimotoed2dd7d2011-11-10 16:21:01 -0800246 snd_soc_update_bits(codec, PW_MGMT1, PMADL, PMADL);
Kuninori Morimotoa3471232010-10-15 14:23:18 +0900247 snd_soc_update_bits(codec, PW_MGMT3, PMADR, PMADR);
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900248 }
249
250 return 0;
251}
252
253static void ak4642_dai_shutdown(struct snd_pcm_substream *substream,
254 struct snd_soc_dai *dai)
255{
256 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
257 struct snd_soc_codec *codec = dai->codec;
258
259 if (is_play) {
260 /* stop headphone output */
Kuninori Morimoto0643ce82010-03-15 18:10:50 +0900261 snd_soc_update_bits(codec, PW_MGMT2, HPMTN, 0);
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900262 } else {
263 /* stop stereo input */
Kuninori Morimotoa3471232010-10-15 14:23:18 +0900264 snd_soc_update_bits(codec, PW_MGMT1, PMADL, 0);
265 snd_soc_update_bits(codec, PW_MGMT3, PMADR, 0);
266 snd_soc_update_bits(codec, ALC_CTL1, ALC, 0);
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900267 }
268}
269
270static int ak4642_dai_set_sysclk(struct snd_soc_dai *codec_dai,
271 int clk_id, unsigned int freq, int dir)
272{
273 struct snd_soc_codec *codec = codec_dai->codec;
Kuninori Morimoto4b6316b2010-03-23 16:27:28 +0900274 u8 pll;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900275
Kuninori Morimoto4b6316b2010-03-23 16:27:28 +0900276 switch (freq) {
277 case 11289600:
278 pll = PLL2;
279 break;
280 case 12288000:
281 pll = PLL2 | PLL0;
282 break;
283 case 12000000:
284 pll = PLL2 | PLL1;
285 break;
286 case 24000000:
287 pll = PLL2 | PLL1 | PLL0;
288 break;
289 case 13500000:
290 pll = PLL3 | PLL2;
291 break;
292 case 27000000:
293 pll = PLL3 | PLL2 | PLL0;
294 break;
295 default:
296 return -EINVAL;
297 }
298 snd_soc_update_bits(codec, MD_CTL1, PLL_MASK, pll);
299
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900300 return 0;
301}
302
Kuninori Morimoto0643ce82010-03-15 18:10:50 +0900303static int ak4642_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
304{
305 struct snd_soc_codec *codec = dai->codec;
306 u8 data;
307 u8 bcko;
308
309 data = MCKO | PMPLL; /* use MCKO */
310 bcko = 0;
311
312 /* set master/slave audio interface */
313 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
314 case SND_SOC_DAIFMT_CBM_CFM:
315 data |= MS;
316 bcko = BCKO_64;
317 break;
318 case SND_SOC_DAIFMT_CBS_CFS:
319 break;
320 default:
321 return -EINVAL;
322 }
Kuninori Morimotobd7fdbc2011-07-06 17:58:56 -0700323 snd_soc_update_bits(codec, PW_MGMT2, MS | MCKO | PMPLL, data);
Kuninori Morimoto0643ce82010-03-15 18:10:50 +0900324 snd_soc_update_bits(codec, MD_CTL1, BCKO_MASK, bcko);
325
Kuninori Morimotocb9c1302011-01-20 11:45:34 +0900326 /* format type */
327 data = 0;
328 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
329 case SND_SOC_DAIFMT_LEFT_J:
330 data = LEFT_J;
331 break;
332 case SND_SOC_DAIFMT_I2S:
333 data = I2S;
334 break;
335 /* FIXME
336 * Please add RIGHT_J / DSP support here
337 */
338 default:
339 return -EINVAL;
340 break;
341 }
342 snd_soc_update_bits(codec, MD_CTL1, DIF_MASK, data);
343
Kuninori Morimoto0643ce82010-03-15 18:10:50 +0900344 return 0;
345}
346
Kuninori Morimoto1ad747c2010-03-23 16:27:38 +0900347static int ak4642_dai_hw_params(struct snd_pcm_substream *substream,
348 struct snd_pcm_hw_params *params,
349 struct snd_soc_dai *dai)
350{
351 struct snd_soc_codec *codec = dai->codec;
352 u8 rate;
353
354 switch (params_rate(params)) {
355 case 7350:
356 rate = FS2;
357 break;
358 case 8000:
359 rate = 0;
360 break;
361 case 11025:
362 rate = FS2 | FS0;
363 break;
364 case 12000:
365 rate = FS0;
366 break;
367 case 14700:
368 rate = FS2 | FS1;
369 break;
370 case 16000:
371 rate = FS1;
372 break;
373 case 22050:
374 rate = FS2 | FS1 | FS0;
375 break;
376 case 24000:
377 rate = FS1 | FS0;
378 break;
379 case 29400:
380 rate = FS3 | FS2 | FS1;
381 break;
382 case 32000:
383 rate = FS3 | FS1;
384 break;
385 case 44100:
386 rate = FS3 | FS2 | FS1 | FS0;
387 break;
388 case 48000:
389 rate = FS3 | FS1 | FS0;
390 break;
391 default:
392 return -EINVAL;
393 break;
394 }
395 snd_soc_update_bits(codec, MD_CTL2, FS_MASK, rate);
396
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900397 return 0;
398}
399
Kuninori Morimotoed2dd7d2011-11-10 16:21:01 -0800400static int ak4642_set_bias_level(struct snd_soc_codec *codec,
401 enum snd_soc_bias_level level)
402{
403 switch (level) {
404 case SND_SOC_BIAS_OFF:
405 snd_soc_write(codec, PW_MGMT1, 0x00);
406 break;
407 default:
408 snd_soc_update_bits(codec, PW_MGMT1, PMVCM, PMVCM);
409 break;
410 }
411 codec->dapm.bias_level = level;
412
413 return 0;
414}
415
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900416static struct snd_soc_dai_ops ak4642_dai_ops = {
417 .startup = ak4642_dai_startup,
418 .shutdown = ak4642_dai_shutdown,
419 .set_sysclk = ak4642_dai_set_sysclk,
Kuninori Morimoto0643ce82010-03-15 18:10:50 +0900420 .set_fmt = ak4642_dai_set_fmt,
Kuninori Morimoto1ad747c2010-03-23 16:27:38 +0900421 .hw_params = ak4642_dai_hw_params,
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900422};
423
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000424static struct snd_soc_dai_driver ak4642_dai = {
425 .name = "ak4642-hifi",
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900426 .playback = {
427 .stream_name = "Playback",
428 .channels_min = 1,
429 .channels_max = 2,
430 .rates = SNDRV_PCM_RATE_8000_48000,
431 .formats = SNDRV_PCM_FMTBIT_S16_LE },
432 .capture = {
433 .stream_name = "Capture",
434 .channels_min = 1,
435 .channels_max = 2,
436 .rates = SNDRV_PCM_RATE_8000_48000,
437 .formats = SNDRV_PCM_FMTBIT_S16_LE },
438 .ops = &ak4642_dai_ops,
Kuninori Morimoto1ad747c2010-03-23 16:27:38 +0900439 .symmetric_rates = 1,
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900440};
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900441
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000442static int ak4642_resume(struct snd_soc_codec *codec)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900443{
Axel Linb91470b2011-10-11 20:20:53 +0800444 snd_soc_cache_sync(codec);
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900445 return 0;
446}
447
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000448
449static int ak4642_probe(struct snd_soc_codec *codec)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900450{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000451 struct ak4642_priv *ak4642 = snd_soc_codec_get_drvdata(codec);
Axel Linb91470b2011-10-11 20:20:53 +0800452 int ret;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900453
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000454 dev_info(codec->dev, "AK4642 Audio Codec %s", AK4642_VERSION);
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900455
Axel Linb91470b2011-10-11 20:20:53 +0800456 ret = snd_soc_codec_set_cache_io(codec, 8, 8, ak4642->control_type);
457 if (ret < 0) {
458 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
459 return ret;
460 }
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900461
Kuninori Morimoto73bb3792010-09-03 16:12:36 +0900462 snd_soc_add_controls(codec, ak4642_snd_controls,
463 ARRAY_SIZE(ak4642_snd_controls));
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900464
Kuninori Morimotoed2dd7d2011-11-10 16:21:01 -0800465 ak4642_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
466
467 return 0;
468}
469
470static int ak4642_remove(struct snd_soc_codec *codec)
471{
472 ak4642_set_bias_level(codec, SND_SOC_BIAS_OFF);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000473 return 0;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900474}
475
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000476static struct snd_soc_codec_driver soc_codec_dev_ak4642 = {
Kuninori Morimoto0ce75aa2010-09-16 13:06:40 +0900477 .probe = ak4642_probe,
Kuninori Morimotoed2dd7d2011-11-10 16:21:01 -0800478 .remove = ak4642_remove,
Kuninori Morimoto0ce75aa2010-09-16 13:06:40 +0900479 .resume = ak4642_resume,
Kuninori Morimotoed2dd7d2011-11-10 16:21:01 -0800480 .set_bias_level = ak4642_set_bias_level,
Kuninori Morimoto0ce75aa2010-09-16 13:06:40 +0900481 .reg_cache_size = ARRAY_SIZE(ak4642_reg),
482 .reg_word_size = sizeof(u8),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000483 .reg_cache_default = ak4642_reg,
Kuninori Morimoto24747da2011-11-10 16:21:31 -0800484 .dapm_widgets = ak4642_dapm_widgets,
485 .num_dapm_widgets = ARRAY_SIZE(ak4642_dapm_widgets),
486 .dapm_routes = ak4642_intercon,
487 .num_dapm_routes = ARRAY_SIZE(ak4642_intercon),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000488};
489
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900490#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000491static __devinit int ak4642_i2c_probe(struct i2c_client *i2c,
492 const struct i2c_device_id *id)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900493{
494 struct ak4642_priv *ak4642;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900495 int ret;
496
497 ak4642 = kzalloc(sizeof(struct ak4642_priv), GFP_KERNEL);
Kuninori Morimoto0ce75aa2010-09-16 13:06:40 +0900498 if (!ak4642)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900499 return -ENOMEM;
500
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900501 i2c_set_clientdata(i2c, ak4642);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000502 ak4642->control_type = SND_SOC_I2C;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900503
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000504 ret = snd_soc_register_codec(&i2c->dev,
505 &soc_codec_dev_ak4642, &ak4642_dai, 1);
506 if (ret < 0)
Axel Lin7bcaad92010-07-23 05:53:44 +0000507 kfree(ak4642);
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900508 return ret;
509}
510
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000511static __devexit int ak4642_i2c_remove(struct i2c_client *client)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900512{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000513 snd_soc_unregister_codec(&client->dev);
514 kfree(i2c_get_clientdata(client));
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900515 return 0;
516}
517
518static const struct i2c_device_id ak4642_i2c_id[] = {
519 { "ak4642", 0 },
520 { "ak4643", 0 },
521 { }
522};
523MODULE_DEVICE_TABLE(i2c, ak4642_i2c_id);
524
525static struct i2c_driver ak4642_i2c_driver = {
526 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000527 .name = "ak4642-codec",
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900528 .owner = THIS_MODULE,
529 },
Kuninori Morimoto0ce75aa2010-09-16 13:06:40 +0900530 .probe = ak4642_i2c_probe,
531 .remove = __devexit_p(ak4642_i2c_remove),
532 .id_table = ak4642_i2c_id,
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900533};
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900534#endif
535
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900536static int __init ak4642_modinit(void)
537{
Kuninori Morimoto1cf86f62009-12-15 15:54:21 +0900538 int ret = 0;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900539#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
540 ret = i2c_add_driver(&ak4642_i2c_driver);
541#endif
542 return ret;
543
544}
545module_init(ak4642_modinit);
546
547static void __exit ak4642_exit(void)
548{
549#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
550 i2c_del_driver(&ak4642_i2c_driver);
551#endif
552
553}
554module_exit(ak4642_exit);
555
556MODULE_DESCRIPTION("Soc AK4642 driver");
557MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>");
558MODULE_LICENSE("GPL");