Joonyoung Shim | 2312fd8 | 2009-09-10 00:12:43 +0900 | [diff] [blame] | 1 | /* |
| 2 | * ak4671.c -- audio driver for AK4671 |
| 3 | * |
| 4 | * Copyright (C) 2009 Samsung Electronics Co.Ltd |
| 5 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/i2c.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <sound/soc.h> |
| 19 | #include <sound/soc-dapm.h> |
| 20 | #include <sound/initval.h> |
| 21 | #include <sound/tlv.h> |
| 22 | |
| 23 | #include "ak4671.h" |
| 24 | |
| 25 | static struct snd_soc_codec *ak4671_codec; |
| 26 | |
| 27 | /* codec private data */ |
| 28 | struct ak4671_priv { |
| 29 | struct snd_soc_codec codec; |
| 30 | u8 reg_cache[AK4671_CACHEREGNUM]; |
| 31 | }; |
| 32 | |
| 33 | /* ak4671 register cache & default register settings */ |
| 34 | static const u8 ak4671_reg[AK4671_CACHEREGNUM] = { |
| 35 | 0x00, /* AK4671_AD_DA_POWER_MANAGEMENT (0x00) */ |
| 36 | 0xf6, /* AK4671_PLL_MODE_SELECT0 (0x01) */ |
| 37 | 0x00, /* AK4671_PLL_MODE_SELECT1 (0x02) */ |
| 38 | 0x02, /* AK4671_FORMAT_SELECT (0x03) */ |
| 39 | 0x00, /* AK4671_MIC_SIGNAL_SELECT (0x04) */ |
| 40 | 0x55, /* AK4671_MIC_AMP_GAIN (0x05) */ |
| 41 | 0x00, /* AK4671_MIXING_POWER_MANAGEMENT0 (0x06) */ |
| 42 | 0x00, /* AK4671_MIXING_POWER_MANAGEMENT1 (0x07) */ |
| 43 | 0xb5, /* AK4671_OUTPUT_VOLUME_CONTROL (0x08) */ |
| 44 | 0x00, /* AK4671_LOUT1_SIGNAL_SELECT (0x09) */ |
| 45 | 0x00, /* AK4671_ROUT1_SIGNAL_SELECT (0x0a) */ |
| 46 | 0x00, /* AK4671_LOUT2_SIGNAL_SELECT (0x0b) */ |
| 47 | 0x00, /* AK4671_ROUT2_SIGNAL_SELECT (0x0c) */ |
| 48 | 0x00, /* AK4671_LOUT3_SIGNAL_SELECT (0x0d) */ |
| 49 | 0x00, /* AK4671_ROUT3_SIGNAL_SELECT (0x0e) */ |
| 50 | 0x00, /* AK4671_LOUT1_POWER_MANAGERMENT (0x0f) */ |
| 51 | 0x00, /* AK4671_LOUT2_POWER_MANAGERMENT (0x10) */ |
| 52 | 0x80, /* AK4671_LOUT3_POWER_MANAGERMENT (0x11) */ |
| 53 | 0x91, /* AK4671_LCH_INPUT_VOLUME_CONTROL (0x12) */ |
| 54 | 0x91, /* AK4671_RCH_INPUT_VOLUME_CONTROL (0x13) */ |
| 55 | 0xe1, /* AK4671_ALC_REFERENCE_SELECT (0x14) */ |
| 56 | 0x00, /* AK4671_DIGITAL_MIXING_CONTROL (0x15) */ |
| 57 | 0x00, /* AK4671_ALC_TIMER_SELECT (0x16) */ |
| 58 | 0x00, /* AK4671_ALC_MODE_CONTROL (0x17) */ |
| 59 | 0x02, /* AK4671_MODE_CONTROL1 (0x18) */ |
| 60 | 0x01, /* AK4671_MODE_CONTROL2 (0x19) */ |
| 61 | 0x18, /* AK4671_LCH_OUTPUT_VOLUME_CONTROL (0x1a) */ |
| 62 | 0x18, /* AK4671_RCH_OUTPUT_VOLUME_CONTROL (0x1b) */ |
| 63 | 0x00, /* AK4671_SIDETONE_A_CONTROL (0x1c) */ |
| 64 | 0x02, /* AK4671_DIGITAL_FILTER_SELECT (0x1d) */ |
| 65 | 0x00, /* AK4671_FIL3_COEFFICIENT0 (0x1e) */ |
| 66 | 0x00, /* AK4671_FIL3_COEFFICIENT1 (0x1f) */ |
| 67 | 0x00, /* AK4671_FIL3_COEFFICIENT2 (0x20) */ |
| 68 | 0x00, /* AK4671_FIL3_COEFFICIENT3 (0x21) */ |
| 69 | 0x00, /* AK4671_EQ_COEFFICIENT0 (0x22) */ |
| 70 | 0x00, /* AK4671_EQ_COEFFICIENT1 (0x23) */ |
| 71 | 0x00, /* AK4671_EQ_COEFFICIENT2 (0x24) */ |
| 72 | 0x00, /* AK4671_EQ_COEFFICIENT3 (0x25) */ |
| 73 | 0x00, /* AK4671_EQ_COEFFICIENT4 (0x26) */ |
| 74 | 0x00, /* AK4671_EQ_COEFFICIENT5 (0x27) */ |
| 75 | 0xa9, /* AK4671_FIL1_COEFFICIENT0 (0x28) */ |
| 76 | 0x1f, /* AK4671_FIL1_COEFFICIENT1 (0x29) */ |
| 77 | 0xad, /* AK4671_FIL1_COEFFICIENT2 (0x2a) */ |
| 78 | 0x20, /* AK4671_FIL1_COEFFICIENT3 (0x2b) */ |
| 79 | 0x00, /* AK4671_FIL2_COEFFICIENT0 (0x2c) */ |
| 80 | 0x00, /* AK4671_FIL2_COEFFICIENT1 (0x2d) */ |
| 81 | 0x00, /* AK4671_FIL2_COEFFICIENT2 (0x2e) */ |
| 82 | 0x00, /* AK4671_FIL2_COEFFICIENT3 (0x2f) */ |
| 83 | 0x00, /* AK4671_DIGITAL_FILTER_SELECT2 (0x30) */ |
| 84 | 0x00, /* this register not used */ |
| 85 | 0x00, /* AK4671_E1_COEFFICIENT0 (0x32) */ |
| 86 | 0x00, /* AK4671_E1_COEFFICIENT1 (0x33) */ |
| 87 | 0x00, /* AK4671_E1_COEFFICIENT2 (0x34) */ |
| 88 | 0x00, /* AK4671_E1_COEFFICIENT3 (0x35) */ |
| 89 | 0x00, /* AK4671_E1_COEFFICIENT4 (0x36) */ |
| 90 | 0x00, /* AK4671_E1_COEFFICIENT5 (0x37) */ |
| 91 | 0x00, /* AK4671_E2_COEFFICIENT0 (0x38) */ |
| 92 | 0x00, /* AK4671_E2_COEFFICIENT1 (0x39) */ |
| 93 | 0x00, /* AK4671_E2_COEFFICIENT2 (0x3a) */ |
| 94 | 0x00, /* AK4671_E2_COEFFICIENT3 (0x3b) */ |
| 95 | 0x00, /* AK4671_E2_COEFFICIENT4 (0x3c) */ |
| 96 | 0x00, /* AK4671_E2_COEFFICIENT5 (0x3d) */ |
| 97 | 0x00, /* AK4671_E3_COEFFICIENT0 (0x3e) */ |
| 98 | 0x00, /* AK4671_E3_COEFFICIENT1 (0x3f) */ |
| 99 | 0x00, /* AK4671_E3_COEFFICIENT2 (0x40) */ |
| 100 | 0x00, /* AK4671_E3_COEFFICIENT3 (0x41) */ |
| 101 | 0x00, /* AK4671_E3_COEFFICIENT4 (0x42) */ |
| 102 | 0x00, /* AK4671_E3_COEFFICIENT5 (0x43) */ |
| 103 | 0x00, /* AK4671_E4_COEFFICIENT0 (0x44) */ |
| 104 | 0x00, /* AK4671_E4_COEFFICIENT1 (0x45) */ |
| 105 | 0x00, /* AK4671_E4_COEFFICIENT2 (0x46) */ |
| 106 | 0x00, /* AK4671_E4_COEFFICIENT3 (0x47) */ |
| 107 | 0x00, /* AK4671_E4_COEFFICIENT4 (0x48) */ |
| 108 | 0x00, /* AK4671_E4_COEFFICIENT5 (0x49) */ |
| 109 | 0x00, /* AK4671_E5_COEFFICIENT0 (0x4a) */ |
| 110 | 0x00, /* AK4671_E5_COEFFICIENT1 (0x4b) */ |
| 111 | 0x00, /* AK4671_E5_COEFFICIENT2 (0x4c) */ |
| 112 | 0x00, /* AK4671_E5_COEFFICIENT3 (0x4d) */ |
| 113 | 0x00, /* AK4671_E5_COEFFICIENT4 (0x4e) */ |
| 114 | 0x00, /* AK4671_E5_COEFFICIENT5 (0x4f) */ |
| 115 | 0x88, /* AK4671_EQ_CONTROL_250HZ_100HZ (0x50) */ |
| 116 | 0x88, /* AK4671_EQ_CONTROL_3500HZ_1KHZ (0x51) */ |
| 117 | 0x08, /* AK4671_EQ_CONTRO_10KHZ (0x52) */ |
| 118 | 0x00, /* AK4671_PCM_IF_CONTROL0 (0x53) */ |
| 119 | 0x00, /* AK4671_PCM_IF_CONTROL1 (0x54) */ |
| 120 | 0x00, /* AK4671_PCM_IF_CONTROL2 (0x55) */ |
| 121 | 0x18, /* AK4671_DIGITAL_VOLUME_B_CONTROL (0x56) */ |
| 122 | 0x18, /* AK4671_DIGITAL_VOLUME_C_CONTROL (0x57) */ |
| 123 | 0x00, /* AK4671_SIDETONE_VOLUME_CONTROL (0x58) */ |
| 124 | 0x00, /* AK4671_DIGITAL_MIXING_CONTROL2 (0x59) */ |
| 125 | 0x00, /* AK4671_SAR_ADC_CONTROL (0x5a) */ |
| 126 | }; |
| 127 | |
| 128 | /* |
| 129 | * LOUT1/ROUT1 output volume control: |
| 130 | * from -24 to 6 dB in 6 dB steps (mute instead of -30 dB) |
| 131 | */ |
| 132 | static DECLARE_TLV_DB_SCALE(out1_tlv, -3000, 600, 1); |
| 133 | |
| 134 | /* |
| 135 | * LOUT2/ROUT2 output volume control: |
| 136 | * from -33 to 6 dB in 3 dB steps (mute instead of -33 dB) |
| 137 | */ |
| 138 | static DECLARE_TLV_DB_SCALE(out2_tlv, -3300, 300, 1); |
| 139 | |
| 140 | /* |
| 141 | * LOUT3/ROUT3 output volume control: |
| 142 | * from -6 to 3 dB in 3 dB steps |
| 143 | */ |
| 144 | static DECLARE_TLV_DB_SCALE(out3_tlv, -600, 300, 0); |
| 145 | |
| 146 | /* |
| 147 | * Mic amp gain control: |
| 148 | * from -15 to 30 dB in 3 dB steps |
| 149 | * REVISIT: The actual min value(0x01) is -12 dB and the reg value 0x00 is not |
| 150 | * available |
| 151 | */ |
| 152 | static DECLARE_TLV_DB_SCALE(mic_amp_tlv, -1500, 300, 0); |
| 153 | |
| 154 | static const struct snd_kcontrol_new ak4671_snd_controls[] = { |
| 155 | /* Common playback gain controls */ |
| 156 | SOC_SINGLE_TLV("Line Output1 Playback Volume", |
| 157 | AK4671_OUTPUT_VOLUME_CONTROL, 0, 0x6, 0, out1_tlv), |
| 158 | SOC_SINGLE_TLV("Headphone Output2 Playback Volume", |
| 159 | AK4671_OUTPUT_VOLUME_CONTROL, 4, 0xd, 0, out2_tlv), |
| 160 | SOC_SINGLE_TLV("Line Output3 Playback Volume", |
| 161 | AK4671_LOUT3_POWER_MANAGERMENT, 6, 0x3, 0, out3_tlv), |
| 162 | |
| 163 | /* Common capture gain controls */ |
| 164 | SOC_DOUBLE_TLV("Mic Amp Capture Volume", |
| 165 | AK4671_MIC_AMP_GAIN, 0, 4, 0xf, 0, mic_amp_tlv), |
| 166 | }; |
| 167 | |
| 168 | /* event handlers */ |
| 169 | static int ak4671_out2_event(struct snd_soc_dapm_widget *w, |
| 170 | struct snd_kcontrol *kcontrol, int event) |
| 171 | { |
| 172 | struct snd_soc_codec *codec = w->codec; |
| 173 | u8 reg; |
| 174 | |
| 175 | switch (event) { |
| 176 | case SND_SOC_DAPM_POST_PMU: |
| 177 | reg = snd_soc_read(codec, AK4671_LOUT2_POWER_MANAGERMENT); |
| 178 | reg |= AK4671_MUTEN; |
| 179 | snd_soc_write(codec, AK4671_LOUT2_POWER_MANAGERMENT, reg); |
| 180 | break; |
| 181 | case SND_SOC_DAPM_PRE_PMD: |
| 182 | reg = snd_soc_read(codec, AK4671_LOUT2_POWER_MANAGERMENT); |
| 183 | reg &= ~AK4671_MUTEN; |
| 184 | snd_soc_write(codec, AK4671_LOUT2_POWER_MANAGERMENT, reg); |
| 185 | break; |
| 186 | } |
| 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | /* Output Mixers */ |
| 192 | static const struct snd_kcontrol_new ak4671_lout1_mixer_controls[] = { |
| 193 | SOC_DAPM_SINGLE("DACL", AK4671_LOUT1_SIGNAL_SELECT, 0, 1, 0), |
| 194 | SOC_DAPM_SINGLE("LINL1", AK4671_LOUT1_SIGNAL_SELECT, 1, 1, 0), |
| 195 | SOC_DAPM_SINGLE("LINL2", AK4671_LOUT1_SIGNAL_SELECT, 2, 1, 0), |
| 196 | SOC_DAPM_SINGLE("LINL3", AK4671_LOUT1_SIGNAL_SELECT, 3, 1, 0), |
| 197 | SOC_DAPM_SINGLE("LINL4", AK4671_LOUT1_SIGNAL_SELECT, 4, 1, 0), |
| 198 | SOC_DAPM_SINGLE("LOOPL", AK4671_LOUT1_SIGNAL_SELECT, 5, 1, 0), |
| 199 | }; |
| 200 | |
| 201 | static const struct snd_kcontrol_new ak4671_rout1_mixer_controls[] = { |
| 202 | SOC_DAPM_SINGLE("DACR", AK4671_ROUT1_SIGNAL_SELECT, 0, 1, 0), |
| 203 | SOC_DAPM_SINGLE("RINR1", AK4671_ROUT1_SIGNAL_SELECT, 1, 1, 0), |
| 204 | SOC_DAPM_SINGLE("RINR2", AK4671_ROUT1_SIGNAL_SELECT, 2, 1, 0), |
| 205 | SOC_DAPM_SINGLE("RINR3", AK4671_ROUT1_SIGNAL_SELECT, 3, 1, 0), |
| 206 | SOC_DAPM_SINGLE("RINR4", AK4671_ROUT1_SIGNAL_SELECT, 4, 1, 0), |
| 207 | SOC_DAPM_SINGLE("LOOPR", AK4671_ROUT1_SIGNAL_SELECT, 5, 1, 0), |
| 208 | }; |
| 209 | |
| 210 | static const struct snd_kcontrol_new ak4671_lout2_mixer_controls[] = { |
| 211 | SOC_DAPM_SINGLE("DACHL", AK4671_LOUT2_SIGNAL_SELECT, 0, 1, 0), |
| 212 | SOC_DAPM_SINGLE("LINH1", AK4671_LOUT2_SIGNAL_SELECT, 1, 1, 0), |
| 213 | SOC_DAPM_SINGLE("LINH2", AK4671_LOUT2_SIGNAL_SELECT, 2, 1, 0), |
| 214 | SOC_DAPM_SINGLE("LINH3", AK4671_LOUT2_SIGNAL_SELECT, 3, 1, 0), |
| 215 | SOC_DAPM_SINGLE("LINH4", AK4671_LOUT2_SIGNAL_SELECT, 4, 1, 0), |
| 216 | SOC_DAPM_SINGLE("LOOPHL", AK4671_LOUT2_SIGNAL_SELECT, 5, 1, 0), |
| 217 | }; |
| 218 | |
| 219 | static const struct snd_kcontrol_new ak4671_rout2_mixer_controls[] = { |
| 220 | SOC_DAPM_SINGLE("DACHR", AK4671_ROUT2_SIGNAL_SELECT, 0, 1, 0), |
| 221 | SOC_DAPM_SINGLE("RINH1", AK4671_ROUT2_SIGNAL_SELECT, 1, 1, 0), |
| 222 | SOC_DAPM_SINGLE("RINH2", AK4671_ROUT2_SIGNAL_SELECT, 2, 1, 0), |
| 223 | SOC_DAPM_SINGLE("RINH3", AK4671_ROUT2_SIGNAL_SELECT, 3, 1, 0), |
| 224 | SOC_DAPM_SINGLE("RINH4", AK4671_ROUT2_SIGNAL_SELECT, 4, 1, 0), |
| 225 | SOC_DAPM_SINGLE("LOOPHR", AK4671_ROUT2_SIGNAL_SELECT, 5, 1, 0), |
| 226 | }; |
| 227 | |
| 228 | static const struct snd_kcontrol_new ak4671_lout3_mixer_controls[] = { |
| 229 | SOC_DAPM_SINGLE("DACSL", AK4671_LOUT3_SIGNAL_SELECT, 0, 1, 0), |
| 230 | SOC_DAPM_SINGLE("LINS1", AK4671_LOUT3_SIGNAL_SELECT, 1, 1, 0), |
| 231 | SOC_DAPM_SINGLE("LINS2", AK4671_LOUT3_SIGNAL_SELECT, 2, 1, 0), |
| 232 | SOC_DAPM_SINGLE("LINS3", AK4671_LOUT3_SIGNAL_SELECT, 3, 1, 0), |
| 233 | SOC_DAPM_SINGLE("LINS4", AK4671_LOUT3_SIGNAL_SELECT, 4, 1, 0), |
| 234 | SOC_DAPM_SINGLE("LOOPSL", AK4671_LOUT3_SIGNAL_SELECT, 5, 1, 0), |
| 235 | }; |
| 236 | |
| 237 | static const struct snd_kcontrol_new ak4671_rout3_mixer_controls[] = { |
| 238 | SOC_DAPM_SINGLE("DACSR", AK4671_ROUT3_SIGNAL_SELECT, 0, 1, 0), |
| 239 | SOC_DAPM_SINGLE("RINS1", AK4671_ROUT3_SIGNAL_SELECT, 1, 1, 0), |
| 240 | SOC_DAPM_SINGLE("RINS2", AK4671_ROUT3_SIGNAL_SELECT, 2, 1, 0), |
| 241 | SOC_DAPM_SINGLE("RINS3", AK4671_ROUT3_SIGNAL_SELECT, 3, 1, 0), |
| 242 | SOC_DAPM_SINGLE("RINS4", AK4671_ROUT3_SIGNAL_SELECT, 4, 1, 0), |
| 243 | SOC_DAPM_SINGLE("LOOPSR", AK4671_ROUT3_SIGNAL_SELECT, 5, 1, 0), |
| 244 | }; |
| 245 | |
| 246 | /* Input MUXs */ |
| 247 | static const char *ak4671_lin_mux_texts[] = |
| 248 | {"LIN1", "LIN2", "LIN3", "LIN4"}; |
| 249 | static const struct soc_enum ak4671_lin_mux_enum = |
| 250 | SOC_ENUM_SINGLE(AK4671_MIC_SIGNAL_SELECT, 0, |
| 251 | ARRAY_SIZE(ak4671_lin_mux_texts), |
| 252 | ak4671_lin_mux_texts); |
| 253 | static const struct snd_kcontrol_new ak4671_lin_mux_control = |
| 254 | SOC_DAPM_ENUM("Route", ak4671_lin_mux_enum); |
| 255 | |
| 256 | static const char *ak4671_rin_mux_texts[] = |
| 257 | {"RIN1", "RIN2", "RIN3", "RIN4"}; |
| 258 | static const struct soc_enum ak4671_rin_mux_enum = |
| 259 | SOC_ENUM_SINGLE(AK4671_MIC_SIGNAL_SELECT, 2, |
| 260 | ARRAY_SIZE(ak4671_rin_mux_texts), |
| 261 | ak4671_rin_mux_texts); |
| 262 | static const struct snd_kcontrol_new ak4671_rin_mux_control = |
| 263 | SOC_DAPM_ENUM("Route", ak4671_rin_mux_enum); |
| 264 | |
| 265 | static const struct snd_soc_dapm_widget ak4671_dapm_widgets[] = { |
| 266 | /* Inputs */ |
| 267 | SND_SOC_DAPM_INPUT("LIN1"), |
| 268 | SND_SOC_DAPM_INPUT("RIN1"), |
| 269 | SND_SOC_DAPM_INPUT("LIN2"), |
| 270 | SND_SOC_DAPM_INPUT("RIN2"), |
| 271 | SND_SOC_DAPM_INPUT("LIN3"), |
| 272 | SND_SOC_DAPM_INPUT("RIN3"), |
| 273 | SND_SOC_DAPM_INPUT("LIN4"), |
| 274 | SND_SOC_DAPM_INPUT("RIN4"), |
| 275 | |
| 276 | /* Outputs */ |
| 277 | SND_SOC_DAPM_OUTPUT("LOUT1"), |
| 278 | SND_SOC_DAPM_OUTPUT("ROUT1"), |
| 279 | SND_SOC_DAPM_OUTPUT("LOUT2"), |
| 280 | SND_SOC_DAPM_OUTPUT("ROUT2"), |
| 281 | SND_SOC_DAPM_OUTPUT("LOUT3"), |
| 282 | SND_SOC_DAPM_OUTPUT("ROUT3"), |
| 283 | |
| 284 | /* DAC */ |
| 285 | SND_SOC_DAPM_DAC("DAC Left", "Left HiFi Playback", |
| 286 | AK4671_AD_DA_POWER_MANAGEMENT, 6, 0), |
| 287 | SND_SOC_DAPM_DAC("DAC Right", "Right HiFi Playback", |
| 288 | AK4671_AD_DA_POWER_MANAGEMENT, 7, 0), |
| 289 | |
| 290 | /* ADC */ |
| 291 | SND_SOC_DAPM_ADC("ADC Left", "Left HiFi Capture", |
| 292 | AK4671_AD_DA_POWER_MANAGEMENT, 4, 0), |
| 293 | SND_SOC_DAPM_ADC("ADC Right", "Right HiFi Capture", |
| 294 | AK4671_AD_DA_POWER_MANAGEMENT, 5, 0), |
| 295 | |
| 296 | /* PGA */ |
| 297 | SND_SOC_DAPM_PGA("LOUT2 Mix Amp", |
| 298 | AK4671_LOUT2_POWER_MANAGERMENT, 5, 0, NULL, 0), |
| 299 | SND_SOC_DAPM_PGA("ROUT2 Mix Amp", |
| 300 | AK4671_LOUT2_POWER_MANAGERMENT, 6, 0, NULL, 0), |
| 301 | |
| 302 | SND_SOC_DAPM_PGA("LIN1 Mixing Circuit", |
| 303 | AK4671_MIXING_POWER_MANAGEMENT1, 0, 0, NULL, 0), |
| 304 | SND_SOC_DAPM_PGA("RIN1 Mixing Circuit", |
| 305 | AK4671_MIXING_POWER_MANAGEMENT1, 1, 0, NULL, 0), |
| 306 | SND_SOC_DAPM_PGA("LIN2 Mixing Circuit", |
| 307 | AK4671_MIXING_POWER_MANAGEMENT1, 2, 0, NULL, 0), |
| 308 | SND_SOC_DAPM_PGA("RIN2 Mixing Circuit", |
| 309 | AK4671_MIXING_POWER_MANAGEMENT1, 3, 0, NULL, 0), |
| 310 | SND_SOC_DAPM_PGA("LIN3 Mixing Circuit", |
| 311 | AK4671_MIXING_POWER_MANAGEMENT1, 4, 0, NULL, 0), |
| 312 | SND_SOC_DAPM_PGA("RIN3 Mixing Circuit", |
| 313 | AK4671_MIXING_POWER_MANAGEMENT1, 5, 0, NULL, 0), |
| 314 | SND_SOC_DAPM_PGA("LIN4 Mixing Circuit", |
| 315 | AK4671_MIXING_POWER_MANAGEMENT1, 6, 0, NULL, 0), |
| 316 | SND_SOC_DAPM_PGA("RIN4 Mixing Circuit", |
| 317 | AK4671_MIXING_POWER_MANAGEMENT1, 7, 0, NULL, 0), |
| 318 | |
| 319 | /* Output Mixers */ |
| 320 | SND_SOC_DAPM_MIXER("LOUT1 Mixer", AK4671_LOUT1_POWER_MANAGERMENT, 0, 0, |
| 321 | &ak4671_lout1_mixer_controls[0], |
| 322 | ARRAY_SIZE(ak4671_lout1_mixer_controls)), |
| 323 | SND_SOC_DAPM_MIXER("ROUT1 Mixer", AK4671_LOUT1_POWER_MANAGERMENT, 1, 0, |
| 324 | &ak4671_rout1_mixer_controls[0], |
| 325 | ARRAY_SIZE(ak4671_rout1_mixer_controls)), |
| 326 | SND_SOC_DAPM_MIXER_E("LOUT2 Mixer", AK4671_LOUT2_POWER_MANAGERMENT, |
| 327 | 0, 0, &ak4671_lout2_mixer_controls[0], |
| 328 | ARRAY_SIZE(ak4671_lout2_mixer_controls), |
| 329 | ak4671_out2_event, |
| 330 | SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_PRE_PMD), |
| 331 | SND_SOC_DAPM_MIXER_E("ROUT2 Mixer", AK4671_LOUT2_POWER_MANAGERMENT, |
| 332 | 1, 0, &ak4671_rout2_mixer_controls[0], |
| 333 | ARRAY_SIZE(ak4671_rout2_mixer_controls), |
| 334 | ak4671_out2_event, |
| 335 | SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_PRE_PMD), |
| 336 | SND_SOC_DAPM_MIXER("LOUT3 Mixer", AK4671_LOUT3_POWER_MANAGERMENT, 0, 0, |
| 337 | &ak4671_lout3_mixer_controls[0], |
| 338 | ARRAY_SIZE(ak4671_lout3_mixer_controls)), |
| 339 | SND_SOC_DAPM_MIXER("ROUT3 Mixer", AK4671_LOUT3_POWER_MANAGERMENT, 1, 0, |
| 340 | &ak4671_rout3_mixer_controls[0], |
| 341 | ARRAY_SIZE(ak4671_rout3_mixer_controls)), |
| 342 | |
| 343 | /* Input MUXs */ |
| 344 | SND_SOC_DAPM_MUX("LIN MUX", AK4671_AD_DA_POWER_MANAGEMENT, 2, 0, |
| 345 | &ak4671_lin_mux_control), |
| 346 | SND_SOC_DAPM_MUX("RIN MUX", AK4671_AD_DA_POWER_MANAGEMENT, 3, 0, |
| 347 | &ak4671_rin_mux_control), |
| 348 | |
| 349 | /* Mic Power */ |
| 350 | SND_SOC_DAPM_MICBIAS("Mic Bias", AK4671_AD_DA_POWER_MANAGEMENT, 1, 0), |
| 351 | |
| 352 | /* Supply */ |
| 353 | SND_SOC_DAPM_SUPPLY("PMPLL", AK4671_PLL_MODE_SELECT1, 0, 0, NULL, 0), |
| 354 | }; |
| 355 | |
| 356 | static const struct snd_soc_dapm_route intercon[] = { |
| 357 | {"DAC Left", "NULL", "PMPLL"}, |
| 358 | {"DAC Right", "NULL", "PMPLL"}, |
| 359 | {"ADC Left", "NULL", "PMPLL"}, |
| 360 | {"ADC Right", "NULL", "PMPLL"}, |
| 361 | |
| 362 | /* Outputs */ |
| 363 | {"LOUT1", "NULL", "LOUT1 Mixer"}, |
| 364 | {"ROUT1", "NULL", "ROUT1 Mixer"}, |
| 365 | {"LOUT2", "NULL", "LOUT2 Mix Amp"}, |
| 366 | {"ROUT2", "NULL", "ROUT2 Mix Amp"}, |
| 367 | {"LOUT3", "NULL", "LOUT3 Mixer"}, |
| 368 | {"ROUT3", "NULL", "ROUT3 Mixer"}, |
| 369 | |
| 370 | {"LOUT1 Mixer", "DACL", "DAC Left"}, |
| 371 | {"ROUT1 Mixer", "DACR", "DAC Right"}, |
| 372 | {"LOUT2 Mixer", "DACHL", "DAC Left"}, |
| 373 | {"ROUT2 Mixer", "DACHR", "DAC Right"}, |
| 374 | {"LOUT2 Mix Amp", "NULL", "LOUT2 Mixer"}, |
| 375 | {"ROUT2 Mix Amp", "NULL", "ROUT2 Mixer"}, |
| 376 | {"LOUT3 Mixer", "DACSL", "DAC Left"}, |
| 377 | {"ROUT3 Mixer", "DACSR", "DAC Right"}, |
| 378 | |
| 379 | /* Inputs */ |
| 380 | {"LIN MUX", "LIN1", "LIN1"}, |
| 381 | {"LIN MUX", "LIN2", "LIN2"}, |
| 382 | {"LIN MUX", "LIN3", "LIN3"}, |
| 383 | {"LIN MUX", "LIN4", "LIN4"}, |
| 384 | |
| 385 | {"RIN MUX", "RIN1", "RIN1"}, |
| 386 | {"RIN MUX", "RIN2", "RIN2"}, |
| 387 | {"RIN MUX", "RIN3", "RIN3"}, |
| 388 | {"RIN MUX", "RIN4", "RIN4"}, |
| 389 | |
| 390 | {"LIN1", NULL, "Mic Bias"}, |
| 391 | {"RIN1", NULL, "Mic Bias"}, |
| 392 | {"LIN2", NULL, "Mic Bias"}, |
| 393 | {"RIN2", NULL, "Mic Bias"}, |
| 394 | |
| 395 | {"ADC Left", "NULL", "LIN MUX"}, |
| 396 | {"ADC Right", "NULL", "RIN MUX"}, |
| 397 | |
| 398 | /* Analog Loops */ |
| 399 | {"LIN1 Mixing Circuit", "NULL", "LIN1"}, |
| 400 | {"RIN1 Mixing Circuit", "NULL", "RIN1"}, |
| 401 | {"LIN2 Mixing Circuit", "NULL", "LIN2"}, |
| 402 | {"RIN2 Mixing Circuit", "NULL", "RIN2"}, |
| 403 | {"LIN3 Mixing Circuit", "NULL", "LIN3"}, |
| 404 | {"RIN3 Mixing Circuit", "NULL", "RIN3"}, |
| 405 | {"LIN4 Mixing Circuit", "NULL", "LIN4"}, |
| 406 | {"RIN4 Mixing Circuit", "NULL", "RIN4"}, |
| 407 | |
| 408 | {"LOUT1 Mixer", "LINL1", "LIN1 Mixing Circuit"}, |
| 409 | {"ROUT1 Mixer", "RINR1", "RIN1 Mixing Circuit"}, |
| 410 | {"LOUT2 Mixer", "LINH1", "LIN1 Mixing Circuit"}, |
| 411 | {"ROUT2 Mixer", "RINH1", "RIN1 Mixing Circuit"}, |
| 412 | {"LOUT3 Mixer", "LINS1", "LIN1 Mixing Circuit"}, |
| 413 | {"ROUT3 Mixer", "RINS1", "RIN1 Mixing Circuit"}, |
| 414 | |
| 415 | {"LOUT1 Mixer", "LINL2", "LIN2 Mixing Circuit"}, |
| 416 | {"ROUT1 Mixer", "RINR2", "RIN2 Mixing Circuit"}, |
| 417 | {"LOUT2 Mixer", "LINH2", "LIN2 Mixing Circuit"}, |
| 418 | {"ROUT2 Mixer", "RINH2", "RIN2 Mixing Circuit"}, |
| 419 | {"LOUT3 Mixer", "LINS2", "LIN2 Mixing Circuit"}, |
| 420 | {"ROUT3 Mixer", "RINS2", "RIN2 Mixing Circuit"}, |
| 421 | |
| 422 | {"LOUT1 Mixer", "LINL3", "LIN3 Mixing Circuit"}, |
| 423 | {"ROUT1 Mixer", "RINR3", "RIN3 Mixing Circuit"}, |
| 424 | {"LOUT2 Mixer", "LINH3", "LIN3 Mixing Circuit"}, |
| 425 | {"ROUT2 Mixer", "RINH3", "RIN3 Mixing Circuit"}, |
| 426 | {"LOUT3 Mixer", "LINS3", "LIN3 Mixing Circuit"}, |
| 427 | {"ROUT3 Mixer", "RINS3", "RIN3 Mixing Circuit"}, |
| 428 | |
| 429 | {"LOUT1 Mixer", "LINL4", "LIN4 Mixing Circuit"}, |
| 430 | {"ROUT1 Mixer", "RINR4", "RIN4 Mixing Circuit"}, |
| 431 | {"LOUT2 Mixer", "LINH4", "LIN4 Mixing Circuit"}, |
| 432 | {"ROUT2 Mixer", "RINH4", "RIN4 Mixing Circuit"}, |
| 433 | {"LOUT3 Mixer", "LINS4", "LIN4 Mixing Circuit"}, |
| 434 | {"ROUT3 Mixer", "RINS4", "RIN4 Mixing Circuit"}, |
| 435 | }; |
| 436 | |
| 437 | static int ak4671_add_widgets(struct snd_soc_codec *codec) |
| 438 | { |
| 439 | snd_soc_dapm_new_controls(codec, ak4671_dapm_widgets, |
| 440 | ARRAY_SIZE(ak4671_dapm_widgets)); |
| 441 | |
| 442 | snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); |
| 443 | |
Joonyoung Shim | 2312fd8 | 2009-09-10 00:12:43 +0900 | [diff] [blame] | 444 | return 0; |
| 445 | } |
| 446 | |
| 447 | static int ak4671_hw_params(struct snd_pcm_substream *substream, |
| 448 | struct snd_pcm_hw_params *params, |
| 449 | struct snd_soc_dai *dai) |
| 450 | { |
| 451 | struct snd_soc_codec *codec = dai->codec; |
| 452 | u8 fs; |
| 453 | |
| 454 | fs = snd_soc_read(codec, AK4671_PLL_MODE_SELECT0); |
| 455 | fs &= ~AK4671_FS; |
| 456 | |
| 457 | switch (params_rate(params)) { |
| 458 | case 8000: |
| 459 | fs |= AK4671_FS_8KHZ; |
| 460 | break; |
| 461 | case 12000: |
| 462 | fs |= AK4671_FS_12KHZ; |
| 463 | break; |
| 464 | case 16000: |
| 465 | fs |= AK4671_FS_16KHZ; |
| 466 | break; |
| 467 | case 24000: |
| 468 | fs |= AK4671_FS_24KHZ; |
| 469 | break; |
| 470 | case 11025: |
| 471 | fs |= AK4671_FS_11_025KHZ; |
| 472 | break; |
| 473 | case 22050: |
| 474 | fs |= AK4671_FS_22_05KHZ; |
| 475 | break; |
| 476 | case 32000: |
| 477 | fs |= AK4671_FS_32KHZ; |
| 478 | break; |
| 479 | case 44100: |
| 480 | fs |= AK4671_FS_44_1KHZ; |
| 481 | break; |
| 482 | case 48000: |
| 483 | fs |= AK4671_FS_48KHZ; |
| 484 | break; |
| 485 | default: |
| 486 | return -EINVAL; |
| 487 | } |
| 488 | |
| 489 | snd_soc_write(codec, AK4671_PLL_MODE_SELECT0, fs); |
| 490 | |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | static int ak4671_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, |
| 495 | unsigned int freq, int dir) |
| 496 | { |
| 497 | struct snd_soc_codec *codec = dai->codec; |
| 498 | u8 pll; |
| 499 | |
| 500 | pll = snd_soc_read(codec, AK4671_PLL_MODE_SELECT0); |
| 501 | pll &= ~AK4671_PLL; |
| 502 | |
| 503 | switch (freq) { |
| 504 | case 11289600: |
| 505 | pll |= AK4671_PLL_11_2896MHZ; |
| 506 | break; |
| 507 | case 12000000: |
| 508 | pll |= AK4671_PLL_12MHZ; |
| 509 | break; |
| 510 | case 12288000: |
| 511 | pll |= AK4671_PLL_12_288MHZ; |
| 512 | break; |
| 513 | case 13000000: |
| 514 | pll |= AK4671_PLL_13MHZ; |
| 515 | break; |
| 516 | case 13500000: |
| 517 | pll |= AK4671_PLL_13_5MHZ; |
| 518 | break; |
| 519 | case 19200000: |
| 520 | pll |= AK4671_PLL_19_2MHZ; |
| 521 | break; |
| 522 | case 24000000: |
| 523 | pll |= AK4671_PLL_24MHZ; |
| 524 | break; |
| 525 | case 26000000: |
| 526 | pll |= AK4671_PLL_26MHZ; |
| 527 | break; |
| 528 | case 27000000: |
| 529 | pll |= AK4671_PLL_27MHZ; |
| 530 | break; |
| 531 | default: |
| 532 | return -EINVAL; |
| 533 | } |
| 534 | |
| 535 | snd_soc_write(codec, AK4671_PLL_MODE_SELECT0, pll); |
| 536 | |
| 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | static int ak4671_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 541 | { |
| 542 | struct snd_soc_codec *codec = dai->codec; |
| 543 | u8 mode; |
| 544 | u8 format; |
| 545 | |
| 546 | /* set master/slave audio interface */ |
| 547 | mode = snd_soc_read(codec, AK4671_PLL_MODE_SELECT1); |
| 548 | |
| 549 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 550 | case SND_SOC_DAIFMT_CBM_CFM: |
| 551 | mode |= AK4671_M_S; |
| 552 | break; |
| 553 | case SND_SOC_DAIFMT_CBM_CFS: |
| 554 | mode &= ~(AK4671_M_S); |
| 555 | break; |
| 556 | default: |
| 557 | return -EINVAL; |
| 558 | } |
| 559 | |
| 560 | /* interface format */ |
| 561 | format = snd_soc_read(codec, AK4671_FORMAT_SELECT); |
| 562 | format &= ~AK4671_DIF; |
| 563 | |
| 564 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 565 | case SND_SOC_DAIFMT_I2S: |
| 566 | format |= AK4671_DIF_I2S_MODE; |
| 567 | break; |
| 568 | case SND_SOC_DAIFMT_LEFT_J: |
| 569 | format |= AK4671_DIF_MSB_MODE; |
| 570 | break; |
| 571 | case SND_SOC_DAIFMT_DSP_A: |
| 572 | format |= AK4671_DIF_DSP_MODE; |
| 573 | format |= AK4671_BCKP; |
| 574 | format |= AK4671_MSBS; |
| 575 | break; |
| 576 | default: |
| 577 | return -EINVAL; |
| 578 | } |
| 579 | |
| 580 | /* set mode and format */ |
| 581 | snd_soc_write(codec, AK4671_PLL_MODE_SELECT1, mode); |
| 582 | snd_soc_write(codec, AK4671_FORMAT_SELECT, format); |
| 583 | |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | static int ak4671_set_bias_level(struct snd_soc_codec *codec, |
| 588 | enum snd_soc_bias_level level) |
| 589 | { |
| 590 | u8 reg; |
| 591 | |
| 592 | switch (level) { |
| 593 | case SND_SOC_BIAS_ON: |
| 594 | case SND_SOC_BIAS_PREPARE: |
| 595 | case SND_SOC_BIAS_STANDBY: |
| 596 | reg = snd_soc_read(codec, AK4671_AD_DA_POWER_MANAGEMENT); |
| 597 | snd_soc_write(codec, AK4671_AD_DA_POWER_MANAGEMENT, |
| 598 | reg | AK4671_PMVCM); |
| 599 | break; |
| 600 | case SND_SOC_BIAS_OFF: |
| 601 | snd_soc_write(codec, AK4671_AD_DA_POWER_MANAGEMENT, 0x00); |
| 602 | break; |
| 603 | } |
| 604 | codec->bias_level = level; |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | #define AK4671_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ |
| 609 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\ |
| 610 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\ |
| 611 | SNDRV_PCM_RATE_48000) |
| 612 | |
| 613 | #define AK4671_FORMATS SNDRV_PCM_FMTBIT_S16_LE |
| 614 | |
| 615 | static struct snd_soc_dai_ops ak4671_dai_ops = { |
| 616 | .hw_params = ak4671_hw_params, |
| 617 | .set_sysclk = ak4671_set_dai_sysclk, |
| 618 | .set_fmt = ak4671_set_dai_fmt, |
| 619 | }; |
| 620 | |
| 621 | struct snd_soc_dai ak4671_dai = { |
| 622 | .name = "AK4671", |
| 623 | .playback = { |
| 624 | .stream_name = "Playback", |
| 625 | .channels_min = 1, |
| 626 | .channels_max = 2, |
| 627 | .rates = AK4671_RATES, |
| 628 | .formats = AK4671_FORMATS,}, |
| 629 | .capture = { |
| 630 | .stream_name = "Capture", |
| 631 | .channels_min = 1, |
| 632 | .channels_max = 2, |
| 633 | .rates = AK4671_RATES, |
| 634 | .formats = AK4671_FORMATS,}, |
| 635 | .ops = &ak4671_dai_ops, |
| 636 | }; |
| 637 | EXPORT_SYMBOL_GPL(ak4671_dai); |
| 638 | |
| 639 | static int ak4671_probe(struct platform_device *pdev) |
| 640 | { |
| 641 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 642 | struct snd_soc_codec *codec; |
| 643 | int ret = 0; |
| 644 | |
| 645 | if (ak4671_codec == NULL) { |
| 646 | dev_err(&pdev->dev, "Codec device not registered\n"); |
| 647 | return -ENODEV; |
| 648 | } |
| 649 | |
| 650 | socdev->card->codec = ak4671_codec; |
| 651 | codec = ak4671_codec; |
| 652 | |
| 653 | /* register pcms */ |
| 654 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); |
| 655 | if (ret < 0) { |
| 656 | dev_err(codec->dev, "failed to create pcms: %d\n", ret); |
| 657 | goto pcm_err; |
| 658 | } |
| 659 | |
| 660 | snd_soc_add_controls(codec, ak4671_snd_controls, |
| 661 | ARRAY_SIZE(ak4671_snd_controls)); |
| 662 | ak4671_add_widgets(codec); |
| 663 | |
Joonyoung Shim | 2312fd8 | 2009-09-10 00:12:43 +0900 | [diff] [blame] | 664 | ak4671_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
| 665 | |
| 666 | return ret; |
| 667 | |
Joonyoung Shim | 2312fd8 | 2009-09-10 00:12:43 +0900 | [diff] [blame] | 668 | pcm_err: |
| 669 | return ret; |
| 670 | } |
| 671 | |
| 672 | static int ak4671_remove(struct platform_device *pdev) |
| 673 | { |
| 674 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 675 | |
| 676 | snd_soc_free_pcms(socdev); |
| 677 | snd_soc_dapm_free(socdev); |
| 678 | |
| 679 | return 0; |
| 680 | } |
| 681 | |
| 682 | struct snd_soc_codec_device soc_codec_dev_ak4671 = { |
| 683 | .probe = ak4671_probe, |
| 684 | .remove = ak4671_remove, |
| 685 | }; |
| 686 | EXPORT_SYMBOL_GPL(soc_codec_dev_ak4671); |
| 687 | |
| 688 | static int ak4671_register(struct ak4671_priv *ak4671, |
| 689 | enum snd_soc_control_type control) |
| 690 | { |
| 691 | int ret; |
| 692 | struct snd_soc_codec *codec = &ak4671->codec; |
| 693 | |
| 694 | if (ak4671_codec) { |
| 695 | dev_err(codec->dev, "Another AK4671 is registered\n"); |
| 696 | ret = -EINVAL; |
| 697 | goto err; |
| 698 | } |
| 699 | |
| 700 | mutex_init(&codec->mutex); |
| 701 | INIT_LIST_HEAD(&codec->dapm_widgets); |
| 702 | INIT_LIST_HEAD(&codec->dapm_paths); |
| 703 | |
| 704 | codec->private_data = ak4671; |
| 705 | codec->name = "AK4671"; |
| 706 | codec->owner = THIS_MODULE; |
| 707 | codec->bias_level = SND_SOC_BIAS_OFF; |
| 708 | codec->set_bias_level = ak4671_set_bias_level; |
| 709 | codec->dai = &ak4671_dai; |
| 710 | codec->num_dai = 1; |
| 711 | codec->reg_cache_size = AK4671_CACHEREGNUM; |
| 712 | codec->reg_cache = &ak4671->reg_cache; |
| 713 | |
| 714 | memcpy(codec->reg_cache, ak4671_reg, sizeof(ak4671_reg)); |
| 715 | |
| 716 | ret = snd_soc_codec_set_cache_io(codec, 8, 8, control); |
| 717 | if (ret < 0) { |
| 718 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
| 719 | goto err; |
| 720 | } |
| 721 | |
| 722 | ak4671_dai.dev = codec->dev; |
| 723 | ak4671_codec = codec; |
| 724 | |
| 725 | ret = snd_soc_register_codec(codec); |
| 726 | if (ret != 0) { |
| 727 | dev_err(codec->dev, "Failed to register codec: %d\n", ret); |
| 728 | goto err; |
| 729 | } |
| 730 | |
| 731 | ret = snd_soc_register_dai(&ak4671_dai); |
| 732 | if (ret != 0) { |
| 733 | dev_err(codec->dev, "Failed to register DAI: %d\n", ret); |
| 734 | goto err_codec; |
| 735 | } |
| 736 | |
| 737 | return 0; |
| 738 | |
| 739 | err_codec: |
| 740 | snd_soc_unregister_codec(codec); |
| 741 | err: |
| 742 | kfree(ak4671); |
| 743 | return ret; |
| 744 | } |
| 745 | |
| 746 | static void ak4671_unregister(struct ak4671_priv *ak4671) |
| 747 | { |
| 748 | ak4671_set_bias_level(&ak4671->codec, SND_SOC_BIAS_OFF); |
| 749 | snd_soc_unregister_dai(&ak4671_dai); |
| 750 | snd_soc_unregister_codec(&ak4671->codec); |
| 751 | kfree(ak4671); |
| 752 | ak4671_codec = NULL; |
| 753 | } |
| 754 | |
| 755 | static int __devinit ak4671_i2c_probe(struct i2c_client *client, |
| 756 | const struct i2c_device_id *id) |
| 757 | { |
| 758 | struct ak4671_priv *ak4671; |
| 759 | struct snd_soc_codec *codec; |
| 760 | |
| 761 | ak4671 = kzalloc(sizeof(struct ak4671_priv), GFP_KERNEL); |
| 762 | if (ak4671 == NULL) |
| 763 | return -ENOMEM; |
| 764 | |
| 765 | codec = &ak4671->codec; |
| 766 | codec->hw_write = (hw_write_t)i2c_master_send; |
| 767 | |
| 768 | i2c_set_clientdata(client, ak4671); |
| 769 | codec->control_data = client; |
| 770 | |
| 771 | codec->dev = &client->dev; |
| 772 | |
| 773 | return ak4671_register(ak4671, SND_SOC_I2C); |
| 774 | } |
| 775 | |
| 776 | static __devexit int ak4671_i2c_remove(struct i2c_client *client) |
| 777 | { |
| 778 | struct ak4671_priv *ak4671 = i2c_get_clientdata(client); |
| 779 | |
| 780 | ak4671_unregister(ak4671); |
| 781 | |
| 782 | return 0; |
| 783 | } |
| 784 | |
| 785 | static const struct i2c_device_id ak4671_i2c_id[] = { |
| 786 | { "ak4671", 0 }, |
| 787 | { } |
| 788 | }; |
| 789 | MODULE_DEVICE_TABLE(i2c, ak4671_i2c_id); |
| 790 | |
| 791 | static struct i2c_driver ak4671_i2c_driver = { |
| 792 | .driver = { |
| 793 | .name = "ak4671", |
| 794 | .owner = THIS_MODULE, |
| 795 | }, |
| 796 | .probe = ak4671_i2c_probe, |
| 797 | .remove = __devexit_p(ak4671_i2c_remove), |
| 798 | .id_table = ak4671_i2c_id, |
| 799 | }; |
| 800 | |
| 801 | static int __init ak4671_modinit(void) |
| 802 | { |
| 803 | return i2c_add_driver(&ak4671_i2c_driver); |
| 804 | } |
| 805 | module_init(ak4671_modinit); |
| 806 | |
| 807 | static void __exit ak4671_exit(void) |
| 808 | { |
| 809 | i2c_del_driver(&ak4671_i2c_driver); |
| 810 | } |
| 811 | module_exit(ak4671_exit); |
| 812 | |
| 813 | MODULE_DESCRIPTION("ASoC AK4671 codec driver"); |
| 814 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); |
| 815 | MODULE_LICENSE("GPL"); |