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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 22 | #include <sound/core.h> |
| 23 | #include <sound/pcm.h> |
| 24 | #include <sound/pcm_params.h> |
| 25 | #include <sound/soc.h> |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 26 | #include <sound/initval.h> |
| 27 | |
| 28 | #include "ak4535.h" |
| 29 | |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 30 | #define AK4535_VERSION "0.3" |
| 31 | |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 32 | /* codec private data */ |
| 33 | struct ak4535_priv { |
| 34 | unsigned int sysclk; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 35 | enum snd_soc_control_type control_type; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | /* |
| 39 | * ak4535 register cache |
| 40 | */ |
Axel Lin | 7c04241 | 2011-10-13 17:17:06 +0800 | [diff] [blame] | 41 | static 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 Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 46 | }; |
| 47 | |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 48 | static const char *ak4535_mono_gain[] = {"+6dB", "-17dB"}; |
| 49 | static const char *ak4535_mono_out[] = {"(L + R)/2", "Hi-Z"}; |
| 50 | static const char *ak4535_hp_out[] = {"Stereo", "Mono"}; |
| 51 | static const char *ak4535_deemp[] = {"44.1kHz", "Off", "48kHz", "32kHz"}; |
| 52 | static const char *ak4535_mic_select[] = {"Internal", "External"}; |
| 53 | |
| 54 | static 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 | |
| 62 | static 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 Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 84 | /* Mono 1 Mixer */ |
| 85 | static 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 */ |
| 91 | static 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 */ |
| 98 | static 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 */ |
| 104 | static const struct snd_kcontrol_new ak4535_input_mux_control = |
| 105 | SOC_DAPM_ENUM("Input Select", ak4535_enum[4]); |
| 106 | |
| 107 | /* HP L switch */ |
| 108 | static const struct snd_kcontrol_new ak4535_hpl_control = |
| 109 | SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 1, 1, 1); |
| 110 | |
| 111 | /* HP R switch */ |
| 112 | static const struct snd_kcontrol_new ak4535_hpr_control = |
| 113 | SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 0, 1, 1); |
| 114 | |
| 115 | /* mono 2 switch */ |
| 116 | static const struct snd_kcontrol_new ak4535_mono2_control = |
| 117 | SOC_DAPM_SINGLE("Switch", AK4535_SIG1, 0, 1, 0); |
| 118 | |
| 119 | /* Line out switch */ |
| 120 | static const struct snd_kcontrol_new ak4535_line_control = |
| 121 | SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 6, 1, 0); |
| 122 | |
| 123 | /* ak4535 dapm widgets */ |
| 124 | static 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 Guanqun | b63c963 | 2011-03-30 21:53:07 +0800 | [diff] [blame] | 174 | static const struct snd_soc_dapm_route ak4535_audio_map[] = { |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 175 | /*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 Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 231 | static int ak4535_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 232 | int clk_id, unsigned int freq, int dir) |
| 233 | { |
| 234 | struct snd_soc_codec *codec = codec_dai->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 235 | struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 236 | |
| 237 | ak4535->sysclk = freq; |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | static int ak4535_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 242 | struct snd_pcm_hw_params *params, |
| 243 | struct snd_soc_dai *dai) |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 244 | { |
| 245 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 246 | struct snd_soc_codec *codec = rtd->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 247 | struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec); |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 248 | u8 mode2 = snd_soc_read(codec, AK4535_MODE2) & ~(0x3 << 5); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 249 | 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 Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 267 | snd_soc_write(codec, AK4535_MODE2, mode2); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 268 | return 0; |
| 269 | } |
| 270 | |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 271 | static int ak4535_set_dai_fmt(struct snd_soc_dai *codec_dai, |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 272 | 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 Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 292 | snd_soc_write(codec, AK4535_MODE1, mode1); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 293 | return 0; |
| 294 | } |
| 295 | |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 296 | static int ak4535_mute(struct snd_soc_dai *dai, int mute) |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 297 | { |
| 298 | struct snd_soc_codec *codec = dai->codec; |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 299 | u16 mute_reg = snd_soc_read(codec, AK4535_DAC); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 300 | if (!mute) |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 301 | snd_soc_write(codec, AK4535_DAC, mute_reg & ~0x20); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 302 | else |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 303 | snd_soc_write(codec, AK4535_DAC, mute_reg | 0x20); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | static int ak4535_set_bias_level(struct snd_soc_codec *codec, |
| 308 | enum snd_soc_bias_level level) |
| 309 | { |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 310 | switch (level) { |
| 311 | case SND_SOC_BIAS_ON: |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 312 | snd_soc_update_bits(codec, AK4535_DAC, 0x20, 0); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 313 | break; |
| 314 | case SND_SOC_BIAS_PREPARE: |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 315 | snd_soc_update_bits(codec, AK4535_DAC, 0x20, 0x20); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 316 | break; |
| 317 | case SND_SOC_BIAS_STANDBY: |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 318 | snd_soc_update_bits(codec, AK4535_PM1, 0x80, 0x80); |
| 319 | snd_soc_update_bits(codec, AK4535_PM2, 0x80, 0); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 320 | break; |
| 321 | case SND_SOC_BIAS_OFF: |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 322 | snd_soc_update_bits(codec, AK4535_PM1, 0x80, 0); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 323 | break; |
| 324 | } |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 325 | codec->dapm.bias_level = level; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 326 | 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 Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 333 | static const struct snd_soc_dai_ops ak4535_dai_ops = { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 334 | .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 Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 340 | static struct snd_soc_dai_driver ak4535_dai = { |
| 341 | .name = "ak4535-hifi", |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 342 | .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 Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 354 | .ops = &ak4535_dai_ops, |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 355 | }; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 356 | |
Lars-Peter Clausen | 84b315e | 2011-12-02 10:18:28 +0100 | [diff] [blame] | 357 | static int ak4535_suspend(struct snd_soc_codec *codec) |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 358 | { |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 359 | ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 360 | return 0; |
| 361 | } |
| 362 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 363 | static int ak4535_resume(struct snd_soc_codec *codec) |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 364 | { |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 365 | snd_soc_cache_sync(codec); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 366 | ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 367 | return 0; |
| 368 | } |
| 369 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 370 | static int ak4535_probe(struct snd_soc_codec *codec) |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 371 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 372 | struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec); |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 373 | int ret; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 374 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 375 | printk(KERN_INFO "AK4535 Audio Codec %s", AK4535_VERSION); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 376 | |
Axel Lin | 3b18450 | 2011-10-06 10:11:51 +0800 | [diff] [blame] | 377 | 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 Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 382 | /* power on device */ |
| 383 | ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
| 384 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 385 | snd_soc_add_codec_controls(codec, ak4535_snd_controls, |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 386 | ARRAY_SIZE(ak4535_snd_controls)); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 387 | return 0; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 388 | } |
| 389 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 390 | /* power down chip */ |
| 391 | static int ak4535_remove(struct snd_soc_codec *codec) |
| 392 | { |
| 393 | ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | static 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 Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 402 | .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 Guanqun | b63c963 | 2011-03-30 21:53:07 +0800 | [diff] [blame] | 406 | .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 Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 410 | }; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 411 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 412 | static __devinit int ak4535_i2c_probe(struct i2c_client *i2c, |
| 413 | const struct i2c_device_id *id) |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 414 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 415 | struct ak4535_priv *ak4535; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 416 | int ret; |
| 417 | |
Axel Lin | 7246492 | 2011-12-20 14:38:09 +0800 | [diff] [blame] | 418 | ak4535 = devm_kzalloc(&i2c->dev, sizeof(struct ak4535_priv), |
| 419 | GFP_KERNEL); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 420 | if (ak4535 == NULL) |
| 421 | return -ENOMEM; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 422 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 423 | i2c_set_clientdata(i2c, ak4535); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 424 | ak4535->control_type = SND_SOC_I2C; |
| 425 | |
| 426 | ret = snd_soc_register_codec(&i2c->dev, |
| 427 | &soc_codec_dev_ak4535, &ak4535_dai, 1); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 428 | return ret; |
| 429 | } |
| 430 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 431 | static __devexit int ak4535_i2c_remove(struct i2c_client *client) |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 432 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 433 | snd_soc_unregister_codec(&client->dev); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 434 | return 0; |
| 435 | } |
| 436 | |
Jean Delvare | d28d271 | 2008-09-01 18:46:59 +0100 | [diff] [blame] | 437 | static const struct i2c_device_id ak4535_i2c_id[] = { |
| 438 | { "ak4535", 0 }, |
| 439 | { } |
| 440 | }; |
| 441 | MODULE_DEVICE_TABLE(i2c, ak4535_i2c_id); |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 442 | |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 443 | static struct i2c_driver ak4535_i2c_driver = { |
| 444 | .driver = { |
Mark Brown | d69280b | 2012-02-16 22:52:19 -0800 | [diff] [blame] | 445 | .name = "ak4535", |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 446 | .owner = THIS_MODULE, |
| 447 | }, |
Jean Delvare | d28d271 | 2008-09-01 18:46:59 +0100 | [diff] [blame] | 448 | .probe = ak4535_i2c_probe, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 449 | .remove = __devexit_p(ak4535_i2c_remove), |
Jean Delvare | d28d271 | 2008-09-01 18:46:59 +0100 | [diff] [blame] | 450 | .id_table = ak4535_i2c_id, |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 451 | }; |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 452 | |
Mark Brown | b08c576 | 2012-02-16 22:52:44 -0800 | [diff] [blame^] | 453 | module_i2c_driver(ak4535_i2c_driver); |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 454 | |
Richard Purdie | 796d2ca | 2008-06-23 14:51:28 +0100 | [diff] [blame] | 455 | MODULE_DESCRIPTION("Soc AK4535 driver"); |
| 456 | MODULE_AUTHOR("Richard Purdie"); |
| 457 | MODULE_LICENSE("GPL"); |