blob: daec5f75def20867d2053ec9f98cb06565ffabb2 [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
Kuninori Morimotoe8c83db2011-11-10 16:21:55 -0800161static const struct snd_kcontrol_new ak4642_lout_mixer_controls[] = {
162 SOC_DAPM_SINGLE("DACL", SG_SL1, 4, 1, 0),
163};
164
Kuninori Morimoto24747da2011-11-10 16:21:31 -0800165static const struct snd_soc_dapm_widget ak4642_dapm_widgets[] = {
166
167 /* Outputs */
168 SND_SOC_DAPM_OUTPUT("HPOUTL"),
169 SND_SOC_DAPM_OUTPUT("HPOUTR"),
Kuninori Morimotoe8c83db2011-11-10 16:21:55 -0800170 SND_SOC_DAPM_OUTPUT("LINEOUT"),
Kuninori Morimoto24747da2011-11-10 16:21:31 -0800171
172 SND_SOC_DAPM_MIXER("HPOUTL Mixer", PW_MGMT2, 5, 0,
173 &ak4642_hpout_mixer_controls[0],
174 ARRAY_SIZE(ak4642_hpout_mixer_controls)),
175
176 SND_SOC_DAPM_MIXER("HPOUTR Mixer", PW_MGMT2, 4, 0,
177 &ak4642_hpout_mixer_controls[0],
178 ARRAY_SIZE(ak4642_hpout_mixer_controls)),
179
Kuninori Morimotoe8c83db2011-11-10 16:21:55 -0800180 SND_SOC_DAPM_MIXER("LINEOUT Mixer", PW_MGMT1, 3, 0,
181 &ak4642_lout_mixer_controls[0],
182 ARRAY_SIZE(ak4642_lout_mixer_controls)),
183
Kuninori Morimoto24747da2011-11-10 16:21:31 -0800184 /* DAC */
185 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", PW_MGMT1, 2, 0),
186};
187
188static const struct snd_soc_dapm_route ak4642_intercon[] = {
189
190 /* Outputs */
191 {"HPOUTL", NULL, "HPOUTL Mixer"},
192 {"HPOUTR", NULL, "HPOUTR Mixer"},
Kuninori Morimotoe8c83db2011-11-10 16:21:55 -0800193 {"LINEOUT", NULL, "LINEOUT Mixer"},
Kuninori Morimoto24747da2011-11-10 16:21:31 -0800194
195 {"HPOUTL Mixer", "DACH", "DAC"},
196 {"HPOUTR Mixer", "DACH", "DAC"},
Kuninori Morimotoe8c83db2011-11-10 16:21:55 -0800197 {"LINEOUT Mixer", "DACL", "DAC"},
Kuninori Morimoto24747da2011-11-10 16:21:31 -0800198};
Kuninori Morimotoa300de32010-07-01 14:23:45 +0900199
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900200/* codec private data */
201struct ak4642_priv {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000202 unsigned int sysclk;
203 enum snd_soc_control_type control_type;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900204};
205
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900206/*
207 * ak4642 register cache
208 */
Kuninori Morimoto19b115e2011-10-13 02:03:54 -0700209static const u8 ak4642_reg[AK4642_CACHEREGNUM] = {
210 0x00, 0x00, 0x01, 0x00,
211 0x02, 0x00, 0x00, 0x00,
212 0xe1, 0xe1, 0x18, 0x00,
213 0xe1, 0x18, 0x11, 0x08,
214 0x00, 0x00, 0x00, 0x00,
215 0x00, 0x00, 0x00, 0x00,
216 0x00, 0x00, 0x00, 0x00,
217 0x00, 0x00, 0x00, 0x00,
218 0x00, 0x00, 0x00, 0x00,
219 0x00,
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900220};
221
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900222static int ak4642_dai_startup(struct snd_pcm_substream *substream,
223 struct snd_soc_dai *dai)
224{
225 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
226 struct snd_soc_codec *codec = dai->codec;
227
228 if (is_play) {
229 /*
230 * start headphone output
231 *
232 * PLL, Master Mode
233 * Audio I/F Format :MSB justified (ADC & DAC)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900234 * Bass Boost Level : Middle
235 *
236 * This operation came from example code of
237 * "ASAHI KASEI AK4642" (japanese) manual p97.
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900238 */
Axel Linb91470b2011-10-11 20:20:53 +0800239 snd_soc_write(codec, L_IVC, 0x91); /* volume */
240 snd_soc_write(codec, R_IVC, 0x91); /* volume */
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900241 } else {
242 /*
243 * start stereo input
244 *
245 * PLL Master Mode
246 * Audio I/F Format:MSB justified (ADC & DAC)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900247 * Pre MIC AMP:+20dB
248 * MIC Power On
249 * ALC setting:Refer to Table 35
250 * ALC bit=“1”
251 *
252 * This operation came from example code of
253 * "ASAHI KASEI AK4642" (japanese) manual p94.
254 */
Axel Linb91470b2011-10-11 20:20:53 +0800255 snd_soc_write(codec, SG_SL1, PMMP | MGAIN0);
256 snd_soc_write(codec, TIMER, ZTM(0x3) | WTM(0x3));
257 snd_soc_write(codec, ALC_CTL1, ALC | LMTH0);
Kuninori Morimotoed2dd7d2011-11-10 16:21:01 -0800258 snd_soc_update_bits(codec, PW_MGMT1, PMADL, PMADL);
Kuninori Morimotoa3471232010-10-15 14:23:18 +0900259 snd_soc_update_bits(codec, PW_MGMT3, PMADR, PMADR);
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900260 }
261
262 return 0;
263}
264
265static void ak4642_dai_shutdown(struct snd_pcm_substream *substream,
266 struct snd_soc_dai *dai)
267{
268 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
269 struct snd_soc_codec *codec = dai->codec;
270
271 if (is_play) {
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900272 } else {
273 /* stop stereo input */
Kuninori Morimotoa3471232010-10-15 14:23:18 +0900274 snd_soc_update_bits(codec, PW_MGMT1, PMADL, 0);
275 snd_soc_update_bits(codec, PW_MGMT3, PMADR, 0);
276 snd_soc_update_bits(codec, ALC_CTL1, ALC, 0);
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900277 }
278}
279
280static int ak4642_dai_set_sysclk(struct snd_soc_dai *codec_dai,
281 int clk_id, unsigned int freq, int dir)
282{
283 struct snd_soc_codec *codec = codec_dai->codec;
Kuninori Morimoto4b6316b2010-03-23 16:27:28 +0900284 u8 pll;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900285
Kuninori Morimoto4b6316b2010-03-23 16:27:28 +0900286 switch (freq) {
287 case 11289600:
288 pll = PLL2;
289 break;
290 case 12288000:
291 pll = PLL2 | PLL0;
292 break;
293 case 12000000:
294 pll = PLL2 | PLL1;
295 break;
296 case 24000000:
297 pll = PLL2 | PLL1 | PLL0;
298 break;
299 case 13500000:
300 pll = PLL3 | PLL2;
301 break;
302 case 27000000:
303 pll = PLL3 | PLL2 | PLL0;
304 break;
305 default:
306 return -EINVAL;
307 }
308 snd_soc_update_bits(codec, MD_CTL1, PLL_MASK, pll);
309
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900310 return 0;
311}
312
Kuninori Morimoto0643ce82010-03-15 18:10:50 +0900313static int ak4642_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
314{
315 struct snd_soc_codec *codec = dai->codec;
316 u8 data;
317 u8 bcko;
318
319 data = MCKO | PMPLL; /* use MCKO */
320 bcko = 0;
321
322 /* set master/slave audio interface */
323 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
324 case SND_SOC_DAIFMT_CBM_CFM:
325 data |= MS;
326 bcko = BCKO_64;
327 break;
328 case SND_SOC_DAIFMT_CBS_CFS:
329 break;
330 default:
331 return -EINVAL;
332 }
Kuninori Morimotobd7fdbc2011-07-06 17:58:56 -0700333 snd_soc_update_bits(codec, PW_MGMT2, MS | MCKO | PMPLL, data);
Kuninori Morimoto0643ce82010-03-15 18:10:50 +0900334 snd_soc_update_bits(codec, MD_CTL1, BCKO_MASK, bcko);
335
Kuninori Morimotocb9c1302011-01-20 11:45:34 +0900336 /* format type */
337 data = 0;
338 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
339 case SND_SOC_DAIFMT_LEFT_J:
340 data = LEFT_J;
341 break;
342 case SND_SOC_DAIFMT_I2S:
343 data = I2S;
344 break;
345 /* FIXME
346 * Please add RIGHT_J / DSP support here
347 */
348 default:
349 return -EINVAL;
350 break;
351 }
352 snd_soc_update_bits(codec, MD_CTL1, DIF_MASK, data);
353
Kuninori Morimoto0643ce82010-03-15 18:10:50 +0900354 return 0;
355}
356
Kuninori Morimoto1ad747c2010-03-23 16:27:38 +0900357static int ak4642_dai_hw_params(struct snd_pcm_substream *substream,
358 struct snd_pcm_hw_params *params,
359 struct snd_soc_dai *dai)
360{
361 struct snd_soc_codec *codec = dai->codec;
362 u8 rate;
363
364 switch (params_rate(params)) {
365 case 7350:
366 rate = FS2;
367 break;
368 case 8000:
369 rate = 0;
370 break;
371 case 11025:
372 rate = FS2 | FS0;
373 break;
374 case 12000:
375 rate = FS0;
376 break;
377 case 14700:
378 rate = FS2 | FS1;
379 break;
380 case 16000:
381 rate = FS1;
382 break;
383 case 22050:
384 rate = FS2 | FS1 | FS0;
385 break;
386 case 24000:
387 rate = FS1 | FS0;
388 break;
389 case 29400:
390 rate = FS3 | FS2 | FS1;
391 break;
392 case 32000:
393 rate = FS3 | FS1;
394 break;
395 case 44100:
396 rate = FS3 | FS2 | FS1 | FS0;
397 break;
398 case 48000:
399 rate = FS3 | FS1 | FS0;
400 break;
401 default:
402 return -EINVAL;
403 break;
404 }
405 snd_soc_update_bits(codec, MD_CTL2, FS_MASK, rate);
406
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900407 return 0;
408}
409
Kuninori Morimotoed2dd7d2011-11-10 16:21:01 -0800410static int ak4642_set_bias_level(struct snd_soc_codec *codec,
411 enum snd_soc_bias_level level)
412{
413 switch (level) {
414 case SND_SOC_BIAS_OFF:
415 snd_soc_write(codec, PW_MGMT1, 0x00);
416 break;
417 default:
418 snd_soc_update_bits(codec, PW_MGMT1, PMVCM, PMVCM);
419 break;
420 }
421 codec->dapm.bias_level = level;
422
423 return 0;
424}
425
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900426static struct snd_soc_dai_ops ak4642_dai_ops = {
427 .startup = ak4642_dai_startup,
428 .shutdown = ak4642_dai_shutdown,
429 .set_sysclk = ak4642_dai_set_sysclk,
Kuninori Morimoto0643ce82010-03-15 18:10:50 +0900430 .set_fmt = ak4642_dai_set_fmt,
Kuninori Morimoto1ad747c2010-03-23 16:27:38 +0900431 .hw_params = ak4642_dai_hw_params,
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900432};
433
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000434static struct snd_soc_dai_driver ak4642_dai = {
435 .name = "ak4642-hifi",
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900436 .playback = {
437 .stream_name = "Playback",
438 .channels_min = 1,
439 .channels_max = 2,
440 .rates = SNDRV_PCM_RATE_8000_48000,
441 .formats = SNDRV_PCM_FMTBIT_S16_LE },
442 .capture = {
443 .stream_name = "Capture",
444 .channels_min = 1,
445 .channels_max = 2,
446 .rates = SNDRV_PCM_RATE_8000_48000,
447 .formats = SNDRV_PCM_FMTBIT_S16_LE },
448 .ops = &ak4642_dai_ops,
Kuninori Morimoto1ad747c2010-03-23 16:27:38 +0900449 .symmetric_rates = 1,
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900450};
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900451
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000452static int ak4642_resume(struct snd_soc_codec *codec)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900453{
Axel Linb91470b2011-10-11 20:20:53 +0800454 snd_soc_cache_sync(codec);
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900455 return 0;
456}
457
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000458
459static int ak4642_probe(struct snd_soc_codec *codec)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900460{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000461 struct ak4642_priv *ak4642 = snd_soc_codec_get_drvdata(codec);
Axel Linb91470b2011-10-11 20:20:53 +0800462 int ret;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900463
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000464 dev_info(codec->dev, "AK4642 Audio Codec %s", AK4642_VERSION);
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900465
Axel Linb91470b2011-10-11 20:20:53 +0800466 ret = snd_soc_codec_set_cache_io(codec, 8, 8, ak4642->control_type);
467 if (ret < 0) {
468 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
469 return ret;
470 }
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900471
Kuninori Morimoto73bb3792010-09-03 16:12:36 +0900472 snd_soc_add_controls(codec, ak4642_snd_controls,
473 ARRAY_SIZE(ak4642_snd_controls));
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900474
Kuninori Morimotoed2dd7d2011-11-10 16:21:01 -0800475 ak4642_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
476
477 return 0;
478}
479
480static int ak4642_remove(struct snd_soc_codec *codec)
481{
482 ak4642_set_bias_level(codec, SND_SOC_BIAS_OFF);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000483 return 0;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900484}
485
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000486static struct snd_soc_codec_driver soc_codec_dev_ak4642 = {
Kuninori Morimoto0ce75aa2010-09-16 13:06:40 +0900487 .probe = ak4642_probe,
Kuninori Morimotoed2dd7d2011-11-10 16:21:01 -0800488 .remove = ak4642_remove,
Kuninori Morimoto0ce75aa2010-09-16 13:06:40 +0900489 .resume = ak4642_resume,
Kuninori Morimotoed2dd7d2011-11-10 16:21:01 -0800490 .set_bias_level = ak4642_set_bias_level,
Kuninori Morimoto0ce75aa2010-09-16 13:06:40 +0900491 .reg_cache_size = ARRAY_SIZE(ak4642_reg),
492 .reg_word_size = sizeof(u8),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000493 .reg_cache_default = ak4642_reg,
Kuninori Morimoto24747da2011-11-10 16:21:31 -0800494 .dapm_widgets = ak4642_dapm_widgets,
495 .num_dapm_widgets = ARRAY_SIZE(ak4642_dapm_widgets),
496 .dapm_routes = ak4642_intercon,
497 .num_dapm_routes = ARRAY_SIZE(ak4642_intercon),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000498};
499
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900500#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000501static __devinit int ak4642_i2c_probe(struct i2c_client *i2c,
502 const struct i2c_device_id *id)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900503{
504 struct ak4642_priv *ak4642;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900505 int ret;
506
507 ak4642 = kzalloc(sizeof(struct ak4642_priv), GFP_KERNEL);
Kuninori Morimoto0ce75aa2010-09-16 13:06:40 +0900508 if (!ak4642)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900509 return -ENOMEM;
510
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900511 i2c_set_clientdata(i2c, ak4642);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000512 ak4642->control_type = SND_SOC_I2C;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900513
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000514 ret = snd_soc_register_codec(&i2c->dev,
515 &soc_codec_dev_ak4642, &ak4642_dai, 1);
516 if (ret < 0)
Axel Lin7bcaad92010-07-23 05:53:44 +0000517 kfree(ak4642);
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900518 return ret;
519}
520
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000521static __devexit int ak4642_i2c_remove(struct i2c_client *client)
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900522{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000523 snd_soc_unregister_codec(&client->dev);
524 kfree(i2c_get_clientdata(client));
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900525 return 0;
526}
527
528static const struct i2c_device_id ak4642_i2c_id[] = {
529 { "ak4642", 0 },
530 { "ak4643", 0 },
531 { }
532};
533MODULE_DEVICE_TABLE(i2c, ak4642_i2c_id);
534
535static struct i2c_driver ak4642_i2c_driver = {
536 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000537 .name = "ak4642-codec",
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900538 .owner = THIS_MODULE,
539 },
Kuninori Morimoto0ce75aa2010-09-16 13:06:40 +0900540 .probe = ak4642_i2c_probe,
541 .remove = __devexit_p(ak4642_i2c_remove),
542 .id_table = ak4642_i2c_id,
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900543};
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900544#endif
545
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900546static int __init ak4642_modinit(void)
547{
Kuninori Morimoto1cf86f62009-12-15 15:54:21 +0900548 int ret = 0;
Kuninori Morimotoa3a83d92009-08-21 10:23:41 +0900549#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
550 ret = i2c_add_driver(&ak4642_i2c_driver);
551#endif
552 return ret;
553
554}
555module_init(ak4642_modinit);
556
557static void __exit ak4642_exit(void)
558{
559#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
560 i2c_del_driver(&ak4642_i2c_driver);
561#endif
562
563}
564module_exit(ak4642_exit);
565
566MODULE_DESCRIPTION("Soc AK4642 driver");
567MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>");
568MODULE_LICENSE("GPL");