Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Universal Interface for Intel High Definition Audio Codec |
| 3 | * |
| 4 | * HD audio interface patch for Silicon Labs 3054/5 modem codec |
| 5 | * |
Sasha Khapyorsky | f01cc52 | 2005-10-10 11:45:31 +0200 | [diff] [blame] | 6 | * Copyright (c) 2005 Sasha Khapyorsky <sashak@alsa-project.org> |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 7 | * Takashi Iwai <tiwai@suse.de> |
| 8 | * |
| 9 | * |
| 10 | * This driver is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This driver is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | */ |
| 24 | |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 25 | #include <linux/init.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/slab.h> |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 28 | #include <sound/core.h> |
| 29 | #include "hda_codec.h" |
| 30 | #include "hda_local.h" |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 31 | |
| 32 | /* si3054 verbs */ |
| 33 | #define SI3054_VERB_READ_NODE 0x900 |
| 34 | #define SI3054_VERB_WRITE_NODE 0x100 |
| 35 | |
| 36 | /* si3054 nodes (registers) */ |
| 37 | #define SI3054_EXTENDED_MID 2 |
| 38 | #define SI3054_LINE_RATE 3 |
| 39 | #define SI3054_LINE_LEVEL 4 |
| 40 | #define SI3054_GPIO_CFG 5 |
| 41 | #define SI3054_GPIO_POLARITY 6 |
| 42 | #define SI3054_GPIO_STICKY 7 |
| 43 | #define SI3054_GPIO_WAKEUP 8 |
| 44 | #define SI3054_GPIO_STATUS 9 |
| 45 | #define SI3054_GPIO_CONTROL 10 |
| 46 | #define SI3054_MISC_AFE 11 |
| 47 | #define SI3054_CHIPID 12 |
| 48 | #define SI3054_LINE_CFG1 13 |
| 49 | #define SI3054_LINE_STATUS 14 |
| 50 | #define SI3054_DC_TERMINATION 15 |
| 51 | #define SI3054_LINE_CONFIG 16 |
| 52 | #define SI3054_CALLPROG_ATT 17 |
| 53 | #define SI3054_SQ_CONTROL 18 |
| 54 | #define SI3054_MISC_CONTROL 19 |
| 55 | #define SI3054_RING_CTRL1 20 |
| 56 | #define SI3054_RING_CTRL2 21 |
| 57 | |
| 58 | /* extended MID */ |
| 59 | #define SI3054_MEI_READY 0xf |
| 60 | |
| 61 | /* line level */ |
| 62 | #define SI3054_ATAG_MASK 0x00f0 |
| 63 | #define SI3054_DTAG_MASK 0xf000 |
| 64 | |
| 65 | /* GPIO bits */ |
| 66 | #define SI3054_GPIO_OH 0x0001 |
| 67 | #define SI3054_GPIO_CID 0x0002 |
| 68 | |
| 69 | /* chipid and revisions */ |
| 70 | #define SI3054_CHIPID_CODEC_REV_MASK 0x000f |
| 71 | #define SI3054_CHIPID_DAA_REV_MASK 0x00f0 |
| 72 | #define SI3054_CHIPID_INTERNATIONAL 0x0100 |
| 73 | #define SI3054_CHIPID_DAA_ID 0x0f00 |
| 74 | #define SI3054_CHIPID_CODEC_ID (1<<12) |
| 75 | |
| 76 | /* si3054 codec registers (nodes) access macros */ |
| 77 | #define GET_REG(codec,reg) (snd_hda_codec_read(codec,reg,0,SI3054_VERB_READ_NODE,0)) |
| 78 | #define SET_REG(codec,reg,val) (snd_hda_codec_write(codec,reg,0,SI3054_VERB_WRITE_NODE,val)) |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 79 | #define SET_REG_CACHE(codec,reg,val) \ |
| 80 | snd_hda_codec_write_cache(codec,reg,0,SI3054_VERB_WRITE_NODE,val) |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 81 | |
| 82 | |
| 83 | struct si3054_spec { |
| 84 | unsigned international; |
| 85 | struct hda_pcm pcm; |
| 86 | }; |
| 87 | |
| 88 | |
| 89 | /* |
| 90 | * Modem mixer |
| 91 | */ |
| 92 | |
| 93 | #define PRIVATE_VALUE(reg,mask) ((reg<<16)|(mask&0xffff)) |
| 94 | #define PRIVATE_REG(val) ((val>>16)&0xffff) |
| 95 | #define PRIVATE_MASK(val) (val&0xffff) |
| 96 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 97 | #define si3054_switch_info snd_ctl_boolean_mono_info |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 98 | |
Takashi Iwai | c8b6bf9b | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 99 | static int si3054_switch_get(struct snd_kcontrol *kcontrol, |
| 100 | struct snd_ctl_elem_value *uvalue) |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 101 | { |
| 102 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 103 | u16 reg = PRIVATE_REG(kcontrol->private_value); |
| 104 | u16 mask = PRIVATE_MASK(kcontrol->private_value); |
| 105 | uvalue->value.integer.value[0] = (GET_REG(codec, reg)) & mask ? 1 : 0 ; |
| 106 | return 0; |
| 107 | } |
| 108 | |
Takashi Iwai | c8b6bf9b | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 109 | static int si3054_switch_put(struct snd_kcontrol *kcontrol, |
| 110 | struct snd_ctl_elem_value *uvalue) |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 111 | { |
| 112 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 113 | u16 reg = PRIVATE_REG(kcontrol->private_value); |
| 114 | u16 mask = PRIVATE_MASK(kcontrol->private_value); |
| 115 | if (uvalue->value.integer.value[0]) |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 116 | SET_REG_CACHE(codec, reg, (GET_REG(codec, reg)) | mask); |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 117 | else |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 118 | SET_REG_CACHE(codec, reg, (GET_REG(codec, reg)) & ~mask); |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | #define SI3054_KCONTROL(kname,reg,mask) { \ |
| 123 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 124 | .name = kname, \ |
| 125 | .info = si3054_switch_info, \ |
| 126 | .get = si3054_switch_get, \ |
| 127 | .put = si3054_switch_put, \ |
| 128 | .private_value = PRIVATE_VALUE(reg,mask), \ |
| 129 | } |
| 130 | |
| 131 | |
Takashi Iwai | c8b6bf9b | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 132 | static struct snd_kcontrol_new si3054_modem_mixer[] = { |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 133 | SI3054_KCONTROL("Off-hook Switch", SI3054_GPIO_CONTROL, SI3054_GPIO_OH), |
| 134 | SI3054_KCONTROL("Caller ID Switch", SI3054_GPIO_CONTROL, SI3054_GPIO_CID), |
| 135 | {} |
| 136 | }; |
| 137 | |
| 138 | static int si3054_build_controls(struct hda_codec *codec) |
| 139 | { |
| 140 | return snd_hda_add_new_ctls(codec, si3054_modem_mixer); |
| 141 | } |
| 142 | |
| 143 | |
| 144 | /* |
| 145 | * PCM callbacks |
| 146 | */ |
| 147 | |
| 148 | static int si3054_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 149 | struct hda_codec *codec, |
| 150 | unsigned int stream_tag, |
| 151 | unsigned int format, |
Takashi Iwai | c8b6bf9b | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 152 | struct snd_pcm_substream *substream) |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 153 | { |
| 154 | u16 val; |
| 155 | |
| 156 | SET_REG(codec, SI3054_LINE_RATE, substream->runtime->rate); |
| 157 | val = GET_REG(codec, SI3054_LINE_LEVEL); |
| 158 | val &= 0xff << (8 * (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)); |
| 159 | val |= ((stream_tag & 0xf) << 4) << (8 * (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)); |
| 160 | SET_REG(codec, SI3054_LINE_LEVEL, val); |
| 161 | |
| 162 | snd_hda_codec_setup_stream(codec, hinfo->nid, |
| 163 | stream_tag, 0, format); |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | static int si3054_pcm_open(struct hda_pcm_stream *hinfo, |
| 168 | struct hda_codec *codec, |
Takashi Iwai | c8b6bf9b | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 169 | struct snd_pcm_substream *substream) |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 170 | { |
| 171 | static unsigned int rates[] = { 8000, 9600, 16000 }; |
Takashi Iwai | c8b6bf9b | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 172 | static struct snd_pcm_hw_constraint_list hw_constraints_rates = { |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 173 | .count = ARRAY_SIZE(rates), |
| 174 | .list = rates, |
| 175 | .mask = 0, |
| 176 | }; |
| 177 | substream->runtime->hw.period_bytes_min = 80; |
| 178 | return snd_pcm_hw_constraint_list(substream->runtime, 0, |
| 179 | SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates); |
| 180 | } |
| 181 | |
| 182 | |
| 183 | static struct hda_pcm_stream si3054_pcm = { |
| 184 | .substreams = 1, |
| 185 | .channels_min = 1, |
| 186 | .channels_max = 1, |
| 187 | .nid = 0x1, |
| 188 | .rates = SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_KNOT, |
| 189 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 190 | .maxbps = 16, |
| 191 | .ops = { |
| 192 | .open = si3054_pcm_open, |
| 193 | .prepare = si3054_pcm_prepare, |
| 194 | }, |
| 195 | }; |
| 196 | |
| 197 | |
| 198 | static int si3054_build_pcms(struct hda_codec *codec) |
| 199 | { |
| 200 | struct si3054_spec *spec = codec->spec; |
| 201 | struct hda_pcm *info = &spec->pcm; |
| 202 | si3054_pcm.nid = codec->mfg; |
| 203 | codec->num_pcms = 1; |
| 204 | codec->pcm_info = info; |
| 205 | info->name = "Si3054 Modem"; |
| 206 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = si3054_pcm; |
| 207 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = si3054_pcm; |
Takashi Iwai | 7ba72ba | 2008-02-06 14:03:20 +0100 | [diff] [blame] | 208 | info->pcm_type = HDA_PCM_TYPE_MODEM; |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | |
| 213 | /* |
| 214 | * Init part |
| 215 | */ |
| 216 | |
| 217 | static int si3054_init(struct hda_codec *codec) |
| 218 | { |
| 219 | struct si3054_spec *spec = codec->spec; |
| 220 | unsigned wait_count; |
| 221 | u16 val; |
| 222 | |
| 223 | snd_hda_codec_write(codec, AC_NODE_ROOT, 0, AC_VERB_SET_CODEC_RESET, 0); |
| 224 | snd_hda_codec_write(codec, codec->mfg, 0, AC_VERB_SET_STREAM_FORMAT, 0); |
| 225 | SET_REG(codec, SI3054_LINE_RATE, 9600); |
| 226 | SET_REG(codec, SI3054_LINE_LEVEL, SI3054_DTAG_MASK|SI3054_ATAG_MASK); |
| 227 | SET_REG(codec, SI3054_EXTENDED_MID, 0); |
| 228 | |
| 229 | wait_count = 10; |
| 230 | do { |
| 231 | msleep(2); |
| 232 | val = GET_REG(codec, SI3054_EXTENDED_MID); |
| 233 | } while ((val & SI3054_MEI_READY) != SI3054_MEI_READY && wait_count--); |
| 234 | |
| 235 | if((val&SI3054_MEI_READY) != SI3054_MEI_READY) { |
| 236 | snd_printk(KERN_ERR "si3054: cannot initialize. EXT MID = %04x\n", val); |
Takashi Iwai | 83af036 | 2006-10-10 20:01:01 +0200 | [diff] [blame] | 237 | /* let's pray that this is no fatal error */ |
| 238 | /* return -EACCES; */ |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | SET_REG(codec, SI3054_GPIO_POLARITY, 0xffff); |
| 242 | SET_REG(codec, SI3054_GPIO_CFG, 0x0); |
| 243 | SET_REG(codec, SI3054_MISC_AFE, 0); |
| 244 | SET_REG(codec, SI3054_LINE_CFG1,0x200); |
| 245 | |
| 246 | if((GET_REG(codec,SI3054_LINE_STATUS) & (1<<6)) == 0) { |
| 247 | snd_printd("Link Frame Detect(FDT) is not ready (line status: %04x)\n", |
| 248 | GET_REG(codec,SI3054_LINE_STATUS)); |
| 249 | } |
| 250 | |
| 251 | spec->international = GET_REG(codec, SI3054_CHIPID) & SI3054_CHIPID_INTERNATIONAL; |
| 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | static void si3054_free(struct hda_codec *codec) |
| 257 | { |
| 258 | kfree(codec->spec); |
| 259 | } |
| 260 | |
| 261 | |
| 262 | /* |
| 263 | */ |
| 264 | |
| 265 | static struct hda_codec_ops si3054_patch_ops = { |
| 266 | .build_controls = si3054_build_controls, |
| 267 | .build_pcms = si3054_build_pcms, |
| 268 | .init = si3054_init, |
| 269 | .free = si3054_free, |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 270 | }; |
| 271 | |
| 272 | static int patch_si3054(struct hda_codec *codec) |
| 273 | { |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 274 | struct si3054_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 275 | if (spec == NULL) |
| 276 | return -ENOMEM; |
| 277 | codec->spec = spec; |
| 278 | codec->patch_ops = si3054_patch_ops; |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | /* |
| 283 | * patch entries |
| 284 | */ |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 285 | static struct hda_codec_preset snd_hda_preset_si3054[] = { |
Daniel Mueller | 26741b5 | 2005-11-14 17:40:44 +0100 | [diff] [blame] | 286 | { .id = 0x163c3055, .name = "Si3054", .patch = patch_si3054 }, |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 287 | { .id = 0x163c3155, .name = "Si3054", .patch = patch_si3054 }, |
Sasha Khapyorsky | e061bf1 | 2006-01-23 15:24:16 +0100 | [diff] [blame] | 288 | { .id = 0x11c13026, .name = "Si3054", .patch = patch_si3054 }, |
Sasha Khapyorsky | 476d120 | 2006-09-26 15:27:38 +0200 | [diff] [blame] | 289 | { .id = 0x11c13055, .name = "Si3054", .patch = patch_si3054 }, |
| 290 | { .id = 0x11c13155, .name = "Si3054", .patch = patch_si3054 }, |
| 291 | { .id = 0x10573055, .name = "Si3054", .patch = patch_si3054 }, |
Takashi Iwai | 5720fdd | 2006-09-17 22:04:17 +0200 | [diff] [blame] | 292 | { .id = 0x10573057, .name = "Si3054", .patch = patch_si3054 }, |
Sasha Khapyorsky | 476d120 | 2006-09-26 15:27:38 +0200 | [diff] [blame] | 293 | { .id = 0x10573155, .name = "Si3054", .patch = patch_si3054 }, |
Claudio Matsuoka | be38114 | 2007-07-11 10:31:08 +0200 | [diff] [blame] | 294 | /* VIA HDA on Clevo m540 */ |
| 295 | { .id = 0x11063288, .name = "Si3054", .patch = patch_si3054 }, |
Christian Rothlaender | 3b54298 | 2007-05-18 16:55:26 +0200 | [diff] [blame] | 296 | /* Asus A8J Modem (SM56) */ |
| 297 | { .id = 0x15433155, .name = "Si3054", .patch = patch_si3054 }, |
Claudio Matsuoka | ef2ec0d | 2007-07-12 11:27:37 +0200 | [diff] [blame] | 298 | /* LG LW20 modem */ |
| 299 | { .id = 0x18540018, .name = "Si3054", .patch = patch_si3054 }, |
Sasha Khapyorsky | b65f824 | 2005-08-11 11:18:38 +0200 | [diff] [blame] | 300 | {} |
| 301 | }; |
| 302 | |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 303 | MODULE_ALIAS("snd-hda-codec-id:163c3055"); |
| 304 | MODULE_ALIAS("snd-hda-codec-id:163c3155"); |
| 305 | MODULE_ALIAS("snd-hda-codec-id:11c13026"); |
| 306 | MODULE_ALIAS("snd-hda-codec-id:11c13055"); |
| 307 | MODULE_ALIAS("snd-hda-codec-id:11c13155"); |
| 308 | MODULE_ALIAS("snd-hda-codec-id:10573055"); |
| 309 | MODULE_ALIAS("snd-hda-codec-id:10573057"); |
| 310 | MODULE_ALIAS("snd-hda-codec-id:10573155"); |
| 311 | MODULE_ALIAS("snd-hda-codec-id:11063288"); |
| 312 | MODULE_ALIAS("snd-hda-codec-id:15433155"); |
| 313 | MODULE_ALIAS("snd-hda-codec-id:18540018"); |
| 314 | |
| 315 | MODULE_LICENSE("GPL"); |
| 316 | MODULE_DESCRIPTION("Si3054 HD-audio modem codec"); |
| 317 | |
| 318 | static struct hda_codec_preset_list si3054_list = { |
| 319 | .preset = snd_hda_preset_si3054, |
| 320 | .owner = THIS_MODULE, |
| 321 | }; |
| 322 | |
| 323 | static int __init patch_si3054_init(void) |
| 324 | { |
| 325 | return snd_hda_add_codec_preset(&si3054_list); |
| 326 | } |
| 327 | |
| 328 | static void __exit patch_si3054_exit(void) |
| 329 | { |
| 330 | snd_hda_delete_codec_preset(&si3054_list); |
| 331 | } |
| 332 | |
| 333 | module_init(patch_si3054_init) |
| 334 | module_exit(patch_si3054_exit) |