blob: e1a214ee757ffaa2621572ebb084fb0033bd621c [file] [log] [blame]
Richard Purdie796d2ca2008-06-23 14:51:28 +01001/*
2 * ak4535.c -- AK4535 ALSA Soc Audio driver
3 *
4 * Copyright 2005 Openedhand Ltd.
5 *
6 * Author: Richard Purdie <richard@openedhand.com>
7 *
8 * Based on wm8753.c by Liam Girdwood
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/module.h>
16#include <linux/moduleparam.h>
17#include <linux/init.h>
18#include <linux/delay.h>
19#include <linux/pm.h>
20#include <linux/i2c.h>
21#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Richard Purdie796d2ca2008-06-23 14:51:28 +010023#include <sound/core.h>
24#include <sound/pcm.h>
25#include <sound/pcm_params.h>
26#include <sound/soc.h>
Richard Purdie796d2ca2008-06-23 14:51:28 +010027#include <sound/initval.h>
28
29#include "ak4535.h"
30
Richard Purdie796d2ca2008-06-23 14:51:28 +010031#define AK4535_VERSION "0.3"
32
Richard Purdie796d2ca2008-06-23 14:51:28 +010033/* codec private data */
34struct ak4535_priv {
35 unsigned int sysclk;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000036 enum snd_soc_control_type control_type;
37 void *control_data;
Richard Purdie796d2ca2008-06-23 14:51:28 +010038};
39
40/*
41 * ak4535 register cache
42 */
43static const u16 ak4535_reg[AK4535_CACHEREGNUM] = {
44 0x0000, 0x0080, 0x0000, 0x0003,
45 0x0002, 0x0000, 0x0011, 0x0001,
46 0x0000, 0x0040, 0x0036, 0x0010,
47 0x0000, 0x0000, 0x0057, 0x0000,
48};
49
50/*
51 * read ak4535 register cache
52 */
53static inline unsigned int ak4535_read_reg_cache(struct snd_soc_codec *codec,
54 unsigned int reg)
55{
56 u16 *cache = codec->reg_cache;
57 if (reg >= AK4535_CACHEREGNUM)
58 return -1;
59 return cache[reg];
60}
61
Richard Purdie796d2ca2008-06-23 14:51:28 +010062/*
63 * write ak4535 register cache
64 */
65static inline void ak4535_write_reg_cache(struct snd_soc_codec *codec,
66 u16 reg, unsigned int value)
67{
68 u16 *cache = codec->reg_cache;
69 if (reg >= AK4535_CACHEREGNUM)
70 return;
71 cache[reg] = value;
72}
73
74/*
75 * write to the AK4535 register space
76 */
77static int ak4535_write(struct snd_soc_codec *codec, unsigned int reg,
78 unsigned int value)
79{
80 u8 data[2];
81
82 /* data is
83 * D15..D8 AK4535 register offset
84 * D7...D0 register data
85 */
86 data[0] = reg & 0xff;
87 data[1] = value & 0xff;
88
89 ak4535_write_reg_cache(codec, reg, value);
90 if (codec->hw_write(codec->control_data, data, 2) == 2)
91 return 0;
92 else
93 return -EIO;
94}
95
96static int ak4535_sync(struct snd_soc_codec *codec)
97{
98 u16 *cache = codec->reg_cache;
99 int i, r = 0;
100
101 for (i = 0; i < AK4535_CACHEREGNUM; i++)
102 r |= ak4535_write(codec, i, cache[i]);
103
104 return r;
105};
106
107static const char *ak4535_mono_gain[] = {"+6dB", "-17dB"};
108static const char *ak4535_mono_out[] = {"(L + R)/2", "Hi-Z"};
109static const char *ak4535_hp_out[] = {"Stereo", "Mono"};
110static const char *ak4535_deemp[] = {"44.1kHz", "Off", "48kHz", "32kHz"};
111static const char *ak4535_mic_select[] = {"Internal", "External"};
112
113static const struct soc_enum ak4535_enum[] = {
114 SOC_ENUM_SINGLE(AK4535_SIG1, 7, 2, ak4535_mono_gain),
115 SOC_ENUM_SINGLE(AK4535_SIG1, 6, 2, ak4535_mono_out),
116 SOC_ENUM_SINGLE(AK4535_MODE2, 2, 2, ak4535_hp_out),
117 SOC_ENUM_SINGLE(AK4535_DAC, 0, 4, ak4535_deemp),
118 SOC_ENUM_SINGLE(AK4535_MIC, 1, 2, ak4535_mic_select),
119};
120
121static const struct snd_kcontrol_new ak4535_snd_controls[] = {
122 SOC_SINGLE("ALC2 Switch", AK4535_SIG1, 1, 1, 0),
123 SOC_ENUM("Mono 1 Output", ak4535_enum[1]),
124 SOC_ENUM("Mono 1 Gain", ak4535_enum[0]),
125 SOC_ENUM("Headphone Output", ak4535_enum[2]),
126 SOC_ENUM("Playback Deemphasis", ak4535_enum[3]),
127 SOC_SINGLE("Bass Volume", AK4535_DAC, 2, 3, 0),
128 SOC_SINGLE("Mic Boost (+20dB) Switch", AK4535_MIC, 0, 1, 0),
129 SOC_ENUM("Mic Select", ak4535_enum[4]),
130 SOC_SINGLE("ALC Operation Time", AK4535_TIMER, 0, 3, 0),
131 SOC_SINGLE("ALC Recovery Time", AK4535_TIMER, 2, 3, 0),
132 SOC_SINGLE("ALC ZC Time", AK4535_TIMER, 4, 3, 0),
133 SOC_SINGLE("ALC 1 Switch", AK4535_ALC1, 5, 1, 0),
134 SOC_SINGLE("ALC 2 Switch", AK4535_ALC1, 6, 1, 0),
135 SOC_SINGLE("ALC Volume", AK4535_ALC2, 0, 127, 0),
136 SOC_SINGLE("Capture Volume", AK4535_PGA, 0, 127, 0),
137 SOC_SINGLE("Left Playback Volume", AK4535_LATT, 0, 127, 1),
138 SOC_SINGLE("Right Playback Volume", AK4535_RATT, 0, 127, 1),
139 SOC_SINGLE("AUX Bypass Volume", AK4535_VOL, 0, 15, 0),
140 SOC_SINGLE("Mic Sidetone Volume", AK4535_VOL, 4, 7, 0),
141};
142
Richard Purdie796d2ca2008-06-23 14:51:28 +0100143/* Mono 1 Mixer */
144static const struct snd_kcontrol_new ak4535_mono1_mixer_controls[] = {
145 SOC_DAPM_SINGLE("Mic Sidetone Switch", AK4535_SIG1, 4, 1, 0),
146 SOC_DAPM_SINGLE("Mono Playback Switch", AK4535_SIG1, 5, 1, 0),
147};
148
149/* Stereo Mixer */
150static const struct snd_kcontrol_new ak4535_stereo_mixer_controls[] = {
151 SOC_DAPM_SINGLE("Mic Sidetone Switch", AK4535_SIG2, 4, 1, 0),
152 SOC_DAPM_SINGLE("Playback Switch", AK4535_SIG2, 7, 1, 0),
153 SOC_DAPM_SINGLE("Aux Bypass Switch", AK4535_SIG2, 5, 1, 0),
154};
155
156/* Input Mixer */
157static const struct snd_kcontrol_new ak4535_input_mixer_controls[] = {
158 SOC_DAPM_SINGLE("Mic Capture Switch", AK4535_MIC, 2, 1, 0),
159 SOC_DAPM_SINGLE("Aux Capture Switch", AK4535_MIC, 5, 1, 0),
160};
161
162/* Input mux */
163static const struct snd_kcontrol_new ak4535_input_mux_control =
164 SOC_DAPM_ENUM("Input Select", ak4535_enum[4]);
165
166/* HP L switch */
167static const struct snd_kcontrol_new ak4535_hpl_control =
168 SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 1, 1, 1);
169
170/* HP R switch */
171static const struct snd_kcontrol_new ak4535_hpr_control =
172 SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 0, 1, 1);
173
174/* mono 2 switch */
175static const struct snd_kcontrol_new ak4535_mono2_control =
176 SOC_DAPM_SINGLE("Switch", AK4535_SIG1, 0, 1, 0);
177
178/* Line out switch */
179static const struct snd_kcontrol_new ak4535_line_control =
180 SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 6, 1, 0);
181
182/* ak4535 dapm widgets */
183static const struct snd_soc_dapm_widget ak4535_dapm_widgets[] = {
184 SND_SOC_DAPM_MIXER("Stereo Mixer", SND_SOC_NOPM, 0, 0,
185 &ak4535_stereo_mixer_controls[0],
186 ARRAY_SIZE(ak4535_stereo_mixer_controls)),
187 SND_SOC_DAPM_MIXER("Mono1 Mixer", SND_SOC_NOPM, 0, 0,
188 &ak4535_mono1_mixer_controls[0],
189 ARRAY_SIZE(ak4535_mono1_mixer_controls)),
190 SND_SOC_DAPM_MIXER("Input Mixer", SND_SOC_NOPM, 0, 0,
191 &ak4535_input_mixer_controls[0],
192 ARRAY_SIZE(ak4535_input_mixer_controls)),
193 SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0,
194 &ak4535_input_mux_control),
195 SND_SOC_DAPM_DAC("DAC", "Playback", AK4535_PM2, 0, 0),
196 SND_SOC_DAPM_SWITCH("Mono 2 Enable", SND_SOC_NOPM, 0, 0,
197 &ak4535_mono2_control),
198 /* speaker powersave bit */
199 SND_SOC_DAPM_PGA("Speaker Enable", AK4535_MODE2, 0, 0, NULL, 0),
200 SND_SOC_DAPM_SWITCH("Line Out Enable", SND_SOC_NOPM, 0, 0,
201 &ak4535_line_control),
202 SND_SOC_DAPM_SWITCH("Left HP Enable", SND_SOC_NOPM, 0, 0,
203 &ak4535_hpl_control),
204 SND_SOC_DAPM_SWITCH("Right HP Enable", SND_SOC_NOPM, 0, 0,
205 &ak4535_hpr_control),
206 SND_SOC_DAPM_OUTPUT("LOUT"),
207 SND_SOC_DAPM_OUTPUT("HPL"),
208 SND_SOC_DAPM_OUTPUT("ROUT"),
209 SND_SOC_DAPM_OUTPUT("HPR"),
210 SND_SOC_DAPM_OUTPUT("SPP"),
211 SND_SOC_DAPM_OUTPUT("SPN"),
212 SND_SOC_DAPM_OUTPUT("MOUT1"),
213 SND_SOC_DAPM_OUTPUT("MOUT2"),
214 SND_SOC_DAPM_OUTPUT("MICOUT"),
215 SND_SOC_DAPM_ADC("ADC", "Capture", AK4535_PM1, 0, 0),
216 SND_SOC_DAPM_PGA("Spk Amp", AK4535_PM2, 3, 0, NULL, 0),
217 SND_SOC_DAPM_PGA("HP R Amp", AK4535_PM2, 1, 0, NULL, 0),
218 SND_SOC_DAPM_PGA("HP L Amp", AK4535_PM2, 2, 0, NULL, 0),
219 SND_SOC_DAPM_PGA("Mic", AK4535_PM1, 1, 0, NULL, 0),
220 SND_SOC_DAPM_PGA("Line Out", AK4535_PM1, 4, 0, NULL, 0),
221 SND_SOC_DAPM_PGA("Mono Out", AK4535_PM1, 3, 0, NULL, 0),
222 SND_SOC_DAPM_PGA("AUX In", AK4535_PM1, 2, 0, NULL, 0),
223
224 SND_SOC_DAPM_MICBIAS("Mic Int Bias", AK4535_MIC, 3, 0),
225 SND_SOC_DAPM_MICBIAS("Mic Ext Bias", AK4535_MIC, 4, 0),
226 SND_SOC_DAPM_INPUT("MICIN"),
227 SND_SOC_DAPM_INPUT("MICEXT"),
228 SND_SOC_DAPM_INPUT("AUX"),
229 SND_SOC_DAPM_INPUT("MIN"),
230 SND_SOC_DAPM_INPUT("AIN"),
231};
232
Lu Guanqunb63c9632011-03-30 21:53:07 +0800233static const struct snd_soc_dapm_route ak4535_audio_map[] = {
Richard Purdie796d2ca2008-06-23 14:51:28 +0100234 /*stereo mixer */
235 {"Stereo Mixer", "Playback Switch", "DAC"},
236 {"Stereo Mixer", "Mic Sidetone Switch", "Mic"},
237 {"Stereo Mixer", "Aux Bypass Switch", "AUX In"},
238
239 /* mono1 mixer */
240 {"Mono1 Mixer", "Mic Sidetone Switch", "Mic"},
241 {"Mono1 Mixer", "Mono Playback Switch", "DAC"},
242
243 /* Mic */
244 {"Mic", NULL, "AIN"},
245 {"Input Mux", "Internal", "Mic Int Bias"},
246 {"Input Mux", "External", "Mic Ext Bias"},
247 {"Mic Int Bias", NULL, "MICIN"},
248 {"Mic Ext Bias", NULL, "MICEXT"},
249 {"MICOUT", NULL, "Input Mux"},
250
251 /* line out */
252 {"LOUT", NULL, "Line Out Enable"},
253 {"ROUT", NULL, "Line Out Enable"},
254 {"Line Out Enable", "Switch", "Line Out"},
255 {"Line Out", NULL, "Stereo Mixer"},
256
257 /* mono1 out */
258 {"MOUT1", NULL, "Mono Out"},
259 {"Mono Out", NULL, "Mono1 Mixer"},
260
261 /* left HP */
262 {"HPL", NULL, "Left HP Enable"},
263 {"Left HP Enable", "Switch", "HP L Amp"},
264 {"HP L Amp", NULL, "Stereo Mixer"},
265
266 /* right HP */
267 {"HPR", NULL, "Right HP Enable"},
268 {"Right HP Enable", "Switch", "HP R Amp"},
269 {"HP R Amp", NULL, "Stereo Mixer"},
270
271 /* speaker */
272 {"SPP", NULL, "Speaker Enable"},
273 {"SPN", NULL, "Speaker Enable"},
274 {"Speaker Enable", "Switch", "Spk Amp"},
275 {"Spk Amp", NULL, "MIN"},
276
277 /* mono 2 */
278 {"MOUT2", NULL, "Mono 2 Enable"},
279 {"Mono 2 Enable", "Switch", "Stereo Mixer"},
280
281 /* Aux In */
282 {"Aux In", NULL, "AUX"},
283
284 /* ADC */
285 {"ADC", NULL, "Input Mixer"},
286 {"Input Mixer", "Mic Capture Switch", "Mic"},
287 {"Input Mixer", "Aux Capture Switch", "Aux In"},
288};
289
Liam Girdwoode550e172008-07-07 16:07:52 +0100290static int ak4535_set_dai_sysclk(struct snd_soc_dai *codec_dai,
Richard Purdie796d2ca2008-06-23 14:51:28 +0100291 int clk_id, unsigned int freq, int dir)
292{
293 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900294 struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100295
296 ak4535->sysclk = freq;
297 return 0;
298}
299
300static int ak4535_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000301 struct snd_pcm_hw_params *params,
302 struct snd_soc_dai *dai)
Richard Purdie796d2ca2008-06-23 14:51:28 +0100303{
304 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000305 struct snd_soc_codec *codec = rtd->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900306 struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100307 u8 mode2 = ak4535_read_reg_cache(codec, AK4535_MODE2) & ~(0x3 << 5);
308 int rate = params_rate(params), fs = 256;
309
310 if (rate)
311 fs = ak4535->sysclk / rate;
312
313 /* set fs */
314 switch (fs) {
315 case 1024:
316 mode2 |= (0x2 << 5);
317 break;
318 case 512:
319 mode2 |= (0x1 << 5);
320 break;
321 case 256:
322 break;
323 }
324
325 /* set rate */
326 ak4535_write(codec, AK4535_MODE2, mode2);
327 return 0;
328}
329
Liam Girdwoode550e172008-07-07 16:07:52 +0100330static int ak4535_set_dai_fmt(struct snd_soc_dai *codec_dai,
Richard Purdie796d2ca2008-06-23 14:51:28 +0100331 unsigned int fmt)
332{
333 struct snd_soc_codec *codec = codec_dai->codec;
334 u8 mode1 = 0;
335
336 /* interface format */
337 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
338 case SND_SOC_DAIFMT_I2S:
339 mode1 = 0x0002;
340 break;
341 case SND_SOC_DAIFMT_LEFT_J:
342 mode1 = 0x0001;
343 break;
344 default:
345 return -EINVAL;
346 }
347
348 /* use 32 fs for BCLK to save power */
349 mode1 |= 0x4;
350
351 ak4535_write(codec, AK4535_MODE1, mode1);
352 return 0;
353}
354
Liam Girdwoode550e172008-07-07 16:07:52 +0100355static int ak4535_mute(struct snd_soc_dai *dai, int mute)
Richard Purdie796d2ca2008-06-23 14:51:28 +0100356{
357 struct snd_soc_codec *codec = dai->codec;
Axel Lincca67a32010-12-01 17:22:34 +0800358 u16 mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100359 if (!mute)
Axel Lincca67a32010-12-01 17:22:34 +0800360 ak4535_write(codec, AK4535_DAC, mute_reg & ~0x20);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100361 else
362 ak4535_write(codec, AK4535_DAC, mute_reg | 0x20);
363 return 0;
364}
365
366static int ak4535_set_bias_level(struct snd_soc_codec *codec,
367 enum snd_soc_bias_level level)
368{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000369 u16 i, mute_reg;
Richard Purdie796d2ca2008-06-23 14:51:28 +0100370
371 switch (level) {
372 case SND_SOC_BIAS_ON:
Axel Lincca67a32010-12-01 17:22:34 +0800373 mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC);
374 ak4535_write(codec, AK4535_DAC, mute_reg & ~0x20);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100375 break;
376 case SND_SOC_BIAS_PREPARE:
Axel Lincca67a32010-12-01 17:22:34 +0800377 mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000378 ak4535_write(codec, AK4535_DAC, mute_reg | 0x20);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100379 break;
380 case SND_SOC_BIAS_STANDBY:
381 i = ak4535_read_reg_cache(codec, AK4535_PM1);
382 ak4535_write(codec, AK4535_PM1, i | 0x80);
383 i = ak4535_read_reg_cache(codec, AK4535_PM2);
384 ak4535_write(codec, AK4535_PM2, i & (~0x80));
385 break;
386 case SND_SOC_BIAS_OFF:
387 i = ak4535_read_reg_cache(codec, AK4535_PM1);
388 ak4535_write(codec, AK4535_PM1, i & (~0x80));
389 break;
390 }
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200391 codec->dapm.bias_level = level;
Richard Purdie796d2ca2008-06-23 14:51:28 +0100392 return 0;
393}
394
395#define AK4535_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
396 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
397 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
398
Eric Miao6335d052009-03-03 09:41:00 +0800399static struct snd_soc_dai_ops ak4535_dai_ops = {
400 .hw_params = ak4535_hw_params,
401 .set_fmt = ak4535_set_dai_fmt,
402 .digital_mute = ak4535_mute,
403 .set_sysclk = ak4535_set_dai_sysclk,
404};
405
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000406static struct snd_soc_dai_driver ak4535_dai = {
407 .name = "ak4535-hifi",
Richard Purdie796d2ca2008-06-23 14:51:28 +0100408 .playback = {
409 .stream_name = "Playback",
410 .channels_min = 1,
411 .channels_max = 2,
412 .rates = AK4535_RATES,
413 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
414 .capture = {
415 .stream_name = "Capture",
416 .channels_min = 1,
417 .channels_max = 2,
418 .rates = AK4535_RATES,
419 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
Eric Miao6335d052009-03-03 09:41:00 +0800420 .ops = &ak4535_dai_ops,
Richard Purdie796d2ca2008-06-23 14:51:28 +0100421};
Richard Purdie796d2ca2008-06-23 14:51:28 +0100422
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000423static int ak4535_suspend(struct snd_soc_codec *codec, pm_message_t state)
Richard Purdie796d2ca2008-06-23 14:51:28 +0100424{
Richard Purdie796d2ca2008-06-23 14:51:28 +0100425 ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF);
426 return 0;
427}
428
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000429static int ak4535_resume(struct snd_soc_codec *codec)
Richard Purdie796d2ca2008-06-23 14:51:28 +0100430{
Richard Purdie796d2ca2008-06-23 14:51:28 +0100431 ak4535_sync(codec);
432 ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100433 return 0;
434}
435
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000436static int ak4535_probe(struct snd_soc_codec *codec)
Richard Purdie796d2ca2008-06-23 14:51:28 +0100437{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000438 struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100439
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000440 printk(KERN_INFO "AK4535 Audio Codec %s", AK4535_VERSION);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100441
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000442 codec->control_data = ak4535->control_data;
Richard Purdie796d2ca2008-06-23 14:51:28 +0100443
444 /* power on device */
445 ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
446
Ian Molton3e8e1952009-01-09 00:23:21 +0000447 snd_soc_add_controls(codec, ak4535_snd_controls,
448 ARRAY_SIZE(ak4535_snd_controls));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000449 return 0;
Richard Purdie796d2ca2008-06-23 14:51:28 +0100450}
451
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000452/* power down chip */
453static int ak4535_remove(struct snd_soc_codec *codec)
454{
455 ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF);
456 return 0;
457}
458
459static struct snd_soc_codec_driver soc_codec_dev_ak4535 = {
460 .probe = ak4535_probe,
461 .remove = ak4535_remove,
462 .suspend = ak4535_suspend,
463 .resume = ak4535_resume,
464 .read = ak4535_read_reg_cache,
465 .write = ak4535_write,
466 .set_bias_level = ak4535_set_bias_level,
467 .reg_cache_size = ARRAY_SIZE(ak4535_reg),
468 .reg_word_size = sizeof(u8),
469 .reg_cache_default = ak4535_reg,
Lu Guanqunb63c9632011-03-30 21:53:07 +0800470 .dapm_widgets = ak4535_dapm_widgets,
471 .num_dapm_widgets = ARRAY_SIZE(ak4535_dapm_widgets),
472 .dapm_routes = ak4535_audio_map,
473 .num_dapm_routes = ARRAY_SIZE(ak4535_audio_map),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000474};
Richard Purdie796d2ca2008-06-23 14:51:28 +0100475
476#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000477static __devinit int ak4535_i2c_probe(struct i2c_client *i2c,
478 const struct i2c_device_id *id)
Richard Purdie796d2ca2008-06-23 14:51:28 +0100479{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000480 struct ak4535_priv *ak4535;
Richard Purdie796d2ca2008-06-23 14:51:28 +0100481 int ret;
482
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000483 ak4535 = kzalloc(sizeof(struct ak4535_priv), GFP_KERNEL);
484 if (ak4535 == NULL)
485 return -ENOMEM;
Richard Purdie796d2ca2008-06-23 14:51:28 +0100486
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000487 i2c_set_clientdata(i2c, ak4535);
488 ak4535->control_data = i2c;
489 ak4535->control_type = SND_SOC_I2C;
490
491 ret = snd_soc_register_codec(&i2c->dev,
492 &soc_codec_dev_ak4535, &ak4535_dai, 1);
Jean Delvared28d2712008-09-01 18:46:59 +0100493 if (ret < 0)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000494 kfree(ak4535);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100495 return ret;
496}
497
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000498static __devexit int ak4535_i2c_remove(struct i2c_client *client)
Richard Purdie796d2ca2008-06-23 14:51:28 +0100499{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000500 snd_soc_unregister_codec(&client->dev);
501 kfree(i2c_get_clientdata(client));
Richard Purdie796d2ca2008-06-23 14:51:28 +0100502 return 0;
503}
504
Jean Delvared28d2712008-09-01 18:46:59 +0100505static const struct i2c_device_id ak4535_i2c_id[] = {
506 { "ak4535", 0 },
507 { }
508};
509MODULE_DEVICE_TABLE(i2c, ak4535_i2c_id);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100510
Richard Purdie796d2ca2008-06-23 14:51:28 +0100511static struct i2c_driver ak4535_i2c_driver = {
512 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000513 .name = "ak4535-codec",
Richard Purdie796d2ca2008-06-23 14:51:28 +0100514 .owner = THIS_MODULE,
515 },
Jean Delvared28d2712008-09-01 18:46:59 +0100516 .probe = ak4535_i2c_probe,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000517 .remove = __devexit_p(ak4535_i2c_remove),
Jean Delvared28d2712008-09-01 18:46:59 +0100518 .id_table = ak4535_i2c_id,
Richard Purdie796d2ca2008-06-23 14:51:28 +0100519};
Richard Purdie796d2ca2008-06-23 14:51:28 +0100520#endif
521
Takashi Iwaic9b3a402008-12-10 07:47:22 +0100522static int __init ak4535_modinit(void)
Mark Brown64089b82008-12-08 19:17:58 +0000523{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000524 int ret = 0;
525#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
526 ret = i2c_add_driver(&ak4535_i2c_driver);
527 if (ret != 0) {
528 printk(KERN_ERR "Failed to register AK4535 I2C driver: %d\n",
529 ret);
530 }
531#endif
532 return ret;
Mark Brown64089b82008-12-08 19:17:58 +0000533}
534module_init(ak4535_modinit);
535
536static void __exit ak4535_exit(void)
537{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000538#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
539 i2c_del_driver(&ak4535_i2c_driver);
540#endif
Mark Brown64089b82008-12-08 19:17:58 +0000541}
542module_exit(ak4535_exit);
543
Richard Purdie796d2ca2008-06-23 14:51:28 +0100544MODULE_DESCRIPTION("Soc AK4535 driver");
545MODULE_AUTHOR("Richard Purdie");
546MODULE_LICENSE("GPL");