2 * HD audio interface patch for Creative CA0132 chip
4 * Copyright (c) 2011, Creative Technology Ltd.
6 * Based on patch_ca0110.c
7 * Copyright (c) 2008 Takashi Iwai <tiwai@suse.de>
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.
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.
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
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>
29 #include <sound/core.h>
30 #include "hda_codec.h"
31 #include "hda_local.h"
33 #define WIDGET_CHIP_CTRL 0x15
34 #define WIDGET_DSP_CTRL 0x16
36 #define WUH_MEM_CONNID 10
37 #define DSP_MEM_CONNID 16
39 enum hda_cmd_vendor_io
{
41 VENDOR_DSPIO_SCP_WRITE_DATA_LOW
= 0x000,
42 VENDOR_DSPIO_SCP_WRITE_DATA_HIGH
= 0x100,
44 VENDOR_DSPIO_STATUS
= 0xF01,
45 VENDOR_DSPIO_SCP_POST_READ_DATA
= 0x702,
46 VENDOR_DSPIO_SCP_READ_DATA
= 0xF02,
47 VENDOR_DSPIO_DSP_INIT
= 0x703,
48 VENDOR_DSPIO_SCP_POST_COUNT_QUERY
= 0x704,
49 VENDOR_DSPIO_SCP_READ_COUNT
= 0xF04,
52 VENDOR_CHIPIO_ADDRESS_LOW
= 0x000,
53 VENDOR_CHIPIO_ADDRESS_HIGH
= 0x100,
54 VENDOR_CHIPIO_STREAM_FORMAT
= 0x200,
55 VENDOR_CHIPIO_DATA_LOW
= 0x300,
56 VENDOR_CHIPIO_DATA_HIGH
= 0x400,
58 VENDOR_CHIPIO_GET_PARAMETER
= 0xF00,
59 VENDOR_CHIPIO_STATUS
= 0xF01,
60 VENDOR_CHIPIO_HIC_POST_READ
= 0x702,
61 VENDOR_CHIPIO_HIC_READ_DATA
= 0xF03,
63 VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE
= 0x70A,
65 VENDOR_CHIPIO_PLL_PMU_WRITE
= 0x70C,
66 VENDOR_CHIPIO_PLL_PMU_READ
= 0xF0C,
67 VENDOR_CHIPIO_8051_ADDRESS_LOW
= 0x70D,
68 VENDOR_CHIPIO_8051_ADDRESS_HIGH
= 0x70E,
69 VENDOR_CHIPIO_FLAG_SET
= 0x70F,
70 VENDOR_CHIPIO_FLAGS_GET
= 0xF0F,
71 VENDOR_CHIPIO_PARAMETER_SET
= 0x710,
72 VENDOR_CHIPIO_PARAMETER_GET
= 0xF10,
74 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET
= 0x711,
75 VENDOR_CHIPIO_PORT_ALLOC_SET
= 0x712,
76 VENDOR_CHIPIO_PORT_ALLOC_GET
= 0xF12,
77 VENDOR_CHIPIO_PORT_FREE_SET
= 0x713,
79 VENDOR_CHIPIO_PARAMETER_EX_ID_GET
= 0xF17,
80 VENDOR_CHIPIO_PARAMETER_EX_ID_SET
= 0x717,
81 VENDOR_CHIPIO_PARAMETER_EX_VALUE_GET
= 0xF18,
82 VENDOR_CHIPIO_PARAMETER_EX_VALUE_SET
= 0x718
88 enum control_flag_id
{
89 /* Connection manager stream setup is bypassed/enabled */
90 CONTROL_FLAG_C_MGR
= 0,
91 /* DSP DMA is bypassed/enabled */
93 /* 8051 'idle' mode is disabled/enabled */
94 CONTROL_FLAG_IDLE_ENABLE
= 2,
95 /* Tracker for the SPDIF-in path is bypassed/enabled */
96 CONTROL_FLAG_TRACKER
= 3,
97 /* DigitalOut to Spdif2Out connection is disabled/enabled */
98 CONTROL_FLAG_SPDIF2OUT
= 4,
99 /* Digital Microphone is disabled/enabled */
100 CONTROL_FLAG_DMIC
= 5,
101 /* ADC_B rate is 48 kHz/96 kHz */
102 CONTROL_FLAG_ADC_B_96KHZ
= 6,
103 /* ADC_C rate is 48 kHz/96 kHz */
104 CONTROL_FLAG_ADC_C_96KHZ
= 7,
105 /* DAC rate is 48 kHz/96 kHz (affects all DACs) */
106 CONTROL_FLAG_DAC_96KHZ
= 8,
107 /* DSP rate is 48 kHz/96 kHz */
108 CONTROL_FLAG_DSP_96KHZ
= 9,
109 /* SRC clock is 98 MHz/196 MHz (196 MHz forces rate to 96 KHz) */
110 CONTROL_FLAG_SRC_CLOCK_196MHZ
= 10,
111 /* SRC rate is 48 kHz/96 kHz (48 kHz disabled when clock is 196 MHz) */
112 CONTROL_FLAG_SRC_RATE_96KHZ
= 11,
113 /* Decode Loop (DSP->SRC->DSP) is disabled/enabled */
114 CONTROL_FLAG_DECODE_LOOP
= 12,
115 /* De-emphasis filter on DAC-1 disabled/enabled */
116 CONTROL_FLAG_DAC1_DEEMPHASIS
= 13,
117 /* De-emphasis filter on DAC-2 disabled/enabled */
118 CONTROL_FLAG_DAC2_DEEMPHASIS
= 14,
119 /* De-emphasis filter on DAC-3 disabled/enabled */
120 CONTROL_FLAG_DAC3_DEEMPHASIS
= 15,
121 /* High-pass filter on ADC_B disabled/enabled */
122 CONTROL_FLAG_ADC_B_HIGH_PASS
= 16,
123 /* High-pass filter on ADC_C disabled/enabled */
124 CONTROL_FLAG_ADC_C_HIGH_PASS
= 17,
125 /* Common mode on Port_A disabled/enabled */
126 CONTROL_FLAG_PORT_A_COMMON_MODE
= 18,
127 /* Common mode on Port_D disabled/enabled */
128 CONTROL_FLAG_PORT_D_COMMON_MODE
= 19,
129 /* Impedance for ramp generator on Port_A 16 Ohm/10K Ohm */
130 CONTROL_FLAG_PORT_A_10KOHM_LOAD
= 20,
131 /* Impedance for ramp generator on Port_D, 16 Ohm/10K Ohm */
132 CONTROL_FLAG_PORT_D_10K0HM_LOAD
= 21,
133 /* ASI rate is 48kHz/96kHz */
134 CONTROL_FLAG_ASI_96KHZ
= 22,
135 /* DAC power settings able to control attached ports no/yes */
136 CONTROL_FLAG_DACS_CONTROL_PORTS
= 23,
137 /* Clock Stop OK reporting is disabled/enabled */
138 CONTROL_FLAG_CONTROL_STOP_OK_ENABLE
= 24,
139 /* Number of control flags */
140 CONTROL_FLAGS_MAX
= (CONTROL_FLAG_CONTROL_STOP_OK_ENABLE
+1)
144 * Control parameter IDs
146 enum control_parameter_id
{
147 /* 0: force HDA, 1: allow DSP if HDA Spdif1Out stream is idle */
148 CONTROL_PARAM_SPDIF1_SOURCE
= 2,
152 /* Select stream with the given ID */
153 CONTROL_PARAM_STREAM_ID
= 24,
154 /* Source connection point for the selected stream */
155 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT
= 25,
156 /* Destination connection point for the selected stream */
157 CONTROL_PARAM_STREAM_DEST_CONN_POINT
= 26,
158 /* Number of audio channels in the selected stream */
159 CONTROL_PARAM_STREAMS_CHANNELS
= 27,
160 /*Enable control for the selected stream */
161 CONTROL_PARAM_STREAM_CONTROL
= 28,
163 /* Connection Point Control */
165 /* Select connection point with the given ID */
166 CONTROL_PARAM_CONN_POINT_ID
= 29,
167 /* Connection point sample rate */
168 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE
= 30,
172 /* Select HDA node with the given ID */
173 CONTROL_PARAM_NODE_ID
= 31
177 * Dsp Io Status codes
179 enum hda_vendor_status_dspio
{
181 VENDOR_STATUS_DSPIO_OK
= 0x00,
182 /* Busy, unable to accept new command, the host must retry */
183 VENDOR_STATUS_DSPIO_BUSY
= 0x01,
184 /* SCP command queue is full */
185 VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL
= 0x02,
186 /* SCP response queue is empty */
187 VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY
= 0x03
191 * Chip Io Status codes
193 enum hda_vendor_status_chipio
{
195 VENDOR_STATUS_CHIPIO_OK
= 0x00,
196 /* Busy, unable to accept new command, the host must retry */
197 VENDOR_STATUS_CHIPIO_BUSY
= 0x01
203 enum ca0132_sample_rate
{
223 SR_RATE_UNKNOWN
= 0x1F
227 * Scp Helper function
235 * Duplicated from ca0110 codec
238 static void init_output(struct hda_codec
*codec
, hda_nid_t pin
, hda_nid_t dac
)
241 snd_hda_codec_write(codec
, pin
, 0,
242 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_HP
);
243 if (get_wcaps(codec
, pin
) & AC_WCAP_OUT_AMP
)
244 snd_hda_codec_write(codec
, pin
, 0,
245 AC_VERB_SET_AMP_GAIN_MUTE
,
249 snd_hda_codec_write(codec
, dac
, 0,
250 AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
);
253 static void init_input(struct hda_codec
*codec
, hda_nid_t pin
, hda_nid_t adc
)
256 snd_hda_codec_write(codec
, pin
, 0,
257 AC_VERB_SET_PIN_WIDGET_CONTROL
,
259 if (get_wcaps(codec
, pin
) & AC_WCAP_IN_AMP
)
260 snd_hda_codec_write(codec
, pin
, 0,
261 AC_VERB_SET_AMP_GAIN_MUTE
,
265 snd_hda_codec_write(codec
, adc
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
269 static char *dirstr
[2] = { "Playback", "Capture" };
271 static int _add_switch(struct hda_codec
*codec
, hda_nid_t nid
, const char *pfx
,
275 int type
= dir
? HDA_INPUT
: HDA_OUTPUT
;
276 struct snd_kcontrol_new knew
=
277 HDA_CODEC_MUTE_MONO(namestr
, nid
, chan
, 0, type
);
278 sprintf(namestr
, "%s %s Switch", pfx
, dirstr
[dir
]);
279 return snd_hda_ctl_add(codec
, nid
, snd_ctl_new1(&knew
, codec
));
282 static int _add_volume(struct hda_codec
*codec
, hda_nid_t nid
, const char *pfx
,
286 int type
= dir
? HDA_INPUT
: HDA_OUTPUT
;
287 struct snd_kcontrol_new knew
=
288 HDA_CODEC_VOLUME_MONO(namestr
, nid
, chan
, 0, type
);
289 sprintf(namestr
, "%s %s Volume", pfx
, dirstr
[dir
]);
290 return snd_hda_ctl_add(codec
, nid
, snd_ctl_new1(&knew
, codec
));
293 #define add_out_switch(codec, nid, pfx) _add_switch(codec, nid, pfx, 3, 0)
294 #define add_out_volume(codec, nid, pfx) _add_volume(codec, nid, pfx, 3, 0)
295 #define add_in_switch(codec, nid, pfx) _add_switch(codec, nid, pfx, 3, 1)
296 #define add_in_volume(codec, nid, pfx) _add_volume(codec, nid, pfx, 3, 1)
297 #define add_mono_switch(codec, nid, pfx, chan) \
298 _add_switch(codec, nid, pfx, chan, 0)
299 #define add_mono_volume(codec, nid, pfx, chan) \
300 _add_volume(codec, nid, pfx, chan, 0)
301 #define add_in_mono_switch(codec, nid, pfx, chan) \
302 _add_switch(codec, nid, pfx, chan, 1)
303 #define add_in_mono_volume(codec, nid, pfx, chan) \
304 _add_volume(codec, nid, pfx, chan, 1)
312 struct auto_pin_cfg autocfg
;
313 struct hda_multi_out multiout
;
314 hda_nid_t out_pins
[AUTO_CFG_MAX_OUTS
];
315 hda_nid_t dacs
[AUTO_CFG_MAX_OUTS
];
317 hda_nid_t input_pins
[AUTO_PIN_LAST
];
318 hda_nid_t adcs
[AUTO_PIN_LAST
];
321 unsigned int num_inputs
;
323 long curr_hp_volume
[2];
324 long curr_speaker_switch
;
325 struct mutex chipio_mutex
;
326 const char *input_labels
[AUTO_PIN_LAST
];
327 struct hda_pcm pcm_rec
[2]; /* PCM information */
330 /* Chip access helper function */
331 static int chipio_send(struct hda_codec
*codec
,
338 /* send bits of data specified by reg */
340 res
= snd_hda_codec_read(codec
, WIDGET_CHIP_CTRL
, 0,
342 if (res
== VENDOR_STATUS_CHIPIO_OK
)
349 * Write chip address through the vendor widget -- NOT protected by the Mutex!
351 static int chipio_write_address(struct hda_codec
*codec
,
352 unsigned int chip_addx
)
356 /* send low 16 bits of the address */
357 res
= chipio_send(codec
, VENDOR_CHIPIO_ADDRESS_LOW
,
361 /* send high 16 bits of the address */
362 res
= chipio_send(codec
, VENDOR_CHIPIO_ADDRESS_HIGH
,
370 * Write data through the vendor widget -- NOT protected by the Mutex!
373 static int chipio_write_data(struct hda_codec
*codec
, unsigned int data
)
377 /* send low 16 bits of the data */
378 res
= chipio_send(codec
, VENDOR_CHIPIO_DATA_LOW
, data
& 0xffff);
381 /* send high 16 bits of the data */
382 res
= chipio_send(codec
, VENDOR_CHIPIO_DATA_HIGH
,
390 * Read data through the vendor widget -- NOT protected by the Mutex!
392 static int chipio_read_data(struct hda_codec
*codec
, unsigned int *data
)
397 res
= chipio_send(codec
, VENDOR_CHIPIO_HIC_POST_READ
, 0);
401 res
= chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0);
406 *data
= snd_hda_codec_read(codec
, WIDGET_CHIP_CTRL
, 0,
407 VENDOR_CHIPIO_HIC_READ_DATA
,
415 * Write given value to the given address through the chip I/O widget.
416 * protected by the Mutex
418 static int chipio_write(struct hda_codec
*codec
,
419 unsigned int chip_addx
, const unsigned int data
)
421 struct ca0132_spec
*spec
= codec
->spec
;
424 mutex_lock(&spec
->chipio_mutex
);
426 /* write the address, and if successful proceed to write data */
427 err
= chipio_write_address(codec
, chip_addx
);
431 err
= chipio_write_data(codec
, data
);
436 mutex_unlock(&spec
->chipio_mutex
);
441 * Read the given address through the chip I/O widget
442 * protected by the Mutex
444 static int chipio_read(struct hda_codec
*codec
,
445 unsigned int chip_addx
, unsigned int *data
)
447 struct ca0132_spec
*spec
= codec
->spec
;
450 mutex_lock(&spec
->chipio_mutex
);
452 /* write the address, and if successful proceed to write data */
453 err
= chipio_write_address(codec
, chip_addx
);
457 err
= chipio_read_data(codec
, data
);
462 mutex_unlock(&spec
->chipio_mutex
);
469 static void ca0132_setup_stream(struct hda_codec
*codec
, hda_nid_t nid
,
471 int channel_id
, int format
)
473 unsigned int oldval
, newval
;
478 snd_printdd("ca0132_setup_stream: "
479 "NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n",
480 nid
, stream_tag
, channel_id
, format
);
482 /* update the format-id if changed */
483 oldval
= snd_hda_codec_read(codec
, nid
, 0,
484 AC_VERB_GET_STREAM_FORMAT
,
486 if (oldval
!= format
) {
488 snd_hda_codec_write(codec
, nid
, 0,
489 AC_VERB_SET_STREAM_FORMAT
,
493 oldval
= snd_hda_codec_read(codec
, nid
, 0, AC_VERB_GET_CONV
, 0);
494 newval
= (stream_tag
<< 4) | channel_id
;
495 if (oldval
!= newval
) {
496 snd_hda_codec_write(codec
, nid
, 0,
497 AC_VERB_SET_CHANNEL_STREAMID
,
502 static void ca0132_cleanup_stream(struct hda_codec
*codec
, hda_nid_t nid
)
504 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_STREAM_FORMAT
, 0);
505 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CHANNEL_STREAMID
, 0);
511 static int ca0132_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
512 struct hda_codec
*codec
,
513 unsigned int stream_tag
,
515 struct snd_pcm_substream
*substream
)
517 struct ca0132_spec
*spec
= codec
->spec
;
519 ca0132_setup_stream(codec
, spec
->dacs
[0], stream_tag
, 0, format
);
524 static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
525 struct hda_codec
*codec
,
526 struct snd_pcm_substream
*substream
)
528 struct ca0132_spec
*spec
= codec
->spec
;
530 ca0132_cleanup_stream(codec
, spec
->dacs
[0]);
538 static int ca0132_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
539 struct hda_codec
*codec
,
540 unsigned int stream_tag
,
542 struct snd_pcm_substream
*substream
)
544 struct ca0132_spec
*spec
= codec
->spec
;
546 ca0132_setup_stream(codec
, spec
->dig_out
, stream_tag
, 0, format
);
551 static int ca0132_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
552 struct hda_codec
*codec
,
553 struct snd_pcm_substream
*substream
)
555 struct ca0132_spec
*spec
= codec
->spec
;
557 ca0132_cleanup_stream(codec
, spec
->dig_out
);
565 static int ca0132_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
566 struct hda_codec
*codec
,
567 unsigned int stream_tag
,
569 struct snd_pcm_substream
*substream
)
571 struct ca0132_spec
*spec
= codec
->spec
;
573 ca0132_setup_stream(codec
, spec
->adcs
[substream
->number
],
574 stream_tag
, 0, format
);
579 static int ca0132_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
580 struct hda_codec
*codec
,
581 struct snd_pcm_substream
*substream
)
583 struct ca0132_spec
*spec
= codec
->spec
;
585 ca0132_cleanup_stream(codec
, spec
->adcs
[substream
->number
]);
593 static int ca0132_dig_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
594 struct hda_codec
*codec
,
595 unsigned int stream_tag
,
597 struct snd_pcm_substream
*substream
)
599 struct ca0132_spec
*spec
= codec
->spec
;
601 ca0132_setup_stream(codec
, spec
->dig_in
, stream_tag
, 0, format
);
606 static int ca0132_dig_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
607 struct hda_codec
*codec
,
608 struct snd_pcm_substream
*substream
)
610 struct ca0132_spec
*spec
= codec
->spec
;
612 ca0132_cleanup_stream(codec
, spec
->dig_in
);
619 static struct hda_pcm_stream ca0132_pcm_analog_playback
= {
624 .prepare
= ca0132_playback_pcm_prepare
,
625 .cleanup
= ca0132_playback_pcm_cleanup
629 static struct hda_pcm_stream ca0132_pcm_analog_capture
= {
634 .prepare
= ca0132_capture_pcm_prepare
,
635 .cleanup
= ca0132_capture_pcm_cleanup
639 static struct hda_pcm_stream ca0132_pcm_digital_playback
= {
644 .prepare
= ca0132_dig_playback_pcm_prepare
,
645 .cleanup
= ca0132_dig_playback_pcm_cleanup
649 static struct hda_pcm_stream ca0132_pcm_digital_capture
= {
654 .prepare
= ca0132_dig_capture_pcm_prepare
,
655 .cleanup
= ca0132_dig_capture_pcm_cleanup
659 static int ca0132_build_pcms(struct hda_codec
*codec
)
661 struct ca0132_spec
*spec
= codec
->spec
;
662 struct hda_pcm
*info
= spec
->pcm_rec
;
664 codec
->pcm_info
= info
;
667 info
->name
= "CA0132 Analog";
668 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = ca0132_pcm_analog_playback
;
669 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->dacs
[0];
670 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
671 spec
->multiout
.max_channels
;
672 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = ca0132_pcm_analog_capture
;
673 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
= spec
->num_inputs
;
674 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adcs
[0];
677 if (!spec
->dig_out
&& !spec
->dig_in
)
681 info
->name
= "CA0132 Digital";
682 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
684 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
685 ca0132_pcm_digital_playback
;
686 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->dig_out
;
689 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
690 ca0132_pcm_digital_capture
;
691 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->dig_in
;
698 #define REG_CODEC_MUTE 0x18b014
699 #define REG_CODEC_HP_VOL_L 0x18b070
700 #define REG_CODEC_HP_VOL_R 0x18b074
702 static int ca0132_hp_switch_get(struct snd_kcontrol
*kcontrol
,
703 struct snd_ctl_elem_value
*ucontrol
)
705 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
706 struct ca0132_spec
*spec
= codec
->spec
;
707 long *valp
= ucontrol
->value
.integer
.value
;
709 *valp
= spec
->curr_hp_switch
;
713 static int ca0132_hp_switch_put(struct snd_kcontrol
*kcontrol
,
714 struct snd_ctl_elem_value
*ucontrol
)
716 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
717 struct ca0132_spec
*spec
= codec
->spec
;
718 long *valp
= ucontrol
->value
.integer
.value
;
723 if (spec
->curr_hp_switch
== *valp
)
726 snd_hda_power_up(codec
);
728 err
= chipio_read(codec
, REG_CODEC_MUTE
, &data
);
732 /* *valp 0 is mute, 1 is unmute */
733 data
= (data
& 0x7f) | (*valp
? 0 : 0x80);
734 chipio_write(codec
, REG_CODEC_MUTE
, data
);
738 spec
->curr_hp_switch
= *valp
;
740 snd_hda_power_down(codec
);
744 static int ca0132_speaker_switch_get(struct snd_kcontrol
*kcontrol
,
745 struct snd_ctl_elem_value
*ucontrol
)
747 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
748 struct ca0132_spec
*spec
= codec
->spec
;
749 long *valp
= ucontrol
->value
.integer
.value
;
751 *valp
= spec
->curr_speaker_switch
;
755 static int ca0132_speaker_switch_put(struct snd_kcontrol
*kcontrol
,
756 struct snd_ctl_elem_value
*ucontrol
)
758 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
759 struct ca0132_spec
*spec
= codec
->spec
;
760 long *valp
= ucontrol
->value
.integer
.value
;
765 if (spec
->curr_speaker_switch
== *valp
)
768 snd_hda_power_up(codec
);
770 err
= chipio_read(codec
, REG_CODEC_MUTE
, &data
);
774 /* *valp 0 is mute, 1 is unmute */
775 data
= (data
& 0xef) | (*valp
? 0 : 0x10);
776 chipio_write(codec
, REG_CODEC_MUTE
, data
);
780 spec
->curr_speaker_switch
= *valp
;
782 snd_hda_power_down(codec
);
786 static int ca0132_hp_volume_get(struct snd_kcontrol
*kcontrol
,
787 struct snd_ctl_elem_value
*ucontrol
)
789 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
790 struct ca0132_spec
*spec
= codec
->spec
;
791 long *valp
= ucontrol
->value
.integer
.value
;
793 *valp
++ = spec
->curr_hp_volume
[0];
794 *valp
= spec
->curr_hp_volume
[1];
798 static int ca0132_hp_volume_put(struct snd_kcontrol
*kcontrol
,
799 struct snd_ctl_elem_value
*ucontrol
)
801 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
802 struct ca0132_spec
*spec
= codec
->spec
;
803 long *valp
= ucontrol
->value
.integer
.value
;
804 long left_vol
, right_vol
;
813 if ((spec
->curr_hp_volume
[0] == left_vol
) &&
814 (spec
->curr_hp_volume
[1] == right_vol
))
817 snd_hda_power_up(codec
);
819 err
= chipio_read(codec
, REG_CODEC_HP_VOL_L
, &data
);
824 data
= (data
& 0xe0) | val
;
825 chipio_write(codec
, REG_CODEC_HP_VOL_L
, data
);
829 val
= 31 - right_vol
;
830 data
= (data
& 0xe0) | val
;
831 chipio_write(codec
, REG_CODEC_HP_VOL_R
, data
);
835 spec
->curr_hp_volume
[0] = left_vol
;
836 spec
->curr_hp_volume
[1] = right_vol
;
838 snd_hda_power_down(codec
);
842 static int add_hp_switch(struct hda_codec
*codec
, hda_nid_t nid
)
844 struct snd_kcontrol_new knew
=
845 HDA_CODEC_MUTE_MONO("Headphone Playback Switch",
846 nid
, 1, 0, HDA_OUTPUT
);
847 knew
.get
= ca0132_hp_switch_get
;
848 knew
.put
= ca0132_hp_switch_put
;
849 return snd_hda_ctl_add(codec
, nid
, snd_ctl_new1(&knew
, codec
));
852 static int add_hp_volume(struct hda_codec
*codec
, hda_nid_t nid
)
854 struct snd_kcontrol_new knew
=
855 HDA_CODEC_VOLUME_MONO("Headphone Playback Volume",
856 nid
, 3, 0, HDA_OUTPUT
);
857 knew
.get
= ca0132_hp_volume_get
;
858 knew
.put
= ca0132_hp_volume_put
;
859 return snd_hda_ctl_add(codec
, nid
, snd_ctl_new1(&knew
, codec
));
862 static int add_speaker_switch(struct hda_codec
*codec
, hda_nid_t nid
)
864 struct snd_kcontrol_new knew
=
865 HDA_CODEC_MUTE_MONO("Speaker Playback Switch",
866 nid
, 1, 0, HDA_OUTPUT
);
867 knew
.get
= ca0132_speaker_switch_get
;
868 knew
.put
= ca0132_speaker_switch_put
;
869 return snd_hda_ctl_add(codec
, nid
, snd_ctl_new1(&knew
, codec
));
872 static void ca0132_fix_hp_caps(struct hda_codec
*codec
)
874 struct ca0132_spec
*spec
= codec
->spec
;
875 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
878 /* set mute-capable, 1db step, 32 steps, ofs 6 */
880 snd_hda_override_amp_caps(codec
, cfg
->hp_pins
[0], HDA_OUTPUT
, caps
);
883 static int ca0132_build_controls(struct hda_codec
*codec
)
885 struct ca0132_spec
*spec
= codec
->spec
;
886 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
889 if (spec
->multiout
.num_dacs
) {
890 err
= add_speaker_switch(codec
, spec
->out_pins
[0]);
896 ca0132_fix_hp_caps(codec
);
897 err
= add_hp_switch(codec
, cfg
->hp_pins
[0]);
900 err
= add_hp_volume(codec
, cfg
->hp_pins
[0]);
905 for (i
= 0; i
< spec
->num_inputs
; i
++) {
906 const char *label
= spec
->input_labels
[i
];
908 err
= add_in_switch(codec
, spec
->adcs
[i
], label
);
911 err
= add_in_volume(codec
, spec
->adcs
[i
], label
);
914 if (cfg
->inputs
[i
].type
== AUTO_PIN_MIC
) {
916 err
= add_in_mono_volume(codec
, spec
->input_pins
[i
],
924 err
= snd_hda_create_spdif_out_ctls(codec
, spec
->dig_out
,
928 err
= add_out_volume(codec
, spec
->dig_out
, "IEC958");
934 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in
);
937 err
= add_in_volume(codec
, spec
->dig_in
, "IEC958");
943 static void ca0132_set_ct_ext(struct hda_codec
*codec
, int enable
)
945 /* Set Creative extension */
946 snd_printdd("SET CREATIVE EXTENSION\n");
947 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
948 VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE
,
954 static void ca0132_config(struct hda_codec
*codec
)
956 struct ca0132_spec
*spec
= codec
->spec
;
957 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
961 cfg
->line_out_pins
[0] = 0x0b; /* front */
962 cfg
->line_out_type
= AUTO_PIN_LINE_OUT
;
964 spec
->dacs
[0] = 0x02;
965 spec
->out_pins
[0] = 0x0b;
966 spec
->multiout
.dac_nids
= spec
->dacs
;
967 spec
->multiout
.num_dacs
= 1;
968 spec
->multiout
.max_channels
= 2;
972 cfg
->hp_pins
[0] = 0x0f;
975 spec
->multiout
.hp_nid
= 0;
978 cfg
->num_inputs
= 2; /* Mic-in and line-in */
979 cfg
->inputs
[0].pin
= 0x12;
980 cfg
->inputs
[0].type
= AUTO_PIN_MIC
;
981 cfg
->inputs
[1].pin
= 0x11;
982 cfg
->inputs
[1].type
= AUTO_PIN_LINE_IN
;
985 spec
->input_pins
[0] = 0x12;
986 spec
->input_labels
[0] = "Mic-In";
987 spec
->adcs
[0] = 0x07;
990 spec
->input_pins
[1] = 0x11;
991 spec
->input_labels
[1] = "Line-In";
992 spec
->adcs
[1] = 0x08;
993 spec
->num_inputs
= 2;
996 static void ca0132_init_chip(struct hda_codec
*codec
)
998 struct ca0132_spec
*spec
= codec
->spec
;
1000 mutex_init(&spec
->chipio_mutex
);
1003 static void ca0132_exit_chip(struct hda_codec
*codec
)
1005 /* put any chip cleanup stuffs here. */
1008 static int ca0132_init(struct hda_codec
*codec
)
1010 struct ca0132_spec
*spec
= codec
->spec
;
1011 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1014 for (i
= 0; i
< spec
->multiout
.num_dacs
; i
++) {
1015 init_output(codec
, spec
->out_pins
[i
],
1016 spec
->multiout
.dac_nids
[i
]);
1018 init_output(codec
, cfg
->hp_pins
[0], spec
->hp_dac
);
1019 init_output(codec
, cfg
->dig_out_pins
[0], spec
->dig_out
);
1021 for (i
= 0; i
< spec
->num_inputs
; i
++)
1022 init_input(codec
, spec
->input_pins
[i
], spec
->adcs
[i
]);
1024 init_input(codec
, cfg
->dig_in_pin
, spec
->dig_in
);
1026 ca0132_set_ct_ext(codec
, 1);
1032 static void ca0132_free(struct hda_codec
*codec
)
1034 ca0132_set_ct_ext(codec
, 0);
1035 ca0132_exit_chip(codec
);
1039 static struct hda_codec_ops ca0132_patch_ops
= {
1040 .build_controls
= ca0132_build_controls
,
1041 .build_pcms
= ca0132_build_pcms
,
1042 .init
= ca0132_init
,
1043 .free
= ca0132_free
,
1048 static int patch_ca0132(struct hda_codec
*codec
)
1050 struct ca0132_spec
*spec
;
1052 snd_printdd("patch_ca0132\n");
1054 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1059 ca0132_init_chip(codec
);
1061 ca0132_config(codec
);
1063 codec
->patch_ops
= ca0132_patch_ops
;
1071 static struct hda_codec_preset snd_hda_preset_ca0132
[] = {
1072 { .id
= 0x11020011, .name
= "CA0132", .patch
= patch_ca0132
},
1076 MODULE_ALIAS("snd-hda-codec-id:11020011");
1078 MODULE_LICENSE("GPL");
1079 MODULE_DESCRIPTION("Creative CA0132, CA0132 HD-audio codec");
1081 static struct hda_codec_preset_list ca0132_list
= {
1082 .preset
= snd_hda_preset_ca0132
,
1083 .owner
= THIS_MODULE
,
1086 static int __init
patch_ca0132_init(void)
1088 return snd_hda_add_codec_preset(&ca0132_list
);
1091 static void __exit
patch_ca0132_exit(void)
1093 snd_hda_delete_codec_preset(&ca0132_list
);
1096 module_init(patch_ca0132_init
)
1097 module_exit(patch_ca0132_exit
)