26 #include <linux/slab.h>
27 #include <linux/pci.h>
29 #include <linux/module.h>
35 #define WIDGET_CHIP_CTRL 0x15
36 #define WIDGET_DSP_CTRL 0x16
38 #define WUH_MEM_CONNID 10
39 #define DSP_MEM_CONNID 16
243 snd_hda_set_pin_ctl(codec, pin,
PIN_HP);
257 snd_hda_set_pin_ctl(codec, pin,
PIN_IN |
264 if (adc && (get_wcaps(codec, adc) & AC_WCAP_IN_AMP))
269 static char *dirstr[2] = {
"Playback",
"Capture" };
279 snd_printdd(
"Skipping '%s %s Switch' (no mute on node 0x%x)\n", pfx, dirstr[dir], nid);
282 sprintf(namestr,
"%s %s Switch", pfx, dirstr[dir]);
294 snd_printdd(
"Skipping '%s %s Volume' (no amp on node 0x%x)\n", pfx, dirstr[dir], nid);
297 sprintf(namestr,
"%s %s Volume", pfx, dirstr[dir]);
301 #define add_out_switch(codec, nid, pfx) _add_switch(codec, nid, pfx, 3, 0)
302 #define add_out_volume(codec, nid, pfx) _add_volume(codec, nid, pfx, 3, 0)
303 #define add_in_switch(codec, nid, pfx) _add_switch(codec, nid, pfx, 3, 1)
304 #define add_in_volume(codec, nid, pfx) _add_volume(codec, nid, pfx, 3, 1)
305 #define add_mono_switch(codec, nid, pfx, chan) \
306 _add_switch(codec, nid, pfx, chan, 0)
307 #define add_mono_volume(codec, nid, pfx, chan) \
308 _add_volume(codec, nid, pfx, chan, 0)
309 #define add_in_mono_switch(codec, nid, pfx, chan) \
310 _add_switch(codec, nid, pfx, chan, 1)
311 #define add_in_mono_volume(codec, nid, pfx, chan) \
312 _add_volume(codec, nid, pfx, chan, 1)
339 static int chipio_send(
struct hda_codec *codec,
359 static int chipio_write_address(
struct hda_codec *codec,
360 unsigned int chip_addx)
381 static int chipio_write_data(
struct hda_codec *codec,
unsigned int data)
400 static int chipio_read_data(
struct hda_codec *codec,
unsigned int *data)
426 static int chipio_write(
struct hda_codec *codec,
427 unsigned int chip_addx,
const unsigned int data)
435 err = chipio_write_address(codec, chip_addx);
439 err = chipio_write_data(codec, data);
452 static int chipio_read(
struct hda_codec *codec,
453 unsigned int chip_addx,
unsigned int *data)
461 err = chipio_write_address(codec, chip_addx);
465 err = chipio_read_data(codec, data);
486 static int ca0132_playback_pcm_prepare(
struct hda_pcm_stream *hinfo,
488 unsigned int stream_tag,
494 stream_tag, format, substream);
497 static int ca0132_playback_pcm_cleanup(
struct hda_pcm_stream *hinfo,
508 static int ca0132_dig_playback_pcm_open(
struct hda_pcm_stream *hinfo,
516 static int ca0132_dig_playback_pcm_prepare(
struct hda_pcm_stream *hinfo,
518 unsigned int stream_tag,
524 stream_tag, format, substream);
527 static int ca0132_dig_playback_pcm_cleanup(
struct hda_pcm_stream *hinfo,
535 static int ca0132_dig_playback_pcm_close(
struct hda_pcm_stream *hinfo,
550 .open = ca0132_playback_pcm_open,
551 .prepare = ca0132_playback_pcm_prepare,
552 .cleanup = ca0132_playback_pcm_cleanup
567 .open = ca0132_dig_playback_pcm_open,
568 .close = ca0132_dig_playback_pcm_close,
569 .prepare = ca0132_dig_playback_pcm_prepare,
570 .cleanup = ca0132_dig_playback_pcm_cleanup
580 static int ca0132_build_pcms(
struct hda_codec *codec)
588 info->
name =
"CA0132 Analog";
602 info->
name =
"CA0132 Digital";
606 ca0132_pcm_digital_playback;
611 ca0132_pcm_digital_capture;
619 #define REG_CODEC_MUTE 0x18b014
620 #define REG_CODEC_HP_VOL_L 0x18b070
621 #define REG_CODEC_HP_VOL_R 0x18b074
623 static int ca0132_hp_switch_get(
struct snd_kcontrol *kcontrol,
628 long *valp = ucontrol->
value.integer.value;
634 static int ca0132_hp_switch_put(
struct snd_kcontrol *kcontrol,
639 long *valp = ucontrol->
value.integer.value;
647 snd_hda_power_up(codec);
654 data = (data & 0x7f) | (*valp ? 0 : 0x80);
662 snd_hda_power_down(codec);
663 return err < 0 ? err : 1;
666 static int ca0132_speaker_switch_get(
struct snd_kcontrol *kcontrol,
671 long *valp = ucontrol->
value.integer.value;
677 static int ca0132_speaker_switch_put(
struct snd_kcontrol *kcontrol,
682 long *valp = ucontrol->
value.integer.value;
690 snd_hda_power_up(codec);
697 data = (data & 0xef) | (*valp ? 0 : 0x10);
705 snd_hda_power_down(codec);
706 return err < 0 ? err : 1;
709 static int ca0132_hp_volume_get(
struct snd_kcontrol *kcontrol,
714 long *valp = ucontrol->
value.integer.value;
721 static int ca0132_hp_volume_put(
struct snd_kcontrol *kcontrol,
726 long *valp = ucontrol->
value.integer.value;
727 long left_vol, right_vol;
740 snd_hda_power_up(codec);
747 data = (data & 0xe0) | val;
752 val = 31 - right_vol;
753 data = (data & 0xe0) | val;
762 snd_hda_power_down(codec);
763 return err < 0 ? err : 1;
771 knew.
get = ca0132_hp_switch_get;
772 knew.
put = ca0132_hp_switch_put;
781 knew.
get = ca0132_hp_volume_get;
782 knew.
put = ca0132_hp_volume_put;
791 knew.
get = ca0132_speaker_switch_get;
792 knew.
put = ca0132_speaker_switch_put;
796 static void ca0132_fix_hp_caps(
struct hda_codec *codec)
807 static int ca0132_build_controls(
struct hda_codec *codec)
814 err = add_speaker_switch(codec, spec->
out_pins[0]);
820 ca0132_fix_hp_caps(codec);
821 err = add_hp_switch(codec, cfg->
hp_pins[0]);
824 err = add_hp_volume(codec, cfg->
hp_pins[0]);
878 static void ca0132_config(
struct hda_codec *codec)
891 spec->
dacs[0] = 0x02;
906 cfg->
inputs[0].pin = 0x12;
908 cfg->
inputs[1].pin = 0x11;
914 spec->
adcs[0] = 0x07;
919 spec->
adcs[1] = 0x08;
933 static void ca0132_init_chip(
struct hda_codec *codec)
940 static void ca0132_exit_chip(
struct hda_codec *codec)
945 static int ca0132_init(
struct hda_codec *codec)
951 for (i = 0; i < spec->
multiout.num_dacs; i++) {
952 init_output(codec, spec->
out_pins[i],
963 ca0132_set_ct_ext(codec, 1);
969 static void ca0132_free(
struct hda_codec *codec)
971 ca0132_set_ct_ext(codec, 0);
972 ca0132_exit_chip(codec);
977 .build_controls = ca0132_build_controls,
978 .build_pcms = ca0132_build_pcms,
985 static int patch_ca0132(
struct hda_codec *codec)
996 ca0132_init_chip(codec);
998 ca0132_config(codec);
1009 { .id = 0x11020011, .name =
"CA0132", .patch = patch_ca0132 },
1019 .preset = snd_hda_preset_ca0132,
1023 static int __init patch_ca0132_init(
void)
1028 static void __exit patch_ca0132_exit(
void)