Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 1 | /* |
| 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 Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 23 | #include <sound/core.h> |
| 24 | #include <sound/pcm.h> |
| 25 | #include <sound/pcm_params.h> |
| 26 | #include <sound/soc.h> |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 27 | #include <sound/initval.h> |
| 28 | |
| 29 | #include "ak4535.h" |
| 30 | |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 31 | #define AK4535_VERSION "0.3" |
| 32 | |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 33 | /* codec private data */ |
| 34 | struct ak4535_priv { |
| 35 | unsigned int sysclk; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 36 | enum snd_soc_control_type control_type; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | /* |
| 40 | * ak4535 register cache |
| 41 | */ |
Axel Lin | 7c04241 | 2011-10-13 17:17:06 +0800 | [diff] [blame^] | 42 | static const u8 ak4535_reg[AK4535_CACHEREGNUM] = { |
| 43 | 0x00, 0x80, 0x00, 0x03, |
| 44 | 0x02, 0x00, 0x11, 0x01, |
| 45 | 0x00, 0x40, 0x36, 0x10, |
| 46 | 0x00, 0x00, 0x57, 0x00, |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 47 | }; |
| 48 | |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 49 | static const char *ak4535_mono_gain[] = {"+6dB", "-17dB"}; |
| 50 | static const char *ak4535_mono_out[] = {"(L + R)/2", "Hi-Z"}; |
| 51 | static const char *ak4535_hp_out[] = {"Stereo", "Mono"}; |
| 52 | static const char *ak4535_deemp[] = {"44.1kHz", "Off", "48kHz", "32kHz"}; |
| 53 | static const char *ak4535_mic_select[] = {"Internal", "External"}; |
| 54 | |
| 55 | static const struct soc_enum ak4535_enum[] = { |
| 56 | SOC_ENUM_SINGLE(AK4535_SIG1, 7, 2, ak4535_mono_gain), |
| 57 | SOC_ENUM_SINGLE(AK4535_SIG1, 6, 2, ak4535_mono_out), |
| 58 | SOC_ENUM_SINGLE(AK4535_MODE2, 2, 2, ak4535_hp_out), |
| 59 | SOC_ENUM_SINGLE(AK4535_DAC, 0, 4, ak4535_deemp), |
| 60 | SOC_ENUM_SINGLE(AK4535_MIC, 1, 2, ak4535_mic_select), |
| 61 | }; |
| 62 | |
| 63 | static const struct snd_kcontrol_new ak4535_snd_controls[] = { |
| 64 | SOC_SINGLE("ALC2 Switch", AK4535_SIG1, 1, 1, 0), |
| 65 | SOC_ENUM("Mono 1 Output", ak4535_enum[1]), |
| 66 | SOC_ENUM("Mono 1 Gain", ak4535_enum[0]), |
| 67 | SOC_ENUM("Headphone Output", ak4535_enum[2]), |
| 68 | SOC_ENUM("Playback Deemphasis", ak4535_enum[3]), |
| 69 | SOC_SINGLE("Bass Volume", AK4535_DAC, 2, 3, 0), |
| 70 | SOC_SINGLE("Mic Boost (+20dB) Switch", AK4535_MIC, 0, 1, 0), |
| 71 | SOC_ENUM("Mic Select", ak4535_enum[4]), |
| 72 | SOC_SINGLE("ALC Operation Time", AK4535_TIMER, 0, 3, 0), |
| 73 | SOC_SINGLE("ALC Recovery Time", AK4535_TIMER, 2, 3, 0), |
| 74 | SOC_SINGLE("ALC ZC Time", AK4535_TIMER, 4, 3, 0), |
| 75 | SOC_SINGLE("ALC 1 Switch", AK4535_ALC1, 5, 1, 0), |
| 76 | SOC_SINGLE("ALC 2 Switch", AK4535_ALC1, 6, 1, 0), |
| 77 | SOC_SINGLE("ALC Volume", AK4535_ALC2, 0, 127, 0), |
| 78 | SOC_SINGLE("Capture Volume", AK4535_PGA, 0, 127, 0), |
| 79 | SOC_SINGLE("Left Playback Volume", AK4535_LATT, 0, 127, 1), |
| 80 | SOC_SINGLE("Right Playback Volume", AK4535_RATT, 0, 127, 1), |
| 81 | SOC_SINGLE("AUX Bypass Volume", AK4535_VOL, 0, 15, 0), |
| 82 | SOC_SINGLE("Mic Sidetone Volume", AK4535_VOL, 4, 7, 0), |
| 83 | }; |
| 84 | |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 85 | /* Mono 1 Mixer */ |
| 86 | static const struct snd_kcontrol_new ak4535_mono1_mixer_controls[] = { |
| 87 | SOC_DAPM_SINGLE("Mic Sidetone Switch", AK4535_SIG1, 4, 1, 0), |
| 88 | SOC_DAPM_SINGLE("Mono Playback Switch", AK4535_SIG1, 5, 1, 0), |
| 89 | }; |
| 90 | |
| 91 | /* Stereo Mixer */ |
| 92 | static const struct snd_kcontrol_new ak4535_stereo_mixer_controls[] = { |
| 93 | SOC_DAPM_SINGLE("Mic Sidetone Switch", AK4535_SIG2, 4, 1, 0), |
| 94 | SOC_DAPM_SINGLE("Playback Switch", AK4535_SIG2, 7, 1, 0), |
| 95 | SOC_DAPM_SINGLE("Aux Bypass Switch", AK4535_SIG2, 5, 1, 0), |
| 96 | }; |
| 97 | |
| 98 | /* Input Mixer */ |
| 99 | static const struct snd_kcontrol_new ak4535_input_mixer_controls[] = { |
| 100 | SOC_DAPM_SINGLE("Mic Capture Switch", AK4535_MIC, 2, 1, 0), |
| 101 | SOC_DAPM_SINGLE("Aux Capture Switch", AK4535_MIC, 5, 1, 0), |
| 102 | }; |
| 103 | |
| 104 | /* Input mux */ |
| 105 | static const struct snd_kcontrol_new ak4535_input_mux_control = |
| 106 | SOC_DAPM_ENUM("Input Select", ak4535_enum[4]); |
| 107 | |
| 108 | /* HP L switch */ |
| 109 | static const struct snd_kcontrol_new ak4535_hpl_control = |
| 110 | SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 1, 1, 1); |
| 111 | |
| 112 | /* HP R switch */ |
| 113 | static const struct snd_kcontrol_new ak4535_hpr_control = |
| 114 | SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 0, 1, 1); |
| 115 | |
| 116 | /* mono 2 switch */ |
| 117 | static const struct snd_kcontrol_new ak4535_mono2_control = |
| 118 | SOC_DAPM_SINGLE("Switch", AK4535_SIG1, 0, 1, 0); |
| 119 | |
| 120 | /* Line out switch */ |
| 121 | static const struct snd_kcontrol_new ak4535_line_control = |
| 122 | SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 6, 1, 0); |
| 123 | |
| 124 | /* ak4535 dapm widgets */ |
| 125 | static const struct snd_soc_dapm_widget ak4535_dapm_widgets[] = { |
| 126 | SND_SOC_DAPM_MIXER("Stereo Mixer", SND_SOC_NOPM, 0, 0, |
| 127 | &ak4535_stereo_mixer_controls[0], |
| 128 | ARRAY_SIZE(ak4535_stereo_mixer_controls)), |
| 129 | SND_SOC_DAPM_MIXER("Mono1 Mixer", SND_SOC_NOPM, 0, 0, |
| 130 | &ak4535_mono1_mixer_controls[0], |
| 131 | ARRAY_SIZE(ak4535_mono1_mixer_controls)), |
| 132 | SND_SOC_DAPM_MIXER("Input Mixer", SND_SOC_NOPM, 0, 0, |
| 133 | &ak4535_input_mixer_controls[0], |
| 134 | ARRAY_SIZE(ak4535_input_mixer_controls)), |
| 135 | SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0, |
| 136 | &ak4535_input_mux_control), |
| 137 | SND_SOC_DAPM_DAC("DAC", "Playback", AK4535_PM2, 0, 0), |
| 138 | SND_SOC_DAPM_SWITCH("Mono 2 Enable", SND_SOC_NOPM, 0, 0, |
| 139 | &ak4535_mono2_control), |
| 140 | /* speaker powersave bit */ |
| 141 | SND_SOC_DAPM_PGA("Speaker Enable", AK4535_MODE2, 0, 0, NULL, 0), |
| 142 | SND_SOC_DAPM_SWITCH("Line Out Enable", SND_SOC_NOPM, 0, 0, |
| 143 | &ak4535_line_control), |
| 144 | SND_SOC_DAPM_SWITCH("Left HP Enable", SND_SOC_NOPM, 0, 0, |
| 145 | &ak4535_hpl_control), |
| 146 | SND_SOC_DAPM_SWITCH("Right HP Enable", SND_SOC_NOPM, 0, 0, |
| 147 | &ak4535_hpr_control), |
| 148 | SND_SOC_DAPM_OUTPUT("LOUT"), |
| 149 | SND_SOC_DAPM_OUTPUT("HPL"), |
| 150 | SND_SOC_DAPM_OUTPUT("ROUT"), |
| 151 | SND_SOC_DAPM_OUTPUT("HPR"), |
| 152 | SND_SOC_DAPM_OUTPUT("SPP"), |
| 153 | SND_SOC_DAPM_OUTPUT("SPN"), |
| 154 | SND_SOC_DAPM_OUTPUT("MOUT1"), |
| 155 | SND_SOC_DAPM_OUTPUT("MOUT2"), |
| 156 | SND_SOC_DAPM_OUTPUT("MICOUT"), |
| 157 | SND_SOC_DAPM_ADC("ADC", "Capture", AK4535_PM1, 0, 0), |
| 158 | SND_SOC_DAPM_PGA("Spk Amp", AK4535_PM2, 3, 0, NULL, 0), |
| 159 | SND_SOC_DAPM_PGA("HP R Amp", AK4535_PM2, 1, 0, NULL, 0), |
| 160 | SND_SOC_DAPM_PGA("HP L Amp", AK4535_PM2, 2, 0, NULL, 0), |
| 161 | SND_SOC_DAPM_PGA("Mic", AK4535_PM1, 1, 0, NULL, 0), |
| 162 | SND_SOC_DAPM_PGA("Line Out", AK4535_PM1, 4, 0, NULL, 0), |
| 163 | SND_SOC_DAPM_PGA("Mono Out", AK4535_PM1, 3, 0, NULL, 0), |
| 164 | SND_SOC_DAPM_PGA("AUX In", AK4535_PM1, 2, 0, NULL, 0), |
| 165 | |
| 166 | SND_SOC_DAPM_MICBIAS("Mic Int Bias", AK4535_MIC, 3, 0), |
| 167 | SND_SOC_DAPM_MICBIAS("Mic Ext Bias", AK4535_MIC, 4, 0), |
| 168 | SND_SOC_DAPM_INPUT("MICIN"), |
| 169 | SND_SOC_DAPM_INPUT("MICEXT"), |
| 170 | SND_SOC_DAPM_INPUT("AUX"), |
| 171 | SND_SOC_DAPM_INPUT("MIN"), |
| 172 | SND_SOC_DAPM_INPUT("AIN"), |
| 173 | }; |
| 174 | |
Lu Guanqun | b63c963 | 2011-03-30 21:53:07 +0800 | [diff] [blame] | 175 | static const struct snd_soc_dapm_route ak4535_audio_map[] = { |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 176 | /*stereo mixer */ |
| 177 | {"Stereo Mixer", "Playback Switch", "DAC"}, |
| 178 | {"Stereo Mixer", "Mic Sidetone Switch", "Mic"}, |
| 179 | {"Stereo Mixer", "Aux Bypass Switch", "AUX In"}, |
| 180 | |
| 181 | /* mono1 mixer */ |
| 182 | {"Mono1 Mixer", "Mic Sidetone Switch", "Mic"}, |
| 183 | {"Mono1 Mixer", "Mono Playback Switch", "DAC"}, |
| 184 | |
| 185 | /* Mic */ |
| 186 | {"Mic", NULL, "AIN"}, |
| 187 | {"Input Mux", "Internal", "Mic Int Bias"}, |
| 188 | {"Input Mux", "External", "Mic Ext Bias"}, |
| 189 | {"Mic Int Bias", NULL, "MICIN"}, |
| 190 | {"Mic Ext Bias", NULL, "MICEXT"}, |
| 191 | {"MICOUT", NULL, "Input Mux"}, |
| 192 | |
| 193 | /* line out */ |
| 194 | {"LOUT", NULL, "Line Out Enable"}, |
| 195 | {"ROUT", NULL, "Line Out Enable"}, |
| 196 | {"Line Out Enable", "Switch", "Line Out"}, |
| 197 | {"Line Out", NULL, "Stereo Mixer"}, |
| 198 | |
| 199 | /* mono1 out */ |
| 200 | {"MOUT1", NULL, "Mono Out"}, |
| 201 | {"Mono Out", NULL, "Mono1 Mixer"}, |
| 202 | |
| 203 | /* left HP */ |
| 204 | {"HPL", NULL, "Left HP Enable"}, |
| 205 | {"Left HP Enable", "Switch", "HP L Amp"}, |
| 206 | {"HP L Amp", NULL, "Stereo Mixer"}, |
| 207 | |
| 208 | /* right HP */ |
| 209 | {"HPR", NULL, "Right HP Enable"}, |
| 210 | {"Right HP Enable", "Switch", "HP R Amp"}, |
| 211 | {"HP R Amp", NULL, "Stereo Mixer"}, |
| 212 | |
| 213 | /* speaker */ |
| 214 | {"SPP", NULL, "Speaker Enable"}, |
| 215 | {"SPN", NULL, "Speaker Enable"}, |
| 216 | {"Speaker Enable", "Switch", "Spk Amp"}, |
| 217 | {"Spk Amp", NULL, "MIN"}, |
| 218 | |
| 219 | /* mono 2 */ |
| 220 | {"MOUT2", NULL, "Mono 2 Enable"}, |
| 221 | {"Mono 2 Enable", "Switch", "Stereo Mixer"}, |
| 222 | |
| 223 | /* Aux In */ |
| 224 | {"Aux In", NULL, "AUX"}, |
| 225 | |
| 226 | /* ADC */ |
| 227 | {"ADC", NULL, "Input Mixer"}, |
| 228 | {"Input Mixer", "Mic Capture Switch", "Mic"}, |
| 229 | {"Input Mixer", "Aux Capture Switch", "Aux In"}, |
| 230 | }; |
| 231 | |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 232 | static int ak4535_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 233 | int clk_id, unsigned int freq, int dir) |
| 234 | { |
| 235 | struct snd_soc_codec *codec = codec_dai->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 236 | struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 237 | |
| 238 | ak4535->sysclk = freq; |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | static int ak4535_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 243 | struct snd_pcm_hw_params *params, |
| 244 | struct snd_soc_dai *dai) |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 245 | { |
| 246 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 247 | struct snd_soc_codec *codec = rtd->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 248 | struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec); |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 249 | u8 mode2 = snd_soc_read(codec, AK4535_MODE2) & ~(0x3 << 5); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 250 | int rate = params_rate(params), fs = 256; |
| 251 | |
| 252 | if (rate) |
| 253 | fs = ak4535->sysclk / rate; |
| 254 | |
| 255 | /* set fs */ |
| 256 | switch (fs) { |
| 257 | case 1024: |
| 258 | mode2 |= (0x2 << 5); |
| 259 | break; |
| 260 | case 512: |
| 261 | mode2 |= (0x1 << 5); |
| 262 | break; |
| 263 | case 256: |
| 264 | break; |
| 265 | } |
| 266 | |
| 267 | /* set rate */ |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 268 | snd_soc_write(codec, AK4535_MODE2, mode2); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 269 | return 0; |
| 270 | } |
| 271 | |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 272 | static int ak4535_set_dai_fmt(struct snd_soc_dai *codec_dai, |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 273 | unsigned int fmt) |
| 274 | { |
| 275 | struct snd_soc_codec *codec = codec_dai->codec; |
| 276 | u8 mode1 = 0; |
| 277 | |
| 278 | /* interface format */ |
| 279 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 280 | case SND_SOC_DAIFMT_I2S: |
| 281 | mode1 = 0x0002; |
| 282 | break; |
| 283 | case SND_SOC_DAIFMT_LEFT_J: |
| 284 | mode1 = 0x0001; |
| 285 | break; |
| 286 | default: |
| 287 | return -EINVAL; |
| 288 | } |
| 289 | |
| 290 | /* use 32 fs for BCLK to save power */ |
| 291 | mode1 |= 0x4; |
| 292 | |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 293 | snd_soc_write(codec, AK4535_MODE1, mode1); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 294 | return 0; |
| 295 | } |
| 296 | |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 297 | static int ak4535_mute(struct snd_soc_dai *dai, int mute) |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 298 | { |
| 299 | struct snd_soc_codec *codec = dai->codec; |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 300 | u16 mute_reg = snd_soc_read(codec, AK4535_DAC); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 301 | if (!mute) |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 302 | snd_soc_write(codec, AK4535_DAC, mute_reg & ~0x20); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 303 | else |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 304 | snd_soc_write(codec, AK4535_DAC, mute_reg | 0x20); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | static int ak4535_set_bias_level(struct snd_soc_codec *codec, |
| 309 | enum snd_soc_bias_level level) |
| 310 | { |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 311 | switch (level) { |
| 312 | case SND_SOC_BIAS_ON: |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 313 | snd_soc_update_bits(codec, AK4535_DAC, 0x20, 0); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 314 | break; |
| 315 | case SND_SOC_BIAS_PREPARE: |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 316 | snd_soc_update_bits(codec, AK4535_DAC, 0x20, 0x20); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 317 | break; |
| 318 | case SND_SOC_BIAS_STANDBY: |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 319 | snd_soc_update_bits(codec, AK4535_PM1, 0x80, 0x80); |
| 320 | snd_soc_update_bits(codec, AK4535_PM2, 0x80, 0); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 321 | break; |
| 322 | case SND_SOC_BIAS_OFF: |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 323 | snd_soc_update_bits(codec, AK4535_PM1, 0x80, 0); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 324 | break; |
| 325 | } |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 326 | codec->dapm.bias_level = level; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | #define AK4535_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ |
| 331 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\ |
| 332 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000) |
| 333 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 334 | static struct snd_soc_dai_ops ak4535_dai_ops = { |
| 335 | .hw_params = ak4535_hw_params, |
| 336 | .set_fmt = ak4535_set_dai_fmt, |
| 337 | .digital_mute = ak4535_mute, |
| 338 | .set_sysclk = ak4535_set_dai_sysclk, |
| 339 | }; |
| 340 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 341 | static struct snd_soc_dai_driver ak4535_dai = { |
| 342 | .name = "ak4535-hifi", |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 343 | .playback = { |
| 344 | .stream_name = "Playback", |
| 345 | .channels_min = 1, |
| 346 | .channels_max = 2, |
| 347 | .rates = AK4535_RATES, |
| 348 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
| 349 | .capture = { |
| 350 | .stream_name = "Capture", |
| 351 | .channels_min = 1, |
| 352 | .channels_max = 2, |
| 353 | .rates = AK4535_RATES, |
| 354 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 355 | .ops = &ak4535_dai_ops, |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 356 | }; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 357 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 358 | static int ak4535_suspend(struct snd_soc_codec *codec, pm_message_t state) |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 359 | { |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 360 | ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 361 | return 0; |
| 362 | } |
| 363 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 364 | static int ak4535_resume(struct snd_soc_codec *codec) |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 365 | { |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 366 | snd_soc_cache_sync(codec); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 367 | ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 368 | return 0; |
| 369 | } |
| 370 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 371 | static int ak4535_probe(struct snd_soc_codec *codec) |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 372 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 373 | struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec); |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 374 | int ret; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 375 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 376 | printk(KERN_INFO "AK4535 Audio Codec %s", AK4535_VERSION); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 377 | |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 378 | ret = snd_soc_codec_set_cache_io(codec, 8, 8, ak4535->control_type); |
| 379 | if (ret < 0) { |
| 380 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
| 381 | return ret; |
| 382 | } |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 383 | /* power on device */ |
| 384 | ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
| 385 | |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 386 | snd_soc_add_controls(codec, ak4535_snd_controls, |
| 387 | ARRAY_SIZE(ak4535_snd_controls)); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 388 | return 0; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 389 | } |
| 390 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 391 | /* power down chip */ |
| 392 | static int ak4535_remove(struct snd_soc_codec *codec) |
| 393 | { |
| 394 | ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | static struct snd_soc_codec_driver soc_codec_dev_ak4535 = { |
| 399 | .probe = ak4535_probe, |
| 400 | .remove = ak4535_remove, |
| 401 | .suspend = ak4535_suspend, |
| 402 | .resume = ak4535_resume, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 403 | .set_bias_level = ak4535_set_bias_level, |
| 404 | .reg_cache_size = ARRAY_SIZE(ak4535_reg), |
| 405 | .reg_word_size = sizeof(u8), |
| 406 | .reg_cache_default = ak4535_reg, |
Lu Guanqun | b63c963 | 2011-03-30 21:53:07 +0800 | [diff] [blame] | 407 | .dapm_widgets = ak4535_dapm_widgets, |
| 408 | .num_dapm_widgets = ARRAY_SIZE(ak4535_dapm_widgets), |
| 409 | .dapm_routes = ak4535_audio_map, |
| 410 | .num_dapm_routes = ARRAY_SIZE(ak4535_audio_map), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 411 | }; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 412 | |
| 413 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 414 | static __devinit int ak4535_i2c_probe(struct i2c_client *i2c, |
| 415 | const struct i2c_device_id *id) |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 416 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 417 | struct ak4535_priv *ak4535; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 418 | int ret; |
| 419 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 420 | ak4535 = kzalloc(sizeof(struct ak4535_priv), GFP_KERNEL); |
| 421 | if (ak4535 == NULL) |
| 422 | return -ENOMEM; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 423 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 424 | i2c_set_clientdata(i2c, ak4535); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 425 | ak4535->control_type = SND_SOC_I2C; |
| 426 | |
| 427 | ret = snd_soc_register_codec(&i2c->dev, |
| 428 | &soc_codec_dev_ak4535, &ak4535_dai, 1); |
Jean Delvare | d28d271 | 2008-09-01 18:46:59 +0100 | [diff] [blame] | 429 | if (ret < 0) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 430 | kfree(ak4535); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 431 | return ret; |
| 432 | } |
| 433 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 434 | static __devexit int ak4535_i2c_remove(struct i2c_client *client) |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 435 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 436 | snd_soc_unregister_codec(&client->dev); |
| 437 | kfree(i2c_get_clientdata(client)); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 438 | return 0; |
| 439 | } |
| 440 | |
Jean Delvare | d28d271 | 2008-09-01 18:46:59 +0100 | [diff] [blame] | 441 | static const struct i2c_device_id ak4535_i2c_id[] = { |
| 442 | { "ak4535", 0 }, |
| 443 | { } |
| 444 | }; |
| 445 | MODULE_DEVICE_TABLE(i2c, ak4535_i2c_id); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 446 | |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 447 | static struct i2c_driver ak4535_i2c_driver = { |
| 448 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 449 | .name = "ak4535-codec", |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 450 | .owner = THIS_MODULE, |
| 451 | }, |
Jean Delvare | d28d271 | 2008-09-01 18:46:59 +0100 | [diff] [blame] | 452 | .probe = ak4535_i2c_probe, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 453 | .remove = __devexit_p(ak4535_i2c_remove), |
Jean Delvare | d28d271 | 2008-09-01 18:46:59 +0100 | [diff] [blame] | 454 | .id_table = ak4535_i2c_id, |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 455 | }; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 456 | #endif |
| 457 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 458 | static int __init ak4535_modinit(void) |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 459 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 460 | int ret = 0; |
| 461 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 462 | ret = i2c_add_driver(&ak4535_i2c_driver); |
| 463 | if (ret != 0) { |
| 464 | printk(KERN_ERR "Failed to register AK4535 I2C driver: %d\n", |
| 465 | ret); |
| 466 | } |
| 467 | #endif |
| 468 | return ret; |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 469 | } |
| 470 | module_init(ak4535_modinit); |
| 471 | |
| 472 | static void __exit ak4535_exit(void) |
| 473 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 474 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 475 | i2c_del_driver(&ak4535_i2c_driver); |
| 476 | #endif |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 477 | } |
| 478 | module_exit(ak4535_exit); |
| 479 | |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 480 | MODULE_DESCRIPTION("Soc AK4535 driver"); |
| 481 | MODULE_AUTHOR("Richard Purdie"); |
| 482 | MODULE_LICENSE("GPL"); |