Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * HD audio interface patch for Creative CA0132 chip |
| 3 | * |
| 4 | * Copyright (c) 2011, Creative Technology Ltd. |
| 5 | * |
| 6 | * Based on patch_ca0110.c |
| 7 | * Copyright (c) 2008 Takashi Iwai <tiwai@suse.de> |
| 8 | * |
| 9 | * This driver is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This driver is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/slab.h> |
| 27 | #include <linux/pci.h> |
| 28 | #include <linux/mutex.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 29 | #include <linux/module.h> |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 30 | #include <sound/core.h> |
| 31 | #include "hda_codec.h" |
| 32 | #include "hda_local.h" |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 33 | #include "hda_auto_parser.h" |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 34 | |
Ian Minett | bcd109c | 2012-09-20 20:29:14 -0700 | [diff] [blame^] | 35 | #include "ca0132_regs.h" |
| 36 | |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 37 | #define WIDGET_CHIP_CTRL 0x15 |
| 38 | #define WIDGET_DSP_CTRL 0x16 |
| 39 | |
| 40 | #define WUH_MEM_CONNID 10 |
| 41 | #define DSP_MEM_CONNID 16 |
| 42 | |
| 43 | enum hda_cmd_vendor_io { |
| 44 | /* for DspIO node */ |
| 45 | VENDOR_DSPIO_SCP_WRITE_DATA_LOW = 0x000, |
| 46 | VENDOR_DSPIO_SCP_WRITE_DATA_HIGH = 0x100, |
| 47 | |
| 48 | VENDOR_DSPIO_STATUS = 0xF01, |
| 49 | VENDOR_DSPIO_SCP_POST_READ_DATA = 0x702, |
| 50 | VENDOR_DSPIO_SCP_READ_DATA = 0xF02, |
| 51 | VENDOR_DSPIO_DSP_INIT = 0x703, |
| 52 | VENDOR_DSPIO_SCP_POST_COUNT_QUERY = 0x704, |
| 53 | VENDOR_DSPIO_SCP_READ_COUNT = 0xF04, |
| 54 | |
| 55 | /* for ChipIO node */ |
| 56 | VENDOR_CHIPIO_ADDRESS_LOW = 0x000, |
| 57 | VENDOR_CHIPIO_ADDRESS_HIGH = 0x100, |
| 58 | VENDOR_CHIPIO_STREAM_FORMAT = 0x200, |
| 59 | VENDOR_CHIPIO_DATA_LOW = 0x300, |
| 60 | VENDOR_CHIPIO_DATA_HIGH = 0x400, |
| 61 | |
| 62 | VENDOR_CHIPIO_GET_PARAMETER = 0xF00, |
| 63 | VENDOR_CHIPIO_STATUS = 0xF01, |
| 64 | VENDOR_CHIPIO_HIC_POST_READ = 0x702, |
| 65 | VENDOR_CHIPIO_HIC_READ_DATA = 0xF03, |
| 66 | |
| 67 | VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE = 0x70A, |
| 68 | |
| 69 | VENDOR_CHIPIO_PLL_PMU_WRITE = 0x70C, |
| 70 | VENDOR_CHIPIO_PLL_PMU_READ = 0xF0C, |
| 71 | VENDOR_CHIPIO_8051_ADDRESS_LOW = 0x70D, |
| 72 | VENDOR_CHIPIO_8051_ADDRESS_HIGH = 0x70E, |
| 73 | VENDOR_CHIPIO_FLAG_SET = 0x70F, |
| 74 | VENDOR_CHIPIO_FLAGS_GET = 0xF0F, |
| 75 | VENDOR_CHIPIO_PARAMETER_SET = 0x710, |
| 76 | VENDOR_CHIPIO_PARAMETER_GET = 0xF10, |
| 77 | |
| 78 | VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET = 0x711, |
| 79 | VENDOR_CHIPIO_PORT_ALLOC_SET = 0x712, |
| 80 | VENDOR_CHIPIO_PORT_ALLOC_GET = 0xF12, |
| 81 | VENDOR_CHIPIO_PORT_FREE_SET = 0x713, |
| 82 | |
| 83 | VENDOR_CHIPIO_PARAMETER_EX_ID_GET = 0xF17, |
| 84 | VENDOR_CHIPIO_PARAMETER_EX_ID_SET = 0x717, |
| 85 | VENDOR_CHIPIO_PARAMETER_EX_VALUE_GET = 0xF18, |
| 86 | VENDOR_CHIPIO_PARAMETER_EX_VALUE_SET = 0x718 |
| 87 | }; |
| 88 | |
| 89 | /* |
| 90 | * Control flag IDs |
| 91 | */ |
| 92 | enum control_flag_id { |
| 93 | /* Connection manager stream setup is bypassed/enabled */ |
| 94 | CONTROL_FLAG_C_MGR = 0, |
| 95 | /* DSP DMA is bypassed/enabled */ |
| 96 | CONTROL_FLAG_DMA = 1, |
| 97 | /* 8051 'idle' mode is disabled/enabled */ |
| 98 | CONTROL_FLAG_IDLE_ENABLE = 2, |
| 99 | /* Tracker for the SPDIF-in path is bypassed/enabled */ |
| 100 | CONTROL_FLAG_TRACKER = 3, |
| 101 | /* DigitalOut to Spdif2Out connection is disabled/enabled */ |
| 102 | CONTROL_FLAG_SPDIF2OUT = 4, |
| 103 | /* Digital Microphone is disabled/enabled */ |
| 104 | CONTROL_FLAG_DMIC = 5, |
| 105 | /* ADC_B rate is 48 kHz/96 kHz */ |
| 106 | CONTROL_FLAG_ADC_B_96KHZ = 6, |
| 107 | /* ADC_C rate is 48 kHz/96 kHz */ |
| 108 | CONTROL_FLAG_ADC_C_96KHZ = 7, |
| 109 | /* DAC rate is 48 kHz/96 kHz (affects all DACs) */ |
| 110 | CONTROL_FLAG_DAC_96KHZ = 8, |
| 111 | /* DSP rate is 48 kHz/96 kHz */ |
| 112 | CONTROL_FLAG_DSP_96KHZ = 9, |
| 113 | /* SRC clock is 98 MHz/196 MHz (196 MHz forces rate to 96 KHz) */ |
| 114 | CONTROL_FLAG_SRC_CLOCK_196MHZ = 10, |
| 115 | /* SRC rate is 48 kHz/96 kHz (48 kHz disabled when clock is 196 MHz) */ |
| 116 | CONTROL_FLAG_SRC_RATE_96KHZ = 11, |
| 117 | /* Decode Loop (DSP->SRC->DSP) is disabled/enabled */ |
| 118 | CONTROL_FLAG_DECODE_LOOP = 12, |
| 119 | /* De-emphasis filter on DAC-1 disabled/enabled */ |
| 120 | CONTROL_FLAG_DAC1_DEEMPHASIS = 13, |
| 121 | /* De-emphasis filter on DAC-2 disabled/enabled */ |
| 122 | CONTROL_FLAG_DAC2_DEEMPHASIS = 14, |
| 123 | /* De-emphasis filter on DAC-3 disabled/enabled */ |
| 124 | CONTROL_FLAG_DAC3_DEEMPHASIS = 15, |
| 125 | /* High-pass filter on ADC_B disabled/enabled */ |
| 126 | CONTROL_FLAG_ADC_B_HIGH_PASS = 16, |
| 127 | /* High-pass filter on ADC_C disabled/enabled */ |
| 128 | CONTROL_FLAG_ADC_C_HIGH_PASS = 17, |
| 129 | /* Common mode on Port_A disabled/enabled */ |
| 130 | CONTROL_FLAG_PORT_A_COMMON_MODE = 18, |
| 131 | /* Common mode on Port_D disabled/enabled */ |
| 132 | CONTROL_FLAG_PORT_D_COMMON_MODE = 19, |
| 133 | /* Impedance for ramp generator on Port_A 16 Ohm/10K Ohm */ |
| 134 | CONTROL_FLAG_PORT_A_10KOHM_LOAD = 20, |
| 135 | /* Impedance for ramp generator on Port_D, 16 Ohm/10K Ohm */ |
| 136 | CONTROL_FLAG_PORT_D_10K0HM_LOAD = 21, |
| 137 | /* ASI rate is 48kHz/96kHz */ |
| 138 | CONTROL_FLAG_ASI_96KHZ = 22, |
| 139 | /* DAC power settings able to control attached ports no/yes */ |
| 140 | CONTROL_FLAG_DACS_CONTROL_PORTS = 23, |
| 141 | /* Clock Stop OK reporting is disabled/enabled */ |
| 142 | CONTROL_FLAG_CONTROL_STOP_OK_ENABLE = 24, |
| 143 | /* Number of control flags */ |
| 144 | CONTROL_FLAGS_MAX = (CONTROL_FLAG_CONTROL_STOP_OK_ENABLE+1) |
| 145 | }; |
| 146 | |
| 147 | /* |
| 148 | * Control parameter IDs |
| 149 | */ |
| 150 | enum control_parameter_id { |
| 151 | /* 0: force HDA, 1: allow DSP if HDA Spdif1Out stream is idle */ |
| 152 | CONTROL_PARAM_SPDIF1_SOURCE = 2, |
| 153 | |
| 154 | /* Stream Control */ |
| 155 | |
| 156 | /* Select stream with the given ID */ |
| 157 | CONTROL_PARAM_STREAM_ID = 24, |
| 158 | /* Source connection point for the selected stream */ |
| 159 | CONTROL_PARAM_STREAM_SOURCE_CONN_POINT = 25, |
| 160 | /* Destination connection point for the selected stream */ |
| 161 | CONTROL_PARAM_STREAM_DEST_CONN_POINT = 26, |
| 162 | /* Number of audio channels in the selected stream */ |
| 163 | CONTROL_PARAM_STREAMS_CHANNELS = 27, |
| 164 | /*Enable control for the selected stream */ |
| 165 | CONTROL_PARAM_STREAM_CONTROL = 28, |
| 166 | |
| 167 | /* Connection Point Control */ |
| 168 | |
| 169 | /* Select connection point with the given ID */ |
| 170 | CONTROL_PARAM_CONN_POINT_ID = 29, |
| 171 | /* Connection point sample rate */ |
| 172 | CONTROL_PARAM_CONN_POINT_SAMPLE_RATE = 30, |
| 173 | |
| 174 | /* Node Control */ |
| 175 | |
| 176 | /* Select HDA node with the given ID */ |
| 177 | CONTROL_PARAM_NODE_ID = 31 |
| 178 | }; |
| 179 | |
| 180 | /* |
| 181 | * Dsp Io Status codes |
| 182 | */ |
| 183 | enum hda_vendor_status_dspio { |
| 184 | /* Success */ |
| 185 | VENDOR_STATUS_DSPIO_OK = 0x00, |
| 186 | /* Busy, unable to accept new command, the host must retry */ |
| 187 | VENDOR_STATUS_DSPIO_BUSY = 0x01, |
| 188 | /* SCP command queue is full */ |
| 189 | VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL = 0x02, |
| 190 | /* SCP response queue is empty */ |
| 191 | VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY = 0x03 |
| 192 | }; |
| 193 | |
| 194 | /* |
| 195 | * Chip Io Status codes |
| 196 | */ |
| 197 | enum hda_vendor_status_chipio { |
| 198 | /* Success */ |
| 199 | VENDOR_STATUS_CHIPIO_OK = 0x00, |
| 200 | /* Busy, unable to accept new command, the host must retry */ |
| 201 | VENDOR_STATUS_CHIPIO_BUSY = 0x01 |
| 202 | }; |
| 203 | |
| 204 | /* |
| 205 | * CA0132 sample rate |
| 206 | */ |
| 207 | enum ca0132_sample_rate { |
| 208 | SR_6_000 = 0x00, |
| 209 | SR_8_000 = 0x01, |
| 210 | SR_9_600 = 0x02, |
| 211 | SR_11_025 = 0x03, |
| 212 | SR_16_000 = 0x04, |
| 213 | SR_22_050 = 0x05, |
| 214 | SR_24_000 = 0x06, |
| 215 | SR_32_000 = 0x07, |
| 216 | SR_44_100 = 0x08, |
| 217 | SR_48_000 = 0x09, |
| 218 | SR_88_200 = 0x0A, |
| 219 | SR_96_000 = 0x0B, |
| 220 | SR_144_000 = 0x0C, |
| 221 | SR_176_400 = 0x0D, |
| 222 | SR_192_000 = 0x0E, |
| 223 | SR_384_000 = 0x0F, |
| 224 | |
| 225 | SR_COUNT = 0x10, |
| 226 | |
| 227 | SR_RATE_UNKNOWN = 0x1F |
| 228 | }; |
| 229 | |
| 230 | /* |
| 231 | * Scp Helper function |
| 232 | */ |
| 233 | enum get_set { |
| 234 | IS_SET = 0, |
| 235 | IS_GET = 1, |
| 236 | }; |
| 237 | |
| 238 | /* |
| 239 | * Duplicated from ca0110 codec |
| 240 | */ |
| 241 | |
| 242 | static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac) |
| 243 | { |
| 244 | if (pin) { |
Takashi Iwai | cdd03ce | 2012-04-20 12:34:50 +0200 | [diff] [blame] | 245 | snd_hda_set_pin_ctl(codec, pin, PIN_HP); |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 246 | if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP) |
| 247 | snd_hda_codec_write(codec, pin, 0, |
| 248 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 249 | AMP_OUT_UNMUTE); |
| 250 | } |
Takashi Iwai | 8e13fc1 | 2012-08-08 17:26:54 +0200 | [diff] [blame] | 251 | if (dac && (get_wcaps(codec, dac) & AC_WCAP_OUT_AMP)) |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 252 | snd_hda_codec_write(codec, dac, 0, |
| 253 | AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO); |
| 254 | } |
| 255 | |
| 256 | static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc) |
| 257 | { |
| 258 | if (pin) { |
Takashi Iwai | 4740860 | 2012-04-20 13:06:53 +0200 | [diff] [blame] | 259 | snd_hda_set_pin_ctl(codec, pin, PIN_IN | |
| 260 | snd_hda_get_default_vref(codec, pin)); |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 261 | if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP) |
| 262 | snd_hda_codec_write(codec, pin, 0, |
| 263 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 264 | AMP_IN_UNMUTE(0)); |
| 265 | } |
Takashi Iwai | 8e13fc1 | 2012-08-08 17:26:54 +0200 | [diff] [blame] | 266 | if (adc && (get_wcaps(codec, adc) & AC_WCAP_IN_AMP)) |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 267 | snd_hda_codec_write(codec, adc, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 268 | AMP_IN_UNMUTE(0)); |
| 269 | } |
| 270 | |
| 271 | static char *dirstr[2] = { "Playback", "Capture" }; |
| 272 | |
| 273 | static int _add_switch(struct hda_codec *codec, hda_nid_t nid, const char *pfx, |
| 274 | int chan, int dir) |
| 275 | { |
| 276 | char namestr[44]; |
| 277 | int type = dir ? HDA_INPUT : HDA_OUTPUT; |
| 278 | struct snd_kcontrol_new knew = |
| 279 | HDA_CODEC_MUTE_MONO(namestr, nid, chan, 0, type); |
David Henningsson | c41999a | 2012-08-20 11:17:00 +0200 | [diff] [blame] | 280 | if ((query_amp_caps(codec, nid, type) & AC_AMPCAP_MUTE) == 0) { |
| 281 | snd_printdd("Skipping '%s %s Switch' (no mute on node 0x%x)\n", pfx, dirstr[dir], nid); |
| 282 | return 0; |
| 283 | } |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 284 | sprintf(namestr, "%s %s Switch", pfx, dirstr[dir]); |
| 285 | return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec)); |
| 286 | } |
| 287 | |
| 288 | static int _add_volume(struct hda_codec *codec, hda_nid_t nid, const char *pfx, |
| 289 | int chan, int dir) |
| 290 | { |
| 291 | char namestr[44]; |
| 292 | int type = dir ? HDA_INPUT : HDA_OUTPUT; |
| 293 | struct snd_kcontrol_new knew = |
| 294 | HDA_CODEC_VOLUME_MONO(namestr, nid, chan, 0, type); |
David Henningsson | c41999a | 2012-08-20 11:17:00 +0200 | [diff] [blame] | 295 | if ((query_amp_caps(codec, nid, type) & AC_AMPCAP_NUM_STEPS) == 0) { |
| 296 | snd_printdd("Skipping '%s %s Volume' (no amp on node 0x%x)\n", pfx, dirstr[dir], nid); |
| 297 | return 0; |
| 298 | } |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 299 | sprintf(namestr, "%s %s Volume", pfx, dirstr[dir]); |
| 300 | return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec)); |
| 301 | } |
| 302 | |
| 303 | #define add_out_switch(codec, nid, pfx) _add_switch(codec, nid, pfx, 3, 0) |
| 304 | #define add_out_volume(codec, nid, pfx) _add_volume(codec, nid, pfx, 3, 0) |
| 305 | #define add_in_switch(codec, nid, pfx) _add_switch(codec, nid, pfx, 3, 1) |
| 306 | #define add_in_volume(codec, nid, pfx) _add_volume(codec, nid, pfx, 3, 1) |
| 307 | #define add_mono_switch(codec, nid, pfx, chan) \ |
| 308 | _add_switch(codec, nid, pfx, chan, 0) |
| 309 | #define add_mono_volume(codec, nid, pfx, chan) \ |
| 310 | _add_volume(codec, nid, pfx, chan, 0) |
| 311 | #define add_in_mono_switch(codec, nid, pfx, chan) \ |
| 312 | _add_switch(codec, nid, pfx, chan, 1) |
| 313 | #define add_in_mono_volume(codec, nid, pfx, chan) \ |
| 314 | _add_volume(codec, nid, pfx, chan, 1) |
| 315 | |
| 316 | |
| 317 | /* |
| 318 | * CA0132 specific |
| 319 | */ |
| 320 | |
| 321 | struct ca0132_spec { |
| 322 | struct auto_pin_cfg autocfg; |
| 323 | struct hda_multi_out multiout; |
| 324 | hda_nid_t out_pins[AUTO_CFG_MAX_OUTS]; |
| 325 | hda_nid_t dacs[AUTO_CFG_MAX_OUTS]; |
| 326 | hda_nid_t hp_dac; |
| 327 | hda_nid_t input_pins[AUTO_PIN_LAST]; |
| 328 | hda_nid_t adcs[AUTO_PIN_LAST]; |
| 329 | hda_nid_t dig_out; |
| 330 | hda_nid_t dig_in; |
| 331 | unsigned int num_inputs; |
| 332 | long curr_hp_switch; |
| 333 | long curr_hp_volume[2]; |
| 334 | long curr_speaker_switch; |
| 335 | struct mutex chipio_mutex; |
| 336 | const char *input_labels[AUTO_PIN_LAST]; |
| 337 | struct hda_pcm pcm_rec[2]; /* PCM information */ |
| 338 | }; |
| 339 | |
| 340 | /* Chip access helper function */ |
| 341 | static int chipio_send(struct hda_codec *codec, |
| 342 | unsigned int reg, |
| 343 | unsigned int data) |
| 344 | { |
| 345 | unsigned int res; |
| 346 | int retry = 50; |
| 347 | |
| 348 | /* send bits of data specified by reg */ |
| 349 | do { |
| 350 | res = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0, |
| 351 | reg, data); |
| 352 | if (res == VENDOR_STATUS_CHIPIO_OK) |
| 353 | return 0; |
| 354 | } while (--retry); |
| 355 | return -EIO; |
| 356 | } |
| 357 | |
| 358 | /* |
| 359 | * Write chip address through the vendor widget -- NOT protected by the Mutex! |
| 360 | */ |
| 361 | static int chipio_write_address(struct hda_codec *codec, |
| 362 | unsigned int chip_addx) |
| 363 | { |
| 364 | int res; |
| 365 | |
| 366 | /* send low 16 bits of the address */ |
| 367 | res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_LOW, |
| 368 | chip_addx & 0xffff); |
| 369 | |
| 370 | if (res != -EIO) { |
| 371 | /* send high 16 bits of the address */ |
| 372 | res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_HIGH, |
| 373 | chip_addx >> 16); |
| 374 | } |
| 375 | |
| 376 | return res; |
| 377 | } |
| 378 | |
| 379 | /* |
| 380 | * Write data through the vendor widget -- NOT protected by the Mutex! |
| 381 | */ |
| 382 | |
| 383 | static int chipio_write_data(struct hda_codec *codec, unsigned int data) |
| 384 | { |
| 385 | int res; |
| 386 | |
| 387 | /* send low 16 bits of the data */ |
| 388 | res = chipio_send(codec, VENDOR_CHIPIO_DATA_LOW, data & 0xffff); |
| 389 | |
| 390 | if (res != -EIO) { |
| 391 | /* send high 16 bits of the data */ |
| 392 | res = chipio_send(codec, VENDOR_CHIPIO_DATA_HIGH, |
| 393 | data >> 16); |
| 394 | } |
| 395 | |
| 396 | return res; |
| 397 | } |
| 398 | |
| 399 | /* |
| 400 | * Read data through the vendor widget -- NOT protected by the Mutex! |
| 401 | */ |
| 402 | static int chipio_read_data(struct hda_codec *codec, unsigned int *data) |
| 403 | { |
| 404 | int res; |
| 405 | |
| 406 | /* post read */ |
| 407 | res = chipio_send(codec, VENDOR_CHIPIO_HIC_POST_READ, 0); |
| 408 | |
| 409 | if (res != -EIO) { |
| 410 | /* read status */ |
| 411 | res = chipio_send(codec, VENDOR_CHIPIO_STATUS, 0); |
| 412 | } |
| 413 | |
| 414 | if (res != -EIO) { |
| 415 | /* read data */ |
| 416 | *data = snd_hda_codec_read(codec, WIDGET_CHIP_CTRL, 0, |
| 417 | VENDOR_CHIPIO_HIC_READ_DATA, |
| 418 | 0); |
| 419 | } |
| 420 | |
| 421 | return res; |
| 422 | } |
| 423 | |
| 424 | /* |
| 425 | * Write given value to the given address through the chip I/O widget. |
| 426 | * protected by the Mutex |
| 427 | */ |
| 428 | static int chipio_write(struct hda_codec *codec, |
| 429 | unsigned int chip_addx, const unsigned int data) |
| 430 | { |
| 431 | struct ca0132_spec *spec = codec->spec; |
| 432 | int err; |
| 433 | |
| 434 | mutex_lock(&spec->chipio_mutex); |
| 435 | |
| 436 | /* write the address, and if successful proceed to write data */ |
| 437 | err = chipio_write_address(codec, chip_addx); |
| 438 | if (err < 0) |
| 439 | goto exit; |
| 440 | |
| 441 | err = chipio_write_data(codec, data); |
| 442 | if (err < 0) |
| 443 | goto exit; |
| 444 | |
| 445 | exit: |
| 446 | mutex_unlock(&spec->chipio_mutex); |
| 447 | return err; |
| 448 | } |
| 449 | |
| 450 | /* |
| 451 | * Read the given address through the chip I/O widget |
| 452 | * protected by the Mutex |
| 453 | */ |
| 454 | static int chipio_read(struct hda_codec *codec, |
| 455 | unsigned int chip_addx, unsigned int *data) |
| 456 | { |
| 457 | struct ca0132_spec *spec = codec->spec; |
| 458 | int err; |
| 459 | |
| 460 | mutex_lock(&spec->chipio_mutex); |
| 461 | |
| 462 | /* write the address, and if successful proceed to write data */ |
| 463 | err = chipio_write_address(codec, chip_addx); |
| 464 | if (err < 0) |
| 465 | goto exit; |
| 466 | |
| 467 | err = chipio_read_data(codec, data); |
| 468 | if (err < 0) |
| 469 | goto exit; |
| 470 | |
| 471 | exit: |
| 472 | mutex_unlock(&spec->chipio_mutex); |
| 473 | return err; |
| 474 | } |
| 475 | |
| 476 | /* |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 477 | * PCM callbacks |
| 478 | */ |
Takashi Iwai | 27ebeb0 | 2012-08-08 17:20:18 +0200 | [diff] [blame] | 479 | static int ca0132_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 480 | struct hda_codec *codec, |
| 481 | struct snd_pcm_substream *substream) |
| 482 | { |
| 483 | struct ca0132_spec *spec = codec->spec; |
| 484 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
| 485 | hinfo); |
| 486 | } |
| 487 | |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 488 | static int ca0132_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 489 | struct hda_codec *codec, |
| 490 | unsigned int stream_tag, |
| 491 | unsigned int format, |
| 492 | struct snd_pcm_substream *substream) |
| 493 | { |
| 494 | struct ca0132_spec *spec = codec->spec; |
Takashi Iwai | 27ebeb0 | 2012-08-08 17:20:18 +0200 | [diff] [blame] | 495 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, |
| 496 | stream_tag, format, substream); |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 500 | struct hda_codec *codec, |
| 501 | struct snd_pcm_substream *substream) |
| 502 | { |
| 503 | struct ca0132_spec *spec = codec->spec; |
Takashi Iwai | 27ebeb0 | 2012-08-08 17:20:18 +0200 | [diff] [blame] | 504 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | /* |
| 508 | * Digital out |
| 509 | */ |
Takashi Iwai | 27ebeb0 | 2012-08-08 17:20:18 +0200 | [diff] [blame] | 510 | static int ca0132_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 511 | struct hda_codec *codec, |
| 512 | struct snd_pcm_substream *substream) |
| 513 | { |
| 514 | struct ca0132_spec *spec = codec->spec; |
| 515 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 516 | } |
| 517 | |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 518 | static int ca0132_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 519 | struct hda_codec *codec, |
| 520 | unsigned int stream_tag, |
| 521 | unsigned int format, |
| 522 | struct snd_pcm_substream *substream) |
| 523 | { |
| 524 | struct ca0132_spec *spec = codec->spec; |
Takashi Iwai | 27ebeb0 | 2012-08-08 17:20:18 +0200 | [diff] [blame] | 525 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 526 | stream_tag, format, substream); |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | static int ca0132_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 530 | struct hda_codec *codec, |
| 531 | struct snd_pcm_substream *substream) |
| 532 | { |
| 533 | struct ca0132_spec *spec = codec->spec; |
Takashi Iwai | 27ebeb0 | 2012-08-08 17:20:18 +0200 | [diff] [blame] | 534 | return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Takashi Iwai | 27ebeb0 | 2012-08-08 17:20:18 +0200 | [diff] [blame] | 537 | static int ca0132_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 538 | struct hda_codec *codec, |
| 539 | struct snd_pcm_substream *substream) |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 540 | { |
| 541 | struct ca0132_spec *spec = codec->spec; |
Takashi Iwai | 27ebeb0 | 2012-08-08 17:20:18 +0200 | [diff] [blame] | 542 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | /* |
| 546 | */ |
| 547 | static struct hda_pcm_stream ca0132_pcm_analog_playback = { |
| 548 | .substreams = 1, |
| 549 | .channels_min = 2, |
| 550 | .channels_max = 2, |
| 551 | .ops = { |
Takashi Iwai | 27ebeb0 | 2012-08-08 17:20:18 +0200 | [diff] [blame] | 552 | .open = ca0132_playback_pcm_open, |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 553 | .prepare = ca0132_playback_pcm_prepare, |
| 554 | .cleanup = ca0132_playback_pcm_cleanup |
| 555 | }, |
| 556 | }; |
| 557 | |
| 558 | static struct hda_pcm_stream ca0132_pcm_analog_capture = { |
| 559 | .substreams = 1, |
| 560 | .channels_min = 2, |
| 561 | .channels_max = 2, |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 562 | }; |
| 563 | |
| 564 | static struct hda_pcm_stream ca0132_pcm_digital_playback = { |
| 565 | .substreams = 1, |
| 566 | .channels_min = 2, |
| 567 | .channels_max = 2, |
| 568 | .ops = { |
Takashi Iwai | 27ebeb0 | 2012-08-08 17:20:18 +0200 | [diff] [blame] | 569 | .open = ca0132_dig_playback_pcm_open, |
| 570 | .close = ca0132_dig_playback_pcm_close, |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 571 | .prepare = ca0132_dig_playback_pcm_prepare, |
| 572 | .cleanup = ca0132_dig_playback_pcm_cleanup |
| 573 | }, |
| 574 | }; |
| 575 | |
| 576 | static struct hda_pcm_stream ca0132_pcm_digital_capture = { |
| 577 | .substreams = 1, |
| 578 | .channels_min = 2, |
| 579 | .channels_max = 2, |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 580 | }; |
| 581 | |
| 582 | static int ca0132_build_pcms(struct hda_codec *codec) |
| 583 | { |
| 584 | struct ca0132_spec *spec = codec->spec; |
| 585 | struct hda_pcm *info = spec->pcm_rec; |
| 586 | |
| 587 | codec->pcm_info = info; |
| 588 | codec->num_pcms = 0; |
| 589 | |
| 590 | info->name = "CA0132 Analog"; |
| 591 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0132_pcm_analog_playback; |
| 592 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0]; |
| 593 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = |
| 594 | spec->multiout.max_channels; |
| 595 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture; |
| 596 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_inputs; |
| 597 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0]; |
| 598 | codec->num_pcms++; |
| 599 | |
| 600 | if (!spec->dig_out && !spec->dig_in) |
| 601 | return 0; |
| 602 | |
| 603 | info++; |
| 604 | info->name = "CA0132 Digital"; |
| 605 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
| 606 | if (spec->dig_out) { |
| 607 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 608 | ca0132_pcm_digital_playback; |
| 609 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dig_out; |
| 610 | } |
| 611 | if (spec->dig_in) { |
| 612 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 613 | ca0132_pcm_digital_capture; |
| 614 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in; |
| 615 | } |
| 616 | codec->num_pcms++; |
| 617 | |
| 618 | return 0; |
| 619 | } |
| 620 | |
| 621 | #define REG_CODEC_MUTE 0x18b014 |
| 622 | #define REG_CODEC_HP_VOL_L 0x18b070 |
| 623 | #define REG_CODEC_HP_VOL_R 0x18b074 |
| 624 | |
| 625 | static int ca0132_hp_switch_get(struct snd_kcontrol *kcontrol, |
| 626 | struct snd_ctl_elem_value *ucontrol) |
| 627 | { |
| 628 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 629 | struct ca0132_spec *spec = codec->spec; |
| 630 | long *valp = ucontrol->value.integer.value; |
| 631 | |
| 632 | *valp = spec->curr_hp_switch; |
| 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | static int ca0132_hp_switch_put(struct snd_kcontrol *kcontrol, |
| 637 | struct snd_ctl_elem_value *ucontrol) |
| 638 | { |
| 639 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 640 | struct ca0132_spec *spec = codec->spec; |
| 641 | long *valp = ucontrol->value.integer.value; |
| 642 | unsigned int data; |
| 643 | int err; |
| 644 | |
| 645 | /* any change? */ |
| 646 | if (spec->curr_hp_switch == *valp) |
| 647 | return 0; |
| 648 | |
| 649 | snd_hda_power_up(codec); |
| 650 | |
| 651 | err = chipio_read(codec, REG_CODEC_MUTE, &data); |
| 652 | if (err < 0) |
Takashi Iwai | b97f6bf | 2012-02-07 11:00:53 +0100 | [diff] [blame] | 653 | goto exit; |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 654 | |
| 655 | /* *valp 0 is mute, 1 is unmute */ |
| 656 | data = (data & 0x7f) | (*valp ? 0 : 0x80); |
Takashi Iwai | b97f6bf | 2012-02-07 11:00:53 +0100 | [diff] [blame] | 657 | err = chipio_write(codec, REG_CODEC_MUTE, data); |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 658 | if (err < 0) |
Takashi Iwai | b97f6bf | 2012-02-07 11:00:53 +0100 | [diff] [blame] | 659 | goto exit; |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 660 | |
| 661 | spec->curr_hp_switch = *valp; |
| 662 | |
Takashi Iwai | b97f6bf | 2012-02-07 11:00:53 +0100 | [diff] [blame] | 663 | exit: |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 664 | snd_hda_power_down(codec); |
Takashi Iwai | b97f6bf | 2012-02-07 11:00:53 +0100 | [diff] [blame] | 665 | return err < 0 ? err : 1; |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | static int ca0132_speaker_switch_get(struct snd_kcontrol *kcontrol, |
| 669 | struct snd_ctl_elem_value *ucontrol) |
| 670 | { |
| 671 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 672 | struct ca0132_spec *spec = codec->spec; |
| 673 | long *valp = ucontrol->value.integer.value; |
| 674 | |
| 675 | *valp = spec->curr_speaker_switch; |
| 676 | return 0; |
| 677 | } |
| 678 | |
| 679 | static int ca0132_speaker_switch_put(struct snd_kcontrol *kcontrol, |
| 680 | struct snd_ctl_elem_value *ucontrol) |
| 681 | { |
| 682 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 683 | struct ca0132_spec *spec = codec->spec; |
| 684 | long *valp = ucontrol->value.integer.value; |
| 685 | unsigned int data; |
| 686 | int err; |
| 687 | |
| 688 | /* any change? */ |
| 689 | if (spec->curr_speaker_switch == *valp) |
| 690 | return 0; |
| 691 | |
| 692 | snd_hda_power_up(codec); |
| 693 | |
| 694 | err = chipio_read(codec, REG_CODEC_MUTE, &data); |
| 695 | if (err < 0) |
Takashi Iwai | b97f6bf | 2012-02-07 11:00:53 +0100 | [diff] [blame] | 696 | goto exit; |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 697 | |
| 698 | /* *valp 0 is mute, 1 is unmute */ |
| 699 | data = (data & 0xef) | (*valp ? 0 : 0x10); |
Takashi Iwai | b97f6bf | 2012-02-07 11:00:53 +0100 | [diff] [blame] | 700 | err = chipio_write(codec, REG_CODEC_MUTE, data); |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 701 | if (err < 0) |
Takashi Iwai | b97f6bf | 2012-02-07 11:00:53 +0100 | [diff] [blame] | 702 | goto exit; |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 703 | |
| 704 | spec->curr_speaker_switch = *valp; |
| 705 | |
Takashi Iwai | b97f6bf | 2012-02-07 11:00:53 +0100 | [diff] [blame] | 706 | exit: |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 707 | snd_hda_power_down(codec); |
Takashi Iwai | b97f6bf | 2012-02-07 11:00:53 +0100 | [diff] [blame] | 708 | return err < 0 ? err : 1; |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | static int ca0132_hp_volume_get(struct snd_kcontrol *kcontrol, |
| 712 | struct snd_ctl_elem_value *ucontrol) |
| 713 | { |
| 714 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 715 | struct ca0132_spec *spec = codec->spec; |
| 716 | long *valp = ucontrol->value.integer.value; |
| 717 | |
| 718 | *valp++ = spec->curr_hp_volume[0]; |
| 719 | *valp = spec->curr_hp_volume[1]; |
| 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | static int ca0132_hp_volume_put(struct snd_kcontrol *kcontrol, |
| 724 | struct snd_ctl_elem_value *ucontrol) |
| 725 | { |
| 726 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 727 | struct ca0132_spec *spec = codec->spec; |
| 728 | long *valp = ucontrol->value.integer.value; |
| 729 | long left_vol, right_vol; |
| 730 | unsigned int data; |
| 731 | int val; |
| 732 | int err; |
| 733 | |
| 734 | left_vol = *valp++; |
| 735 | right_vol = *valp; |
| 736 | |
| 737 | /* any change? */ |
| 738 | if ((spec->curr_hp_volume[0] == left_vol) && |
| 739 | (spec->curr_hp_volume[1] == right_vol)) |
| 740 | return 0; |
| 741 | |
| 742 | snd_hda_power_up(codec); |
| 743 | |
| 744 | err = chipio_read(codec, REG_CODEC_HP_VOL_L, &data); |
| 745 | if (err < 0) |
Takashi Iwai | b97f6bf | 2012-02-07 11:00:53 +0100 | [diff] [blame] | 746 | goto exit; |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 747 | |
| 748 | val = 31 - left_vol; |
| 749 | data = (data & 0xe0) | val; |
Takashi Iwai | b97f6bf | 2012-02-07 11:00:53 +0100 | [diff] [blame] | 750 | err = chipio_write(codec, REG_CODEC_HP_VOL_L, data); |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 751 | if (err < 0) |
Takashi Iwai | b97f6bf | 2012-02-07 11:00:53 +0100 | [diff] [blame] | 752 | goto exit; |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 753 | |
| 754 | val = 31 - right_vol; |
| 755 | data = (data & 0xe0) | val; |
Takashi Iwai | b97f6bf | 2012-02-07 11:00:53 +0100 | [diff] [blame] | 756 | err = chipio_write(codec, REG_CODEC_HP_VOL_R, data); |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 757 | if (err < 0) |
Takashi Iwai | b97f6bf | 2012-02-07 11:00:53 +0100 | [diff] [blame] | 758 | goto exit; |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 759 | |
| 760 | spec->curr_hp_volume[0] = left_vol; |
| 761 | spec->curr_hp_volume[1] = right_vol; |
| 762 | |
Takashi Iwai | b97f6bf | 2012-02-07 11:00:53 +0100 | [diff] [blame] | 763 | exit: |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 764 | snd_hda_power_down(codec); |
Takashi Iwai | b97f6bf | 2012-02-07 11:00:53 +0100 | [diff] [blame] | 765 | return err < 0 ? err : 1; |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | static int add_hp_switch(struct hda_codec *codec, hda_nid_t nid) |
| 769 | { |
| 770 | struct snd_kcontrol_new knew = |
| 771 | HDA_CODEC_MUTE_MONO("Headphone Playback Switch", |
| 772 | nid, 1, 0, HDA_OUTPUT); |
| 773 | knew.get = ca0132_hp_switch_get; |
| 774 | knew.put = ca0132_hp_switch_put; |
| 775 | return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec)); |
| 776 | } |
| 777 | |
| 778 | static int add_hp_volume(struct hda_codec *codec, hda_nid_t nid) |
| 779 | { |
| 780 | struct snd_kcontrol_new knew = |
| 781 | HDA_CODEC_VOLUME_MONO("Headphone Playback Volume", |
| 782 | nid, 3, 0, HDA_OUTPUT); |
| 783 | knew.get = ca0132_hp_volume_get; |
| 784 | knew.put = ca0132_hp_volume_put; |
| 785 | return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec)); |
| 786 | } |
| 787 | |
| 788 | static int add_speaker_switch(struct hda_codec *codec, hda_nid_t nid) |
| 789 | { |
| 790 | struct snd_kcontrol_new knew = |
| 791 | HDA_CODEC_MUTE_MONO("Speaker Playback Switch", |
| 792 | nid, 1, 0, HDA_OUTPUT); |
| 793 | knew.get = ca0132_speaker_switch_get; |
| 794 | knew.put = ca0132_speaker_switch_put; |
| 795 | return snd_hda_ctl_add(codec, nid, snd_ctl_new1(&knew, codec)); |
| 796 | } |
| 797 | |
| 798 | static void ca0132_fix_hp_caps(struct hda_codec *codec) |
| 799 | { |
| 800 | struct ca0132_spec *spec = codec->spec; |
| 801 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 802 | unsigned int caps; |
| 803 | |
| 804 | /* set mute-capable, 1db step, 32 steps, ofs 6 */ |
| 805 | caps = 0x80031f06; |
| 806 | snd_hda_override_amp_caps(codec, cfg->hp_pins[0], HDA_OUTPUT, caps); |
| 807 | } |
| 808 | |
| 809 | static int ca0132_build_controls(struct hda_codec *codec) |
| 810 | { |
| 811 | struct ca0132_spec *spec = codec->spec; |
| 812 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 813 | int i, err; |
| 814 | |
| 815 | if (spec->multiout.num_dacs) { |
| 816 | err = add_speaker_switch(codec, spec->out_pins[0]); |
| 817 | if (err < 0) |
| 818 | return err; |
| 819 | } |
| 820 | |
| 821 | if (cfg->hp_outs) { |
| 822 | ca0132_fix_hp_caps(codec); |
| 823 | err = add_hp_switch(codec, cfg->hp_pins[0]); |
| 824 | if (err < 0) |
| 825 | return err; |
| 826 | err = add_hp_volume(codec, cfg->hp_pins[0]); |
| 827 | if (err < 0) |
| 828 | return err; |
| 829 | } |
| 830 | |
| 831 | for (i = 0; i < spec->num_inputs; i++) { |
| 832 | const char *label = spec->input_labels[i]; |
| 833 | |
| 834 | err = add_in_switch(codec, spec->adcs[i], label); |
| 835 | if (err < 0) |
| 836 | return err; |
| 837 | err = add_in_volume(codec, spec->adcs[i], label); |
| 838 | if (err < 0) |
| 839 | return err; |
| 840 | if (cfg->inputs[i].type == AUTO_PIN_MIC) { |
| 841 | /* add Mic-Boost */ |
| 842 | err = add_in_mono_volume(codec, spec->input_pins[i], |
| 843 | "Mic Boost", 1); |
| 844 | if (err < 0) |
| 845 | return err; |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | if (spec->dig_out) { |
Takashi Iwai | efb9f46 | 2011-06-21 07:44:51 +0200 | [diff] [blame] | 850 | err = snd_hda_create_spdif_out_ctls(codec, spec->dig_out, |
| 851 | spec->dig_out); |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 852 | if (err < 0) |
| 853 | return err; |
Takashi Iwai | 8e13fc1 | 2012-08-08 17:26:54 +0200 | [diff] [blame] | 854 | err = snd_hda_create_spdif_share_sw(codec, &spec->multiout); |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 855 | if (err < 0) |
| 856 | return err; |
Takashi Iwai | 8e13fc1 | 2012-08-08 17:26:54 +0200 | [diff] [blame] | 857 | /* spec->multiout.share_spdif = 1; */ |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | if (spec->dig_in) { |
| 861 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in); |
| 862 | if (err < 0) |
| 863 | return err; |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 864 | } |
| 865 | return 0; |
| 866 | } |
| 867 | |
| 868 | |
| 869 | static void ca0132_set_ct_ext(struct hda_codec *codec, int enable) |
| 870 | { |
| 871 | /* Set Creative extension */ |
| 872 | snd_printdd("SET CREATIVE EXTENSION\n"); |
| 873 | snd_hda_codec_write(codec, WIDGET_CHIP_CTRL, 0, |
| 874 | VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, |
| 875 | enable); |
| 876 | msleep(20); |
| 877 | } |
| 878 | |
| 879 | |
| 880 | static void ca0132_config(struct hda_codec *codec) |
| 881 | { |
| 882 | struct ca0132_spec *spec = codec->spec; |
| 883 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 884 | |
Takashi Iwai | 27ebeb0 | 2012-08-08 17:20:18 +0200 | [diff] [blame] | 885 | codec->pcm_format_first = 1; |
| 886 | codec->no_sticky_stream = 1; |
| 887 | |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 888 | /* line-outs */ |
| 889 | cfg->line_outs = 1; |
| 890 | cfg->line_out_pins[0] = 0x0b; /* front */ |
| 891 | cfg->line_out_type = AUTO_PIN_LINE_OUT; |
| 892 | |
| 893 | spec->dacs[0] = 0x02; |
| 894 | spec->out_pins[0] = 0x0b; |
| 895 | spec->multiout.dac_nids = spec->dacs; |
| 896 | spec->multiout.num_dacs = 1; |
| 897 | spec->multiout.max_channels = 2; |
| 898 | |
| 899 | /* headphone */ |
| 900 | cfg->hp_outs = 1; |
| 901 | cfg->hp_pins[0] = 0x0f; |
| 902 | |
| 903 | spec->hp_dac = 0; |
| 904 | spec->multiout.hp_nid = 0; |
| 905 | |
| 906 | /* inputs */ |
| 907 | cfg->num_inputs = 2; /* Mic-in and line-in */ |
| 908 | cfg->inputs[0].pin = 0x12; |
| 909 | cfg->inputs[0].type = AUTO_PIN_MIC; |
| 910 | cfg->inputs[1].pin = 0x11; |
| 911 | cfg->inputs[1].type = AUTO_PIN_LINE_IN; |
| 912 | |
| 913 | /* Mic-in */ |
| 914 | spec->input_pins[0] = 0x12; |
Takashi Iwai | 55cf87f | 2012-08-08 17:15:55 +0200 | [diff] [blame] | 915 | spec->input_labels[0] = "Mic"; |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 916 | spec->adcs[0] = 0x07; |
| 917 | |
| 918 | /* Line-In */ |
| 919 | spec->input_pins[1] = 0x11; |
Takashi Iwai | 55cf87f | 2012-08-08 17:15:55 +0200 | [diff] [blame] | 920 | spec->input_labels[1] = "Line"; |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 921 | spec->adcs[1] = 0x08; |
| 922 | spec->num_inputs = 2; |
Takashi Iwai | 8e13fc1 | 2012-08-08 17:26:54 +0200 | [diff] [blame] | 923 | |
| 924 | /* SPDIF I/O */ |
| 925 | spec->dig_out = 0x05; |
| 926 | spec->multiout.dig_out_nid = spec->dig_out; |
| 927 | cfg->dig_out_pins[0] = 0x0c; |
| 928 | cfg->dig_outs = 1; |
| 929 | cfg->dig_out_type[0] = HDA_PCM_TYPE_SPDIF; |
| 930 | spec->dig_in = 0x09; |
| 931 | cfg->dig_in_pin = 0x0e; |
| 932 | cfg->dig_in_type = HDA_PCM_TYPE_SPDIF; |
Ian Minett | 95c6e9c | 2011-06-15 15:35:17 -0700 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | static void ca0132_init_chip(struct hda_codec *codec) |
| 936 | { |
| 937 | struct ca0132_spec *spec = codec->spec; |
| 938 | |
| 939 | mutex_init(&spec->chipio_mutex); |
| 940 | } |
| 941 | |
| 942 | static void ca0132_exit_chip(struct hda_codec *codec) |
| 943 | { |
| 944 | /* put any chip cleanup stuffs here. */ |
| 945 | } |
| 946 | |
| 947 | static int ca0132_init(struct hda_codec *codec) |
| 948 | { |
| 949 | struct ca0132_spec *spec = codec->spec; |
| 950 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 951 | int i; |
| 952 | |
| 953 | for (i = 0; i < spec->multiout.num_dacs; i++) { |
| 954 | init_output(codec, spec->out_pins[i], |
| 955 | spec->multiout.dac_nids[i]); |
| 956 | } |
| 957 | init_output(codec, cfg->hp_pins[0], spec->hp_dac); |
| 958 | init_output(codec, cfg->dig_out_pins[0], spec->dig_out); |
| 959 | |
| 960 | for (i = 0; i < spec->num_inputs; i++) |
| 961 | init_input(codec, spec->input_pins[i], spec->adcs[i]); |
| 962 | |
| 963 | init_input(codec, cfg->dig_in_pin, spec->dig_in); |
| 964 | |
| 965 | ca0132_set_ct_ext(codec, 1); |
| 966 | |
| 967 | return 0; |
| 968 | } |
| 969 | |
| 970 | |
| 971 | static void ca0132_free(struct hda_codec *codec) |
| 972 | { |
| 973 | ca0132_set_ct_ext(codec, 0); |
| 974 | ca0132_exit_chip(codec); |
| 975 | kfree(codec->spec); |
| 976 | } |
| 977 | |
| 978 | static struct hda_codec_ops ca0132_patch_ops = { |
| 979 | .build_controls = ca0132_build_controls, |
| 980 | .build_pcms = ca0132_build_pcms, |
| 981 | .init = ca0132_init, |
| 982 | .free = ca0132_free, |
| 983 | }; |
| 984 | |
| 985 | |
| 986 | |
| 987 | static int patch_ca0132(struct hda_codec *codec) |
| 988 | { |
| 989 | struct ca0132_spec *spec; |
| 990 | |
| 991 | snd_printdd("patch_ca0132\n"); |
| 992 | |
| 993 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 994 | if (!spec) |
| 995 | return -ENOMEM; |
| 996 | codec->spec = spec; |
| 997 | |
| 998 | ca0132_init_chip(codec); |
| 999 | |
| 1000 | ca0132_config(codec); |
| 1001 | |
| 1002 | codec->patch_ops = ca0132_patch_ops; |
| 1003 | |
| 1004 | return 0; |
| 1005 | } |
| 1006 | |
| 1007 | /* |
| 1008 | * patch entries |
| 1009 | */ |
| 1010 | static struct hda_codec_preset snd_hda_preset_ca0132[] = { |
| 1011 | { .id = 0x11020011, .name = "CA0132", .patch = patch_ca0132 }, |
| 1012 | {} /* terminator */ |
| 1013 | }; |
| 1014 | |
| 1015 | MODULE_ALIAS("snd-hda-codec-id:11020011"); |
| 1016 | |
| 1017 | MODULE_LICENSE("GPL"); |
| 1018 | MODULE_DESCRIPTION("Creative CA0132, CA0132 HD-audio codec"); |
| 1019 | |
| 1020 | static struct hda_codec_preset_list ca0132_list = { |
| 1021 | .preset = snd_hda_preset_ca0132, |
| 1022 | .owner = THIS_MODULE, |
| 1023 | }; |
| 1024 | |
| 1025 | static int __init patch_ca0132_init(void) |
| 1026 | { |
| 1027 | return snd_hda_add_codec_preset(&ca0132_list); |
| 1028 | } |
| 1029 | |
| 1030 | static void __exit patch_ca0132_exit(void) |
| 1031 | { |
| 1032 | snd_hda_delete_codec_preset(&ca0132_list); |
| 1033 | } |
| 1034 | |
| 1035 | module_init(patch_ca0132_init) |
| 1036 | module_exit(patch_ca0132_exit) |