blob: b2460c2eebe00b386609caeaaed73eecacc7ac3e [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),
Kuninori Morimoto3c703522011-11-10 16:21:42 -0800153
154 SOC_SINGLE("Headphone Switch", PW_MGMT2, 6, 1, 0),
Kuninori Morimotoa300de32010-07-01 14:23:45 +0900155};
156
Kuninori Morimoto24747da2011-11-10 16:21:31 -0800157static const struct snd_kcontrol_new ak4642_hpout_mixer_controls[] = {
158 SOC_DAPM_SINGLE("DACH", MD_CTL4, 0, 1, 0),
159};
160
161static const struct snd_soc_dapm_widget ak4642_dapm_widgets[] = {
162
163 /* Outputs */
164 SND_SOC_DAPM_OUTPUT("HPOUTL"),
165 SND_SOC_DAPM_OUTPUT("HPOUTR"),
166
167 SND_SOC_DAPM_MIXER("HPOUTL Mixer", PW_MGMT2, 5, 0,
168 &ak4642_hpout_mixer_controls[0],
169 ARRAY_SIZE(ak4642_hpout_mixer_controls)),
170
171 SND_SOC_DAPM_MIXER("HPOUTR Mixer", PW_MGMT2, 4, 0,
172 &ak4642_hpout_mixer_controls[0],
173 ARRAY_SIZE(ak4642_hpout_mixer_controls)),
174
175 /* DAC */
176 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", PW_MGMT1, 2, 0),
177};
178
179static const struct snd_soc_dapm_route ak4642_intercon[] = {
180
181 /* Outputs */
182 {"HPOUTL", NULL, "HPOUTL Mixer"},
183 {"HPOUTR", NULL, "HPOUTR Mixer"},
184
185 {"HPOUTL Mixer", "DACH", "DAC"},
186 {"HPOUTR Mixer", "DACH", "DAC"},
187};
Kuninori Morimotoa300de32010-07-01 14:23:45 +0900188
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900189/* codec private data */
190struct ak4642_priv {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000191 unsigned int sysclk;
192 enum snd_soc_control_type control_type;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900193};
194
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900195/*
196 * ak4642 register cache
197 */
Kuninori Morimoto19b115e2011-10-13 02:03:54 -0700198static const u8 ak4642_reg[AK4642_CACHEREGNUM] = {
199 0x00, 0x00, 0x01, 0x00,
200 0x02, 0x00, 0x00, 0x00,
201 0xe1, 0xe1, 0x18, 0x00,
202 0xe1, 0x18, 0x11, 0x08,
203 0x00, 0x00, 0x00, 0x00,
204 0x00, 0x00, 0x00, 0x00,
205 0x00, 0x00, 0x00, 0x00,
206 0x00, 0x00, 0x00, 0x00,
207 0x00, 0x00, 0x00, 0x00,
208 0x00,
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900209};
210
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900211static int ak4642_dai_startup(struct snd_pcm_substream *substream,
212 struct snd_soc_dai *dai)
213{
214 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
215 struct snd_soc_codec *codec = dai->codec;
216
217 if (is_play) {
218 /*
219 * start headphone output
220 *
221 * PLL, Master Mode
222 * Audio I/F Format :MSB justified (ADC & DAC)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900223 * Bass Boost Level : Middle
224 *
225 * This operation came from example code of
226 * "ASAHI KASEI AK4642" (japanese) manual p97.
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900227 */
Axel Linb91470b2011-10-11 20:20:53 +0800228 snd_soc_write(codec, L_IVC, 0x91); /* volume */
229 snd_soc_write(codec, R_IVC, 0x91); /* volume */
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900230 } else {
231 /*
232 * start stereo input
233 *
234 * PLL Master Mode
235 * Audio I/F Format:MSB justified (ADC & DAC)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900236 * Pre MIC AMP:+20dB
237 * MIC Power On
238 * ALC setting:Refer to Table 35
239 * ALC bit=“1”
240 *
241 * This operation came from example code of
242 * "ASAHI KASEI AK4642" (japanese) manual p94.
243 */
Axel Linb91470b2011-10-11 20:20:53 +0800244 snd_soc_write(codec, SG_SL1, PMMP | MGAIN0);
245 snd_soc_write(codec, TIMER, ZTM(0x3) | WTM(0x3));
246 snd_soc_write(codec, ALC_CTL1, ALC | LMTH0);
Kuninori Morimotoed2dd7d2011-11-10 16:21:01 -0800247 snd_soc_update_bits(codec, PW_MGMT1, PMADL, PMADL);
Kuninori Morimotoa3471232010-10-15 14:23:18 +0900248 snd_soc_update_bits(codec, PW_MGMT3, PMADR, PMADR);
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900249 }
250
251 return 0;
252}
253
254static void ak4642_dai_shutdown(struct snd_pcm_substream *substream,
255 struct snd_soc_dai *dai)
256{
257 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
258 struct snd_soc_codec *codec = dai->codec;
259
260 if (is_play) {
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900261 } else {
262 /* stop stereo input */
Kuninori Morimotoa3471232010-10-15 14:23:18 +0900263 snd_soc_update_bits(codec, PW_MGMT1, PMADL, 0);
264 snd_soc_update_bits(codec, PW_MGMT3, PMADR, 0);
265 snd_soc_update_bits(codec, ALC_CTL1, ALC, 0);
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900266 }
267}
268
269static int ak4642_dai_set_sysclk(struct snd_soc_dai *codec_dai,
270 int clk_id, unsigned int freq, int dir)
271{
272 struct snd_soc_codec *codec = codec_dai->codec;
Kuninori Morimoto4b6316b2010-03-23 16:27:28 +0900273 u8 pll;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900274
Kuninori Morimoto4b6316b2010-03-23 16:27:28 +0900275 switch (freq) {
276 case 11289600:
277 pll = PLL2;
278 break;
279 case 12288000:
280 pll = PLL2 | PLL0;
281 break;
282 case 12000000:
283 pll = PLL2 | PLL1;
284 break;
285 case 24000000:
286 pll = PLL2 | PLL1 | PLL0;
287 break;
288 case 13500000:
289 pll = PLL3 | PLL2;
290 break;
291 case 27000000:
292 pll = PLL3 | PLL2 | PLL0;
293 break;
294 default:
295 return -EINVAL;
296 }
297 snd_soc_update_bits(codec, MD_CTL1, PLL_MASK, pll);
298
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900299 return 0;
300}
301
Kuninori Morimoto0643ce82010-03-15 18:10:50 +0900302static int ak4642_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
303{
304 struct snd_soc_codec *codec = dai->codec;
305 u8 data;
306 u8 bcko;
307
308 data = MCKO | PMPLL; /* use MCKO */
309 bcko = 0;
310
311 /* set master/slave audio interface */
312 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
313 case SND_SOC_DAIFMT_CBM_CFM:
314 data |= MS;
315 bcko = BCKO_64;
316 break;
317 case SND_SOC_DAIFMT_CBS_CFS:
318 break;
319 default:
320 return -EINVAL;
321 }
Kuninori Morimotobd7fdbc2011-07-06 17:58:56 -0700322 snd_soc_update_bits(codec, PW_MGMT2, MS | MCKO | PMPLL, data);
Kuninori Morimoto0643ce82010-03-15 18:10:50 +0900323 snd_soc_update_bits(codec, MD_CTL1, BCKO_MASK, bcko);
324
Kuninori Morimotocb9c1302011-01-20 11:45:34 +0900325 /* format type */
326 data = 0;
327 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
328 case SND_SOC_DAIFMT_LEFT_J:
329 data = LEFT_J;
330 break;
331 case SND_SOC_DAIFMT_I2S:
332 data = I2S;
333 break;
334 /* FIXME
335 * Please add RIGHT_J / DSP support here
336 */
337 default:
338 return -EINVAL;
339 break;
340 }
341 snd_soc_update_bits(codec, MD_CTL1, DIF_MASK, data);
342
Kuninori Morimoto0643ce82010-03-15 18:10:50 +0900343 return 0;
344}
345
Kuninori Morimoto1ad747c2010-03-23 16:27:38 +0900346static int ak4642_dai_hw_params(struct snd_pcm_substream *substream,
347 struct snd_pcm_hw_params *params,
348 struct snd_soc_dai *dai)
349{
350 struct snd_soc_codec *codec = dai->codec;
351 u8 rate;
352
353 switch (params_rate(params)) {
354 case 7350:
355 rate = FS2;
356 break;
357 case 8000:
358 rate = 0;
359 break;
360 case 11025:
361 rate = FS2 | FS0;
362 break;
363 case 12000:
364 rate = FS0;
365 break;
366 case 14700:
367 rate = FS2 | FS1;
368 break;
369 case 16000:
370 rate = FS1;
371 break;
372 case 22050:
373 rate = FS2 | FS1 | FS0;
374 break;
375 case 24000:
376 rate = FS1 | FS0;
377 break;
378 case 29400:
379 rate = FS3 | FS2 | FS1;
380 break;
381 case 32000:
382 rate = FS3 | FS1;
383 break;
384 case 44100:
385 rate = FS3 | FS2 | FS1 | FS0;
386 break;
387 case 48000:
388 rate = FS3 | FS1 | FS0;
389 break;
390 default:
391 return -EINVAL;
392 break;
393 }
394 snd_soc_update_bits(codec, MD_CTL2, FS_MASK, rate);
395
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900396 return 0;
397}
398
Kuninori Morimotoed2dd7d2011-11-10 16:21:01 -0800399static int ak4642_set_bias_level(struct snd_soc_codec *codec,
400 enum snd_soc_bias_level level)
401{
402 switch (level) {
403 case SND_SOC_BIAS_OFF:
404 snd_soc_write(codec, PW_MGMT1, 0x00);
405 break;
406 default:
407 snd_soc_update_bits(codec, PW_MGMT1, PMVCM, PMVCM);
408 break;
409 }
410 codec->dapm.bias_level = level;
411
412 return 0;
413}
414
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900415static struct snd_soc_dai_ops ak4642_dai_ops = {
416 .startup = ak4642_dai_startup,
417 .shutdown = ak4642_dai_shutdown,
418 .set_sysclk = ak4642_dai_set_sysclk,
Kuninori Morimoto0643ce82010-03-15 18:10:50 +0900419 .set_fmt = ak4642_dai_set_fmt,
Kuninori Morimoto1ad747c2010-03-23 16:27:38 +0900420 .hw_params = ak4642_dai_hw_params,
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900421};
422
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000423static struct snd_soc_dai_driver ak4642_dai = {
424 .name = "ak4642-hifi",
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900425 .playback = {
426 .stream_name = "Playback",
427 .channels_min = 1,
428 .channels_max = 2,
429 .rates = SNDRV_PCM_RATE_8000_48000,
430 .formats = SNDRV_PCM_FMTBIT_S16_LE },
431 .capture = {
432 .stream_name = "Capture",
433 .channels_min = 1,
434 .channels_max = 2,
435 .rates = SNDRV_PCM_RATE_8000_48000,
436 .formats = SNDRV_PCM_FMTBIT_S16_LE },
437 .ops = &ak4642_dai_ops,
Kuninori Morimoto1ad747c2010-03-23 16:27:38 +0900438 .symmetric_rates = 1,
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900439};
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900440
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000441static int ak4642_resume(struct snd_soc_codec *codec)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900442{
Axel Linb91470b2011-10-11 20:20:53 +0800443 snd_soc_cache_sync(codec);
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900444 return 0;
445}
446
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000447
448static int ak4642_probe(struct snd_soc_codec *codec)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900449{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000450 struct ak4642_priv *ak4642 = snd_soc_codec_get_drvdata(codec);
Axel Linb91470b2011-10-11 20:20:53 +0800451 int ret;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900452
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000453 dev_info(codec->dev, "AK4642 Audio Codec %s", AK4642_VERSION);
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900454
Axel Linb91470b2011-10-11 20:20:53 +0800455 ret = snd_soc_codec_set_cache_io(codec, 8, 8, ak4642->control_type);
456 if (ret < 0) {
457 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
458 return ret;
459 }
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900460
Kuninori Morimoto73bb3792010-09-03 16:12:36 +0900461 snd_soc_add_controls(codec, ak4642_snd_controls,
462 ARRAY_SIZE(ak4642_snd_controls));
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900463
Kuninori Morimotoed2dd7d2011-11-10 16:21:01 -0800464 ak4642_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
465
466 return 0;
467}
468
469static int ak4642_remove(struct snd_soc_codec *codec)
470{
471 ak4642_set_bias_level(codec, SND_SOC_BIAS_OFF);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000472 return 0;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900473}
474
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000475static struct snd_soc_codec_driver soc_codec_dev_ak4642 = {
Kuninori Morimoto0ce75aa2010-09-16 13:06:40 +0900476 .probe = ak4642_probe,
Kuninori Morimotoed2dd7d2011-11-10 16:21:01 -0800477 .remove = ak4642_remove,
Kuninori Morimoto0ce75aa2010-09-16 13:06:40 +0900478 .resume = ak4642_resume,
Kuninori Morimotoed2dd7d2011-11-10 16:21:01 -0800479 .set_bias_level = ak4642_set_bias_level,
Kuninori Morimoto0ce75aa2010-09-16 13:06:40 +0900480 .reg_cache_size = ARRAY_SIZE(ak4642_reg),
481 .reg_word_size = sizeof(u8),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000482 .reg_cache_default = ak4642_reg,
Kuninori Morimoto24747da2011-11-10 16:21:31 -0800483 .dapm_widgets = ak4642_dapm_widgets,
484 .num_dapm_widgets = ARRAY_SIZE(ak4642_dapm_widgets),
485 .dapm_routes = ak4642_intercon,
486 .num_dapm_routes = ARRAY_SIZE(ak4642_intercon),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000487};
488
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900489#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000490static __devinit int ak4642_i2c_probe(struct i2c_client *i2c,
491 const struct i2c_device_id *id)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900492{
493 struct ak4642_priv *ak4642;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900494 int ret;
495
496 ak4642 = kzalloc(sizeof(struct ak4642_priv), GFP_KERNEL);
Kuninori Morimoto0ce75aa2010-09-16 13:06:40 +0900497 if (!ak4642)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900498 return -ENOMEM;
499
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900500 i2c_set_clientdata(i2c, ak4642);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000501 ak4642->control_type = SND_SOC_I2C;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900502
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000503 ret = snd_soc_register_codec(&i2c->dev,
504 &soc_codec_dev_ak4642, &ak4642_dai, 1);
505 if (ret < 0)
Axel Lin7bcaad92010-07-23 05:53:44 +0000506 kfree(ak4642);
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900507 return ret;
508}
509
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000510static __devexit int ak4642_i2c_remove(struct i2c_client *client)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900511{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000512 snd_soc_unregister_codec(&client->dev);
513 kfree(i2c_get_clientdata(client));
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900514 return 0;
515}
516
517static const struct i2c_device_id ak4642_i2c_id[] = {
518 { "ak4642", 0 },
519 { "ak4643", 0 },
520 { }
521};
522MODULE_DEVICE_TABLE(i2c, ak4642_i2c_id);
523
524static struct i2c_driver ak4642_i2c_driver = {
525 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000526 .name = "ak4642-codec",
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900527 .owner = THIS_MODULE,
528 },
Kuninori Morimoto0ce75aa2010-09-16 13:06:40 +0900529 .probe = ak4642_i2c_probe,
530 .remove = __devexit_p(ak4642_i2c_remove),
531 .id_table = ak4642_i2c_id,
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900532};
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900533#endif
534
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900535static int __init ak4642_modinit(void)
536{
Kuninori Morimoto1cf86f62009-12-15 15:54:21 +0900537 int ret = 0;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900538#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
539 ret = i2c_add_driver(&ak4642_i2c_driver);
540#endif
541 return ret;
542
543}
544module_init(ak4642_modinit);
545
546static void __exit ak4642_exit(void)
547{
548#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
549 i2c_del_driver(&ak4642_i2c_driver);
550#endif
551
552}
553module_exit(ak4642_exit);
554
555MODULE_DESCRIPTION("Soc AK4642 driver");
556MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>");
557MODULE_LICENSE("GPL");