28 #include <linux/module.h>
43 ak->
ops.lock(ak, chip);
44 ak->
ops.write(ak, chip, reg, val);
48 ak->
ops.unlock(ak, chip);
59 for (chip = 0; chip < ak->
num_dacs/2; chip++) {
71 static void ak435X_reset(
struct snd_akm4xxx *ak,
int state)
87 static void ak4381_reset(
struct snd_akm4xxx *ak,
int state)
91 for (chip = 0; chip < ak->
num_dacs/2; chip++) {
113 ak4524_reset(ak, state);
119 ak435X_reset(ak, state);
122 ak435X_reset(ak, state);
125 ak4381_reset(ak, state);
142 static const unsigned char vol_cvt_datt[128] = {
143 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04,
144 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x06, 0x06,
145 0x06, 0x07, 0x07, 0x08, 0x08, 0x08, 0x09, 0x0a,
146 0x0a, 0x0b, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x0f,
147 0x10, 0x10, 0x11, 0x12, 0x12, 0x13, 0x13, 0x14,
148 0x15, 0x16, 0x17, 0x17, 0x18, 0x19, 0x1a, 0x1c,
149 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x23,
150 0x24, 0x25, 0x26, 0x28, 0x29, 0x2a, 0x2b, 0x2d,
151 0x2e, 0x30, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
152 0x37, 0x38, 0x39, 0x3b, 0x3c, 0x3e, 0x3f, 0x40,
153 0x41, 0x42, 0x43, 0x44, 0x46, 0x47, 0x48, 0x4a,
154 0x4b, 0x4d, 0x4e, 0x50, 0x51, 0x52, 0x53, 0x54,
155 0x55, 0x56, 0x58, 0x59, 0x5b, 0x5c, 0x5e, 0x5f,
156 0x60, 0x61, 0x62, 0x64, 0x65, 0x66, 0x67, 0x69,
157 0x6a, 0x6c, 0x6d, 0x6f, 0x70, 0x71, 0x72, 0x73,
158 0x75, 0x76, 0x77, 0x79, 0x7a, 0x7c, 0x7d, 0x7f,
174 static const unsigned char inits_ak4524[] = {
186 static const unsigned char inits_ak4528[] = {
196 static const unsigned char inits_ak4529[] = {
212 static const unsigned char inits_ak4355[] = {
229 static const unsigned char inits_ak4358[] = {
248 static const unsigned char inits_ak4381[] = {
259 static const unsigned char inits_ak4620[] = {
275 const unsigned char *
ptr, *inits;
283 inits = inits_ak4524;
289 inits = inits_ak4528;
295 inits = inits_ak4529;
301 inits = inits_ak4355;
307 inits = inits_ak4358;
313 inits = inits_ak4381;
325 inits = inits_ak4620;
335 for (chip = 0; chip < ak->
num_chips; chip++) {
337 while (*ptr != 0xff) {
351 #define AK_IPGA (1<<20)
352 #define AK_VOL_CVT (1<<21)
353 #define AK_NEEDSMSB (1<<22)
354 #define AK_INVERT (1<<23)
355 #define AK_GET_CHIP(val) (((val) >> 8) & 0xff)
356 #define AK_GET_ADDR(val) ((val) & 0xff)
357 #define AK_GET_SHIFT(val) (((val) >> 16) & 0x0f)
358 #define AK_GET_VOL_CVT(val) (((val) >> 21) & 1)
359 #define AK_GET_IPGA(val) (((val) >> 20) & 1)
360 #define AK_GET_NEEDSMSB(val) (((val) >> 22) & 1)
361 #define AK_GET_INVERT(val) (((val) >> 23) & 1)
362 #define AK_GET_MASK(val) (((val) >> 24) & 0xff)
363 #define AK_COMPOSE(chip,addr,shift,mask) \
364 (((chip) << 8) | (addr) | ((shift) << 16) | ((mask) << 24))
366 static int snd_akm4xxx_volume_info(
struct snd_kcontrol *kcontrol,
378 static int snd_akm4xxx_volume_get(
struct snd_kcontrol *kcontrol,
401 nval = vol_cvt_datt[nval];
414 static int snd_akm4xxx_volume_put(
struct snd_kcontrol *kcontrol,
418 unsigned int val = ucontrol->
value.integer.value[0];
424 static int snd_akm4xxx_stereo_volume_info(
struct snd_kcontrol *kcontrol,
436 static int snd_akm4xxx_stereo_volume_get(
struct snd_kcontrol *kcontrol,
448 static int snd_akm4xxx_stereo_volume_put(
struct snd_kcontrol *kcontrol,
456 val[0] = ucontrol->
value.integer.value[0];
457 val[1] = ucontrol->
value.integer.value[1];
458 if (val[0] > mask || val[1] > mask)
460 change = put_ak_reg(kcontrol, addr, val[0]);
461 change |= put_ak_reg(kcontrol, addr + 1, val[1]);
465 static int snd_akm4xxx_deemphasis_info(
struct snd_kcontrol *kcontrol,
468 static char *texts[4] = {
469 "44.1kHz",
"Off",
"48kHz",
"32kHz",
481 static int snd_akm4xxx_deemphasis_get(
struct snd_kcontrol *kcontrol,
488 ucontrol->
value.enumerated.item[0] =
493 static int snd_akm4xxx_deemphasis_put(
struct snd_kcontrol *kcontrol,
500 unsigned char nval = ucontrol->
value.enumerated.item[0] & 3;
503 nval = (nval << shift) |
511 #define ak4xxx_switch_info snd_ctl_boolean_mono_info
513 static int ak4xxx_switch_get(
struct snd_kcontrol *kcontrol,
525 ucontrol->
value.integer.value[0] = (val & (1<<shift)) != 0;
529 static int ak4xxx_switch_put(
struct snd_kcontrol *kcontrol,
537 long flag = ucontrol->
value.integer.value[0];
538 unsigned char val, oval;
545 val = oval | (1<<shift);
547 val = oval & ~(1<<shift);
548 change = (oval !=
val);
554 #define AK5365_NUM_INPUTS 5
556 static int ak4xxx_capture_num_inputs(
struct snd_akm4xxx *ak,
int mixer_ch)
559 const char **input_names;
561 input_names = ak->
adc_info[mixer_ch].input_names;
568 static int ak4xxx_capture_source_info(
struct snd_kcontrol *kcontrol,
573 const char **input_names;
576 num_names = ak4xxx_capture_num_inputs(ak, mixer_ch);
583 if (idx >= num_names)
585 input_names = ak->
adc_info[mixer_ch].input_names;
591 static int ak4xxx_capture_source_get(
struct snd_kcontrol *kcontrol,
601 ucontrol->
value.enumerated.item[0] =
val;
605 static int ak4xxx_capture_source_put(
struct snd_kcontrol *kcontrol,
613 unsigned char oval,
val;
614 int num_names = ak4xxx_capture_num_inputs(ak, mixer_ch);
616 if (ucontrol->
value.enumerated.item[0] >= num_names)
621 val |= ucontrol->
value.enumerated.item[0] &
mask;
633 static int build_dac_controls(
struct snd_akm4xxx *ak)
635 int idx,
err, mixer_ch, num_stereo;
639 for (idx = 0; idx < ak->
num_dacs; ) {
641 if (ak->
type == SND_AK4381
642 && ak->
dac_info[mixer_ch].switch_name) {
643 memset(&knew, 0,
sizeof(knew));
647 knew.name = ak->
dac_info[mixer_ch].switch_name;
649 knew.get = ak4xxx_switch_get;
650 knew.put = ak4xxx_switch_put;
660 memset(&knew, 0,
sizeof(knew));
662 knew.name =
"DAC Volume";
666 knew.name = ak->
dac_info[mixer_ch].name;
667 num_stereo = ak->
dac_info[mixer_ch].num_channels;
673 if (num_stereo == 2) {
674 knew.info = snd_akm4xxx_stereo_volume_info;
675 knew.get = snd_akm4xxx_stereo_volume_get;
676 knew.put = snd_akm4xxx_stereo_volume_put;
678 knew.info = snd_akm4xxx_volume_info;
679 knew.get = snd_akm4xxx_volume_get;
680 knew.put = snd_akm4xxx_volume_put;
688 knew.tlv.p = db_scale_vol_datt;
695 knew.tlv.p = db_scale_vol_datt;
699 int val = idx < 6 ? idx + 2 : (idx - 6) + 0
xb;
702 knew.tlv.p = db_scale_8bit;
707 knew.private_value =
AK_COMPOSE(0, idx + 4, 0, 255);
708 knew.tlv.p = db_scale_8bit;
712 int addr = idx < 6 ? idx + 4 : idx + 5;
715 knew.tlv.p = db_scale_7bit;
722 knew.tlv.p = db_scale_linear;
728 knew.tlv.p = db_scale_linear;
744 static int build_adc_controls(
struct snd_akm4xxx *ak)
746 int idx,
err, mixer_ch, num_stereo, max_steps;
750 if (ak->
type == SND_AK4528)
752 for (idx = 0; idx < ak->
num_adcs;) {
753 memset(&knew, 0,
sizeof(knew));
755 knew.name =
"ADC Volume";
759 knew.name = ak->
adc_info[mixer_ch].name;
760 num_stereo = ak->
adc_info[mixer_ch].num_channels;
766 if (num_stereo == 2) {
767 knew.info = snd_akm4xxx_stereo_volume_info;
768 knew.get = snd_akm4xxx_stereo_volume_get;
769 knew.put = snd_akm4xxx_stereo_volume_put;
771 knew.info = snd_akm4xxx_volume_info;
772 knew.get = snd_akm4xxx_volume_get;
773 knew.put = snd_akm4xxx_volume_put;
776 if (ak->
type == SND_AK5365)
781 AK_COMPOSE(idx/2, (idx%2) + 4, 0, max_steps) |
783 knew.tlv.p = db_scale_vol_datt;
788 if (ak->
type == SND_AK5365 && (idx % 2) == 0) {
790 ! ak->
adc_info[mixer_ch].switch_name) {
791 knew.name =
"Capture Switch";
794 knew.name = ak->
adc_info[mixer_ch].switch_name;
796 knew.get = ak4xxx_switch_get;
797 knew.put = ak4xxx_switch_put;
807 memset(&knew, 0,
sizeof(knew));
808 knew.name = ak->
adc_info[mixer_ch].selector_name;
810 knew.name =
"Capture Channel";
815 knew.info = ak4xxx_capture_source_info;
816 knew.get = ak4xxx_capture_source_get;
817 knew.put = ak4xxx_capture_source_put;
834 static int build_deemphasis(
struct snd_akm4xxx *ak,
int num_emphs)
839 for (idx = 0; idx < num_emphs; idx++) {
840 memset(&knew, 0,
sizeof(knew));
841 knew.name =
"Deemphasis";
845 knew.info = snd_akm4xxx_deemphasis_info;
846 knew.get = snd_akm4xxx_deemphasis_get;
847 knew.put = snd_akm4xxx_deemphasis_put;
853 knew.private_value =
AK_COMPOSE(idx, 3, 0, 0);
856 int shift = idx == 3 ? 6 : (2 -
idx) * 2;
858 knew.private_value =
AK_COMPOSE(0, 8, shift, 0);
863 knew.private_value =
AK_COMPOSE(idx, 3, 0, 0);
866 knew.private_value =
AK_COMPOSE(idx, 1, 1, 0);
878 #ifdef CONFIG_PROC_FS
884 for (chip = 0; chip < ak->
num_chips; chip++) {
887 snd_iprintf(buffer,
"chip %d: 0x%02x = 0x%02x\n", chip,
897 err = snd_card_proc_new(ak->
card, ak->
name, &entry);
900 snd_info_set_text_ops(entry, ak, proc_regs_read);
904 static int proc_init(
struct snd_akm4xxx *ak) {
return 0; }
911 err = build_dac_controls(ak);
915 err = build_adc_controls(ak);
918 if (ak->
type == SND_AK4355 || ak->
type == SND_AK4358)
920 else if (ak->
type == SND_AK4620)
924 err = build_deemphasis(ak, num_emphs);
935 static int __init alsa_akm4xxx_module_init(
void)
940 static void __exit alsa_akm4xxx_module_exit(
void)