blob: 71fca53c9bbfb807a107b064746ba1ad77fe07d9 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090021#include <linux/slab.h>
Richard Purdie796d2ca2008-06-23 14:51:28 +010022#include <sound/core.h>
23#include <sound/pcm.h>
24#include <sound/pcm_params.h>
25#include <sound/soc.h>
Richard Purdie796d2ca2008-06-23 14:51:28 +010026#include <sound/initval.h>
27
28#include "ak4535.h"
29
Richard Purdie796d2ca2008-06-23 14:51:28 +010030#define AK4535_VERSION "0.3"
31
Richard Purdie796d2ca2008-06-23 14:51:28 +010032/* codec private data */
33struct ak4535_priv {
34 unsigned int sysclk;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000035 enum snd_soc_control_type control_type;
Richard Purdie796d2ca2008-06-23 14:51:28 +010036};
37
38/*
39 * ak4535 register cache
40 */
Axel Lin7c042412011-10-13 17:17:06 +080041static const u8 ak4535_reg[AK4535_CACHEREGNUM] = {
42 0x00, 0x80, 0x00, 0x03,
43 0x02, 0x00, 0x11, 0x01,
44 0x00, 0x40, 0x36, 0x10,
45 0x00, 0x00, 0x57, 0x00,
Richard Purdie796d2ca2008-06-23 14:51:28 +010046};
47
Richard Purdie796d2ca2008-06-23 14:51:28 +010048static const char *ak4535_mono_gain[] = {"+6dB", "-17dB"};
49static const char *ak4535_mono_out[] = {"(L + R)/2", "Hi-Z"};
50static const char *ak4535_hp_out[] = {"Stereo", "Mono"};
51static const char *ak4535_deemp[] = {"44.1kHz", "Off", "48kHz", "32kHz"};
52static const char *ak4535_mic_select[] = {"Internal", "External"};
53
54static const struct soc_enum ak4535_enum[] = {
55 SOC_ENUM_SINGLE(AK4535_SIG1, 7, 2, ak4535_mono_gain),
56 SOC_ENUM_SINGLE(AK4535_SIG1, 6, 2, ak4535_mono_out),
57 SOC_ENUM_SINGLE(AK4535_MODE2, 2, 2, ak4535_hp_out),
58 SOC_ENUM_SINGLE(AK4535_DAC, 0, 4, ak4535_deemp),
59 SOC_ENUM_SINGLE(AK4535_MIC, 1, 2, ak4535_mic_select),
60};
61
62static const struct snd_kcontrol_new ak4535_snd_controls[] = {
63 SOC_SINGLE("ALC2 Switch", AK4535_SIG1, 1, 1, 0),
64 SOC_ENUM("Mono 1 Output", ak4535_enum[1]),
65 SOC_ENUM("Mono 1 Gain", ak4535_enum[0]),
66 SOC_ENUM("Headphone Output", ak4535_enum[2]),
67 SOC_ENUM("Playback Deemphasis", ak4535_enum[3]),
68 SOC_SINGLE("Bass Volume", AK4535_DAC, 2, 3, 0),
69 SOC_SINGLE("Mic Boost (+20dB) Switch", AK4535_MIC, 0, 1, 0),
70 SOC_ENUM("Mic Select", ak4535_enum[4]),
71 SOC_SINGLE("ALC Operation Time", AK4535_TIMER, 0, 3, 0),
72 SOC_SINGLE("ALC Recovery Time", AK4535_TIMER, 2, 3, 0),
73 SOC_SINGLE("ALC ZC Time", AK4535_TIMER, 4, 3, 0),
74 SOC_SINGLE("ALC 1 Switch", AK4535_ALC1, 5, 1, 0),
75 SOC_SINGLE("ALC 2 Switch", AK4535_ALC1, 6, 1, 0),
76 SOC_SINGLE("ALC Volume", AK4535_ALC2, 0, 127, 0),
77 SOC_SINGLE("Capture Volume", AK4535_PGA, 0, 127, 0),
78 SOC_SINGLE("Left Playback Volume", AK4535_LATT, 0, 127, 1),
79 SOC_SINGLE("Right Playback Volume", AK4535_RATT, 0, 127, 1),
80 SOC_SINGLE("AUX Bypass Volume", AK4535_VOL, 0, 15, 0),
81 SOC_SINGLE("Mic Sidetone Volume", AK4535_VOL, 4, 7, 0),
82};
83
Richard Purdie796d2ca2008-06-23 14:51:28 +010084/* Mono 1 Mixer */
85static const struct snd_kcontrol_new ak4535_mono1_mixer_controls[] = {
86 SOC_DAPM_SINGLE("Mic Sidetone Switch", AK4535_SIG1, 4, 1, 0),
87 SOC_DAPM_SINGLE("Mono Playback Switch", AK4535_SIG1, 5, 1, 0),
88};
89
90/* Stereo Mixer */
91static const struct snd_kcontrol_new ak4535_stereo_mixer_controls[] = {
92 SOC_DAPM_SINGLE("Mic Sidetone Switch", AK4535_SIG2, 4, 1, 0),
93 SOC_DAPM_SINGLE("Playback Switch", AK4535_SIG2, 7, 1, 0),
94 SOC_DAPM_SINGLE("Aux Bypass Switch", AK4535_SIG2, 5, 1, 0),
95};
96
97/* Input Mixer */
98static const struct snd_kcontrol_new ak4535_input_mixer_controls[] = {
99 SOC_DAPM_SINGLE("Mic Capture Switch", AK4535_MIC, 2, 1, 0),
100 SOC_DAPM_SINGLE("Aux Capture Switch", AK4535_MIC, 5, 1, 0),
101};
102
103/* Input mux */
104static const struct snd_kcontrol_new ak4535_input_mux_control =
105 SOC_DAPM_ENUM("Input Select", ak4535_enum[4]);
106
107/* HP L switch */
108static const struct snd_kcontrol_new ak4535_hpl_control =
109 SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 1, 1, 1);
110
111/* HP R switch */
112static const struct snd_kcontrol_new ak4535_hpr_control =
113 SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 0, 1, 1);
114
115/* mono 2 switch */
116static const struct snd_kcontrol_new ak4535_mono2_control =
117 SOC_DAPM_SINGLE("Switch", AK4535_SIG1, 0, 1, 0);
118
119/* Line out switch */
120static const struct snd_kcontrol_new ak4535_line_control =
121 SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 6, 1, 0);
122
123/* ak4535 dapm widgets */
124static const struct snd_soc_dapm_widget ak4535_dapm_widgets[] = {
125 SND_SOC_DAPM_MIXER("Stereo Mixer", SND_SOC_NOPM, 0, 0,
126 &ak4535_stereo_mixer_controls[0],
127 ARRAY_SIZE(ak4535_stereo_mixer_controls)),
128 SND_SOC_DAPM_MIXER("Mono1 Mixer", SND_SOC_NOPM, 0, 0,
129 &ak4535_mono1_mixer_controls[0],
130 ARRAY_SIZE(ak4535_mono1_mixer_controls)),
131 SND_SOC_DAPM_MIXER("Input Mixer", SND_SOC_NOPM, 0, 0,
132 &ak4535_input_mixer_controls[0],
133 ARRAY_SIZE(ak4535_input_mixer_controls)),
134 SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0,
135 &ak4535_input_mux_control),
136 SND_SOC_DAPM_DAC("DAC", "Playback", AK4535_PM2, 0, 0),
137 SND_SOC_DAPM_SWITCH("Mono 2 Enable", SND_SOC_NOPM, 0, 0,
138 &ak4535_mono2_control),
139 /* speaker powersave bit */
140 SND_SOC_DAPM_PGA("Speaker Enable", AK4535_MODE2, 0, 0, NULL, 0),
141 SND_SOC_DAPM_SWITCH("Line Out Enable", SND_SOC_NOPM, 0, 0,
142 &ak4535_line_control),
143 SND_SOC_DAPM_SWITCH("Left HP Enable", SND_SOC_NOPM, 0, 0,
144 &ak4535_hpl_control),
145 SND_SOC_DAPM_SWITCH("Right HP Enable", SND_SOC_NOPM, 0, 0,
146 &ak4535_hpr_control),
147 SND_SOC_DAPM_OUTPUT("LOUT"),
148 SND_SOC_DAPM_OUTPUT("HPL"),
149 SND_SOC_DAPM_OUTPUT("ROUT"),
150 SND_SOC_DAPM_OUTPUT("HPR"),
151 SND_SOC_DAPM_OUTPUT("SPP"),
152 SND_SOC_DAPM_OUTPUT("SPN"),
153 SND_SOC_DAPM_OUTPUT("MOUT1"),
154 SND_SOC_DAPM_OUTPUT("MOUT2"),
155 SND_SOC_DAPM_OUTPUT("MICOUT"),
156 SND_SOC_DAPM_ADC("ADC", "Capture", AK4535_PM1, 0, 0),
157 SND_SOC_DAPM_PGA("Spk Amp", AK4535_PM2, 3, 0, NULL, 0),
158 SND_SOC_DAPM_PGA("HP R Amp", AK4535_PM2, 1, 0, NULL, 0),
159 SND_SOC_DAPM_PGA("HP L Amp", AK4535_PM2, 2, 0, NULL, 0),
160 SND_SOC_DAPM_PGA("Mic", AK4535_PM1, 1, 0, NULL, 0),
161 SND_SOC_DAPM_PGA("Line Out", AK4535_PM1, 4, 0, NULL, 0),
162 SND_SOC_DAPM_PGA("Mono Out", AK4535_PM1, 3, 0, NULL, 0),
163 SND_SOC_DAPM_PGA("AUX In", AK4535_PM1, 2, 0, NULL, 0),
164
165 SND_SOC_DAPM_MICBIAS("Mic Int Bias", AK4535_MIC, 3, 0),
166 SND_SOC_DAPM_MICBIAS("Mic Ext Bias", AK4535_MIC, 4, 0),
167 SND_SOC_DAPM_INPUT("MICIN"),
168 SND_SOC_DAPM_INPUT("MICEXT"),
169 SND_SOC_DAPM_INPUT("AUX"),
170 SND_SOC_DAPM_INPUT("MIN"),
171 SND_SOC_DAPM_INPUT("AIN"),
172};
173
Lu Guanqunb63c9632011-03-30 21:53:07 +0800174static const struct snd_soc_dapm_route ak4535_audio_map[] = {
Richard Purdie796d2ca2008-06-23 14:51:28 +0100175 /*stereo mixer */
176 {"Stereo Mixer", "Playback Switch", "DAC"},
177 {"Stereo Mixer", "Mic Sidetone Switch", "Mic"},
178 {"Stereo Mixer", "Aux Bypass Switch", "AUX In"},
179
180 /* mono1 mixer */
181 {"Mono1 Mixer", "Mic Sidetone Switch", "Mic"},
182 {"Mono1 Mixer", "Mono Playback Switch", "DAC"},
183
184 /* Mic */
185 {"Mic", NULL, "AIN"},
186 {"Input Mux", "Internal", "Mic Int Bias"},
187 {"Input Mux", "External", "Mic Ext Bias"},
188 {"Mic Int Bias", NULL, "MICIN"},
189 {"Mic Ext Bias", NULL, "MICEXT"},
190 {"MICOUT", NULL, "Input Mux"},
191
192 /* line out */
193 {"LOUT", NULL, "Line Out Enable"},
194 {"ROUT", NULL, "Line Out Enable"},
195 {"Line Out Enable", "Switch", "Line Out"},
196 {"Line Out", NULL, "Stereo Mixer"},
197
198 /* mono1 out */
199 {"MOUT1", NULL, "Mono Out"},
200 {"Mono Out", NULL, "Mono1 Mixer"},
201
202 /* left HP */
203 {"HPL", NULL, "Left HP Enable"},
204 {"Left HP Enable", "Switch", "HP L Amp"},
205 {"HP L Amp", NULL, "Stereo Mixer"},
206
207 /* right HP */
208 {"HPR", NULL, "Right HP Enable"},
209 {"Right HP Enable", "Switch", "HP R Amp"},
210 {"HP R Amp", NULL, "Stereo Mixer"},
211
212 /* speaker */
213 {"SPP", NULL, "Speaker Enable"},
214 {"SPN", NULL, "Speaker Enable"},
215 {"Speaker Enable", "Switch", "Spk Amp"},
216 {"Spk Amp", NULL, "MIN"},
217
218 /* mono 2 */
219 {"MOUT2", NULL, "Mono 2 Enable"},
220 {"Mono 2 Enable", "Switch", "Stereo Mixer"},
221
222 /* Aux In */
223 {"Aux In", NULL, "AUX"},
224
225 /* ADC */
226 {"ADC", NULL, "Input Mixer"},
227 {"Input Mixer", "Mic Capture Switch", "Mic"},
228 {"Input Mixer", "Aux Capture Switch", "Aux In"},
229};
230
Liam Girdwoode550e172008-07-07 16:07:52 +0100231static int ak4535_set_dai_sysclk(struct snd_soc_dai *codec_dai,
Richard Purdie796d2ca2008-06-23 14:51:28 +0100232 int clk_id, unsigned int freq, int dir)
233{
234 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900235 struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100236
237 ak4535->sysclk = freq;
238 return 0;
239}
240
241static int ak4535_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000242 struct snd_pcm_hw_params *params,
243 struct snd_soc_dai *dai)
Richard Purdie796d2ca2008-06-23 14:51:28 +0100244{
245 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000246 struct snd_soc_codec *codec = rtd->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900247 struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);
Axel Lin3b184502011-10-06 10:11:51 +0800248 u8 mode2 = snd_soc_read(codec, AK4535_MODE2) & ~(0x3 << 5);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100249 int rate = params_rate(params), fs = 256;
250
251 if (rate)
252 fs = ak4535->sysclk / rate;
253
254 /* set fs */
255 switch (fs) {
256 case 1024:
257 mode2 |= (0x2 << 5);
258 break;
259 case 512:
260 mode2 |= (0x1 << 5);
261 break;
262 case 256:
263 break;
264 }
265
266 /* set rate */
Axel Lin3b184502011-10-06 10:11:51 +0800267 snd_soc_write(codec, AK4535_MODE2, mode2);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100268 return 0;
269}
270
Liam Girdwoode550e172008-07-07 16:07:52 +0100271static int ak4535_set_dai_fmt(struct snd_soc_dai *codec_dai,
Richard Purdie796d2ca2008-06-23 14:51:28 +0100272 unsigned int fmt)
273{
274 struct snd_soc_codec *codec = codec_dai->codec;
275 u8 mode1 = 0;
276
277 /* interface format */
278 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
279 case SND_SOC_DAIFMT_I2S:
280 mode1 = 0x0002;
281 break;
282 case SND_SOC_DAIFMT_LEFT_J:
283 mode1 = 0x0001;
284 break;
285 default:
286 return -EINVAL;
287 }
288
289 /* use 32 fs for BCLK to save power */
290 mode1 |= 0x4;
291
Axel Lin3b184502011-10-06 10:11:51 +0800292 snd_soc_write(codec, AK4535_MODE1, mode1);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100293 return 0;
294}
295
Liam Girdwoode550e172008-07-07 16:07:52 +0100296static int ak4535_mute(struct snd_soc_dai *dai, int mute)
Richard Purdie796d2ca2008-06-23 14:51:28 +0100297{
298 struct snd_soc_codec *codec = dai->codec;
Axel Lin3b184502011-10-06 10:11:51 +0800299 u16 mute_reg = snd_soc_read(codec, AK4535_DAC);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100300 if (!mute)
Axel Lin3b184502011-10-06 10:11:51 +0800301 snd_soc_write(codec, AK4535_DAC, mute_reg & ~0x20);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100302 else
Axel Lin3b184502011-10-06 10:11:51 +0800303 snd_soc_write(codec, AK4535_DAC, mute_reg | 0x20);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100304 return 0;
305}
306
307static int ak4535_set_bias_level(struct snd_soc_codec *codec,
308 enum snd_soc_bias_level level)
309{
Richard Purdie796d2ca2008-06-23 14:51:28 +0100310 switch (level) {
311 case SND_SOC_BIAS_ON:
Axel Lin3b184502011-10-06 10:11:51 +0800312 snd_soc_update_bits(codec, AK4535_DAC, 0x20, 0);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100313 break;
314 case SND_SOC_BIAS_PREPARE:
Axel Lin3b184502011-10-06 10:11:51 +0800315 snd_soc_update_bits(codec, AK4535_DAC, 0x20, 0x20);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100316 break;
317 case SND_SOC_BIAS_STANDBY:
Axel Lin3b184502011-10-06 10:11:51 +0800318 snd_soc_update_bits(codec, AK4535_PM1, 0x80, 0x80);
319 snd_soc_update_bits(codec, AK4535_PM2, 0x80, 0);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100320 break;
321 case SND_SOC_BIAS_OFF:
Axel Lin3b184502011-10-06 10:11:51 +0800322 snd_soc_update_bits(codec, AK4535_PM1, 0x80, 0);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100323 break;
324 }
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200325 codec->dapm.bias_level = level;
Richard Purdie796d2ca2008-06-23 14:51:28 +0100326 return 0;
327}
328
329#define AK4535_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
330 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
331 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
332
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100333static const struct snd_soc_dai_ops ak4535_dai_ops = {
Eric Miao6335d052009-03-03 09:41:00 +0800334 .hw_params = ak4535_hw_params,
335 .set_fmt = ak4535_set_dai_fmt,
336 .digital_mute = ak4535_mute,
337 .set_sysclk = ak4535_set_dai_sysclk,
338};
339
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000340static struct snd_soc_dai_driver ak4535_dai = {
341 .name = "ak4535-hifi",
Richard Purdie796d2ca2008-06-23 14:51:28 +0100342 .playback = {
343 .stream_name = "Playback",
344 .channels_min = 1,
345 .channels_max = 2,
346 .rates = AK4535_RATES,
347 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
348 .capture = {
349 .stream_name = "Capture",
350 .channels_min = 1,
351 .channels_max = 2,
352 .rates = AK4535_RATES,
353 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
Eric Miao6335d052009-03-03 09:41:00 +0800354 .ops = &ak4535_dai_ops,
Richard Purdie796d2ca2008-06-23 14:51:28 +0100355};
Richard Purdie796d2ca2008-06-23 14:51:28 +0100356
Lars-Peter Clausen84b315e2011-12-02 10:18:28 +0100357static int ak4535_suspend(struct snd_soc_codec *codec)
Richard Purdie796d2ca2008-06-23 14:51:28 +0100358{
Richard Purdie796d2ca2008-06-23 14:51:28 +0100359 ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF);
360 return 0;
361}
362
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000363static int ak4535_resume(struct snd_soc_codec *codec)
Richard Purdie796d2ca2008-06-23 14:51:28 +0100364{
Axel Lin3b184502011-10-06 10:11:51 +0800365 snd_soc_cache_sync(codec);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100366 ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100367 return 0;
368}
369
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000370static int ak4535_probe(struct snd_soc_codec *codec)
Richard Purdie796d2ca2008-06-23 14:51:28 +0100371{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000372 struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);
Axel Lin3b184502011-10-06 10:11:51 +0800373 int ret;
Richard Purdie796d2ca2008-06-23 14:51:28 +0100374
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000375 printk(KERN_INFO "AK4535 Audio Codec %s", AK4535_VERSION);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100376
Axel Lin3b184502011-10-06 10:11:51 +0800377 ret = snd_soc_codec_set_cache_io(codec, 8, 8, ak4535->control_type);
378 if (ret < 0) {
379 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
380 return ret;
381 }
Richard Purdie796d2ca2008-06-23 14:51:28 +0100382 /* power on device */
383 ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
384
Liam Girdwood022658b2012-02-03 17:43:09 +0000385 snd_soc_add_codec_controls(codec, ak4535_snd_controls,
Ian Molton3e8e1952009-01-09 00:23:21 +0000386 ARRAY_SIZE(ak4535_snd_controls));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000387 return 0;
Richard Purdie796d2ca2008-06-23 14:51:28 +0100388}
389
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000390/* power down chip */
391static int ak4535_remove(struct snd_soc_codec *codec)
392{
393 ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF);
394 return 0;
395}
396
397static struct snd_soc_codec_driver soc_codec_dev_ak4535 = {
398 .probe = ak4535_probe,
399 .remove = ak4535_remove,
400 .suspend = ak4535_suspend,
401 .resume = ak4535_resume,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000402 .set_bias_level = ak4535_set_bias_level,
403 .reg_cache_size = ARRAY_SIZE(ak4535_reg),
404 .reg_word_size = sizeof(u8),
405 .reg_cache_default = ak4535_reg,
Lu Guanqunb63c9632011-03-30 21:53:07 +0800406 .dapm_widgets = ak4535_dapm_widgets,
407 .num_dapm_widgets = ARRAY_SIZE(ak4535_dapm_widgets),
408 .dapm_routes = ak4535_audio_map,
409 .num_dapm_routes = ARRAY_SIZE(ak4535_audio_map),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000410};
Richard Purdie796d2ca2008-06-23 14:51:28 +0100411
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000412static __devinit int ak4535_i2c_probe(struct i2c_client *i2c,
413 const struct i2c_device_id *id)
Richard Purdie796d2ca2008-06-23 14:51:28 +0100414{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000415 struct ak4535_priv *ak4535;
Richard Purdie796d2ca2008-06-23 14:51:28 +0100416 int ret;
417
Axel Lin72464922011-12-20 14:38:09 +0800418 ak4535 = devm_kzalloc(&i2c->dev, sizeof(struct ak4535_priv),
419 GFP_KERNEL);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000420 if (ak4535 == NULL)
421 return -ENOMEM;
Richard Purdie796d2ca2008-06-23 14:51:28 +0100422
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000423 i2c_set_clientdata(i2c, ak4535);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000424 ak4535->control_type = SND_SOC_I2C;
425
426 ret = snd_soc_register_codec(&i2c->dev,
427 &soc_codec_dev_ak4535, &ak4535_dai, 1);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100428 return ret;
429}
430
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000431static __devexit int ak4535_i2c_remove(struct i2c_client *client)
Richard Purdie796d2ca2008-06-23 14:51:28 +0100432{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000433 snd_soc_unregister_codec(&client->dev);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100434 return 0;
435}
436
Jean Delvared28d2712008-09-01 18:46:59 +0100437static const struct i2c_device_id ak4535_i2c_id[] = {
438 { "ak4535", 0 },
439 { }
440};
441MODULE_DEVICE_TABLE(i2c, ak4535_i2c_id);
Richard Purdie796d2ca2008-06-23 14:51:28 +0100442
Richard Purdie796d2ca2008-06-23 14:51:28 +0100443static struct i2c_driver ak4535_i2c_driver = {
444 .driver = {
Mark Brownd69280b2012-02-16 22:52:19 -0800445 .name = "ak4535",
Richard Purdie796d2ca2008-06-23 14:51:28 +0100446 .owner = THIS_MODULE,
447 },
Jean Delvared28d2712008-09-01 18:46:59 +0100448 .probe = ak4535_i2c_probe,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000449 .remove = __devexit_p(ak4535_i2c_remove),
Jean Delvared28d2712008-09-01 18:46:59 +0100450 .id_table = ak4535_i2c_id,
Richard Purdie796d2ca2008-06-23 14:51:28 +0100451};
Richard Purdie796d2ca2008-06-23 14:51:28 +0100452
Mark Brownb08c5762012-02-16 22:52:44 -0800453module_i2c_driver(ak4535_i2c_driver);
Mark Brown64089b82008-12-08 19:17:58 +0000454
Richard Purdie796d2ca2008-06-23 14:51:28 +0100455MODULE_DESCRIPTION("Soc AK4535 driver");
456MODULE_AUTHOR("Richard Purdie");
457MODULE_LICENSE("GPL");