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