Lines Matching +full:chip +full:- +full:reset

1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Copyright (c) 2000-2004 Jaroslav Kysela <perex@perex.cz>,
18 #include <sound/ak4xxx-adda.h>
26 void snd_akm4xxx_write(struct snd_akm4xxx *ak, int chip, unsigned char reg, in snd_akm4xxx_write() argument
29 ak->ops.lock(ak, chip); in snd_akm4xxx_write()
30 ak->ops.write(ak, chip, reg, val); in snd_akm4xxx_write()
33 snd_akm4xxx_set(ak, chip, reg, val); in snd_akm4xxx_write()
34 ak->ops.unlock(ak, chip); in snd_akm4xxx_write()
39 /* reset procedure for AK4524 and AK4528 */
42 unsigned int chip; in ak4524_reset() local
45 for (chip = 0; chip < ak->num_dacs/2; chip++) { in ak4524_reset()
46 snd_akm4xxx_write(ak, chip, 0x01, state ? 0x00 : 0x03); in ak4524_reset()
50 for (reg = 0x04; reg < ak->total_regs; reg++) in ak4524_reset()
51 snd_akm4xxx_write(ak, chip, reg, in ak4524_reset()
52 snd_akm4xxx_get(ak, chip, reg)); in ak4524_reset()
56 /* reset procedure for AK4355 and AK4358 */
62 snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */ in ak435X_reset()
65 for (reg = 0x00; reg < ak->total_regs; reg++) in ak435X_reset()
69 snd_akm4xxx_write(ak, 0, 0x01, 0x01); /* un-reset, unmute */ in ak435X_reset()
72 /* reset procedure for AK4381 */
75 unsigned int chip; in ak4381_reset() local
77 for (chip = 0; chip < ak->num_dacs/2; chip++) { in ak4381_reset()
78 snd_akm4xxx_write(ak, chip, 0x00, state ? 0x0c : 0x0f); in ak4381_reset()
81 for (reg = 0x01; reg < ak->total_regs; reg++) in ak4381_reset()
82 snd_akm4xxx_write(ak, chip, reg, in ak4381_reset()
83 snd_akm4xxx_get(ak, chip, reg)); in ak4381_reset()
88 * reset the AKM codecs
89 * @state: 1 = reset codec, 0 = restore the registers
91 * assert the reset operation and restores the register values to the chips.
95 switch (ak->type) { in snd_akm4xxx_reset()
122 * Volume conversion table for non-linear volumes
123 * from -63.5dB (mute) to 0dB step 0.5dB
150 static const DECLARE_TLV_DB_SCALE(db_scale_vol_datt, -6350, 50, 1);
151 static const DECLARE_TLV_DB_SCALE(db_scale_8bit, -12750, 50, 1);
152 static const DECLARE_TLV_DB_SCALE(db_scale_7bit, -6350, 50, 1);
162 0x01, 0x00, /* 1: ADC/DAC reset */ in snd_akm4xxx_init()
174 0x01, 0x00, /* 1: ADC/DAC reset */ in snd_akm4xxx_init()
199 0x01, 0x02, /* 1: reset and soft-mute */ in snd_akm4xxx_init()
200 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect, in snd_akm4xxx_init()
201 * disable DZF, sharp roll-off, RSTN#=0 */ in snd_akm4xxx_init()
204 0x03, 0x01, /* 3: de-emphasis off */ in snd_akm4xxx_init()
212 0x01, 0x01, /* 1: un-reset, unmute */ in snd_akm4xxx_init()
216 0x01, 0x02, /* 1: reset and soft-mute */ in snd_akm4xxx_init()
217 0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect, in snd_akm4xxx_init()
218 * disable DZF, sharp roll-off, RSTN#=0 */ in snd_akm4xxx_init()
221 0x03, 0x01, /* 3: de-emphasis off */ in snd_akm4xxx_init()
231 0x01, 0x01, /* 1: un-reset, unmute */ in snd_akm4xxx_init()
235 0x00, 0x0c, /* 0: mode3(i2s), disable auto-clock detect */ in snd_akm4xxx_init()
236 0x01, 0x02, /* 1: de-emphasis off, normal speed, in snd_akm4xxx_init()
237 * sharp roll-off, DZF off */ in snd_akm4xxx_init()
242 0x00, 0x0f, /* 0: power-up, un-reset */ in snd_akm4xxx_init()
247 0x01, 0x00, /* 0: reset */ in snd_akm4xxx_init()
260 int chip; in snd_akm4xxx_init() local
264 memset(ak->images, 0, sizeof(ak->images)); in snd_akm4xxx_init()
265 memset(ak->volumes, 0, sizeof(ak->volumes)); in snd_akm4xxx_init()
267 switch (ak->type) { in snd_akm4xxx_init()
270 ak->num_chips = ak->num_dacs / 2; in snd_akm4xxx_init()
271 ak->name = "ak4524"; in snd_akm4xxx_init()
272 ak->total_regs = 0x08; in snd_akm4xxx_init()
276 ak->num_chips = ak->num_dacs / 2; in snd_akm4xxx_init()
277 ak->name = "ak4528"; in snd_akm4xxx_init()
278 ak->total_regs = 0x06; in snd_akm4xxx_init()
282 ak->num_chips = 1; in snd_akm4xxx_init()
283 ak->name = "ak4529"; in snd_akm4xxx_init()
284 ak->total_regs = 0x0d; in snd_akm4xxx_init()
288 ak->num_chips = 1; in snd_akm4xxx_init()
289 ak->name = "ak4355"; in snd_akm4xxx_init()
290 ak->total_regs = 0x0b; in snd_akm4xxx_init()
294 ak->num_chips = 1; in snd_akm4xxx_init()
295 ak->name = "ak4358"; in snd_akm4xxx_init()
296 ak->total_regs = 0x10; in snd_akm4xxx_init()
300 ak->num_chips = ak->num_dacs / 2; in snd_akm4xxx_init()
301 ak->name = "ak4381"; in snd_akm4xxx_init()
302 ak->total_regs = 0x05; in snd_akm4xxx_init()
306 ak->num_chips = 1; in snd_akm4xxx_init()
307 ak->name = "ak5365"; in snd_akm4xxx_init()
308 ak->total_regs = 0x08; in snd_akm4xxx_init()
312 ak->num_chips = ak->num_dacs / 2; in snd_akm4xxx_init()
313 ak->name = "ak4620"; in snd_akm4xxx_init()
314 ak->total_regs = 0x08; in snd_akm4xxx_init()
321 for (chip = 0; chip < ak->num_chips; chip++) { in snd_akm4xxx_init()
326 snd_akm4xxx_write(ak, chip, reg, data); in snd_akm4xxx_init()
349 #define AK_COMPOSE(chip,addr,shift,mask) \ argument
350 (((chip) << 8) | (addr) | ((shift) << 16) | ((mask) << 24))
355 unsigned int mask = AK_GET_MASK(kcontrol->private_value); in snd_akm4xxx_volume_info()
357 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_akm4xxx_volume_info()
358 uinfo->count = 1; in snd_akm4xxx_volume_info()
359 uinfo->value.integer.min = 0; in snd_akm4xxx_volume_info()
360 uinfo->value.integer.max = mask; in snd_akm4xxx_volume_info()
368 int chip = AK_GET_CHIP(kcontrol->private_value); in snd_akm4xxx_volume_get() local
369 int addr = AK_GET_ADDR(kcontrol->private_value); in snd_akm4xxx_volume_get()
371 ucontrol->value.integer.value[0] = snd_akm4xxx_get_vol(ak, chip, addr); in snd_akm4xxx_volume_get()
379 unsigned int mask = AK_GET_MASK(kcontrol->private_value); in put_ak_reg()
380 int chip = AK_GET_CHIP(kcontrol->private_value); in put_ak_reg() local
382 if (snd_akm4xxx_get_vol(ak, chip, addr) == nval) in put_ak_reg()
385 snd_akm4xxx_set_vol(ak, chip, addr, nval); in put_ak_reg()
386 if (AK_GET_VOL_CVT(kcontrol->private_value) && nval < 128) in put_ak_reg()
388 if (AK_GET_IPGA(kcontrol->private_value) && nval >= 128) in put_ak_reg()
390 if (AK_GET_INVERT(kcontrol->private_value)) in put_ak_reg()
391 nval = mask - nval; in put_ak_reg()
392 if (AK_GET_NEEDSMSB(kcontrol->private_value)) in put_ak_reg()
394 snd_akm4xxx_write(ak, chip, addr, nval); in put_ak_reg()
401 unsigned int mask = AK_GET_MASK(kcontrol->private_value); in snd_akm4xxx_volume_put()
402 unsigned int val = ucontrol->value.integer.value[0]; in snd_akm4xxx_volume_put()
404 return -EINVAL; in snd_akm4xxx_volume_put()
405 return put_ak_reg(kcontrol, AK_GET_ADDR(kcontrol->private_value), val); in snd_akm4xxx_volume_put()
411 unsigned int mask = AK_GET_MASK(kcontrol->private_value); in snd_akm4xxx_stereo_volume_info()
413 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_akm4xxx_stereo_volume_info()
414 uinfo->count = 2; in snd_akm4xxx_stereo_volume_info()
415 uinfo->value.integer.min = 0; in snd_akm4xxx_stereo_volume_info()
416 uinfo->value.integer.max = mask; in snd_akm4xxx_stereo_volume_info()
424 int chip = AK_GET_CHIP(kcontrol->private_value); in snd_akm4xxx_stereo_volume_get() local
425 int addr = AK_GET_ADDR(kcontrol->private_value); in snd_akm4xxx_stereo_volume_get()
427 ucontrol->value.integer.value[0] = snd_akm4xxx_get_vol(ak, chip, addr); in snd_akm4xxx_stereo_volume_get()
428 ucontrol->value.integer.value[1] = snd_akm4xxx_get_vol(ak, chip, addr+1); in snd_akm4xxx_stereo_volume_get()
435 int addr = AK_GET_ADDR(kcontrol->private_value); in snd_akm4xxx_stereo_volume_put()
436 unsigned int mask = AK_GET_MASK(kcontrol->private_value); in snd_akm4xxx_stereo_volume_put()
440 val[0] = ucontrol->value.integer.value[0]; in snd_akm4xxx_stereo_volume_put()
441 val[1] = ucontrol->value.integer.value[1]; in snd_akm4xxx_stereo_volume_put()
443 return -EINVAL; in snd_akm4xxx_stereo_volume_put()
462 int chip = AK_GET_CHIP(kcontrol->private_value); in snd_akm4xxx_deemphasis_get() local
463 int addr = AK_GET_ADDR(kcontrol->private_value); in snd_akm4xxx_deemphasis_get()
464 int shift = AK_GET_SHIFT(kcontrol->private_value); in snd_akm4xxx_deemphasis_get()
465 ucontrol->value.enumerated.item[0] = in snd_akm4xxx_deemphasis_get()
466 (snd_akm4xxx_get(ak, chip, addr) >> shift) & 3; in snd_akm4xxx_deemphasis_get()
474 int chip = AK_GET_CHIP(kcontrol->private_value); in snd_akm4xxx_deemphasis_put() local
475 int addr = AK_GET_ADDR(kcontrol->private_value); in snd_akm4xxx_deemphasis_put()
476 int shift = AK_GET_SHIFT(kcontrol->private_value); in snd_akm4xxx_deemphasis_put()
477 unsigned char nval = ucontrol->value.enumerated.item[0] & 3; in snd_akm4xxx_deemphasis_put()
481 (snd_akm4xxx_get(ak, chip, addr) & ~(3 << shift)); in snd_akm4xxx_deemphasis_put()
482 change = snd_akm4xxx_get(ak, chip, addr) != nval; in snd_akm4xxx_deemphasis_put()
484 snd_akm4xxx_write(ak, chip, addr, nval); in snd_akm4xxx_deemphasis_put()
494 int chip = AK_GET_CHIP(kcontrol->private_value); in ak4xxx_switch_get() local
495 int addr = AK_GET_ADDR(kcontrol->private_value); in ak4xxx_switch_get()
496 int shift = AK_GET_SHIFT(kcontrol->private_value); in ak4xxx_switch_get()
497 int invert = AK_GET_INVERT(kcontrol->private_value); in ak4xxx_switch_get()
499 unsigned char val = snd_akm4xxx_get(ak, chip, addr) & (1<<shift); in ak4xxx_switch_get()
502 ucontrol->value.integer.value[0] = (val & (1<<shift)) != 0; in ak4xxx_switch_get()
510 int chip = AK_GET_CHIP(kcontrol->private_value); in ak4xxx_switch_put() local
511 int addr = AK_GET_ADDR(kcontrol->private_value); in ak4xxx_switch_put()
512 int shift = AK_GET_SHIFT(kcontrol->private_value); in ak4xxx_switch_put()
513 int invert = AK_GET_INVERT(kcontrol->private_value); in ak4xxx_switch_put()
514 long flag = ucontrol->value.integer.value[0]; in ak4xxx_switch_put()
520 oval = snd_akm4xxx_get(ak, chip, addr); in ak4xxx_switch_put()
527 snd_akm4xxx_write(ak, chip, addr, val); in ak4xxx_switch_put()
538 input_names = ak->adc_info[mixer_ch].input_names; in ak4xxx_capture_num_inputs()
549 int mixer_ch = AK_GET_SHIFT(kcontrol->private_value); in ak4xxx_capture_source_info()
554 return -EINVAL; in ak4xxx_capture_source_info()
556 ak->adc_info[mixer_ch].input_names); in ak4xxx_capture_source_info()
563 int chip = AK_GET_CHIP(kcontrol->private_value); in ak4xxx_capture_source_get() local
564 int addr = AK_GET_ADDR(kcontrol->private_value); in ak4xxx_capture_source_get()
565 int mask = AK_GET_MASK(kcontrol->private_value); in ak4xxx_capture_source_get()
568 val = snd_akm4xxx_get(ak, chip, addr) & mask; in ak4xxx_capture_source_get()
569 ucontrol->value.enumerated.item[0] = val; in ak4xxx_capture_source_get()
577 int mixer_ch = AK_GET_SHIFT(kcontrol->private_value); in ak4xxx_capture_source_put()
578 int chip = AK_GET_CHIP(kcontrol->private_value); in ak4xxx_capture_source_put() local
579 int addr = AK_GET_ADDR(kcontrol->private_value); in ak4xxx_capture_source_put()
580 int mask = AK_GET_MASK(kcontrol->private_value); in ak4xxx_capture_source_put()
584 if (ucontrol->value.enumerated.item[0] >= num_names) in ak4xxx_capture_source_put()
585 return -EINVAL; in ak4xxx_capture_source_put()
587 oval = snd_akm4xxx_get(ak, chip, addr); in ak4xxx_capture_source_put()
589 val |= ucontrol->value.enumerated.item[0] & mask; in ak4xxx_capture_source_put()
591 snd_akm4xxx_write(ak, chip, addr, val); in ak4xxx_capture_source_put()
607 for (idx = 0; idx < ak->num_dacs; ) { in build_dac_controls()
608 /* mute control for Revolution 7.1 - AK4381 */ in build_dac_controls()
609 if (ak->type == SND_AK4381 in build_dac_controls()
610 && ak->dac_info[mixer_ch].switch_name) { in build_dac_controls()
615 knew.name = ak->dac_info[mixer_ch].switch_name; in build_dac_controls()
624 err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); in build_dac_controls()
629 if (! ak->dac_info || ! ak->dac_info[mixer_ch].name) { in build_dac_controls()
631 knew.index = mixer_ch + ak->idx_offset * 2; in build_dac_controls()
634 knew.name = ak->dac_info[mixer_ch].name; in build_dac_controls()
635 num_stereo = ak->dac_info[mixer_ch].num_channels; in build_dac_controls()
650 switch (ak->type) { in build_dac_controls()
666 /* registers 2-7 and b,c */ in build_dac_controls()
667 int val = idx < 6 ? idx + 2 : (idx - 6) + 0xb; in build_dac_controls()
674 /* register 4-9, chip #0 only */ in build_dac_controls()
679 /* register 4-9 and 11-12, chip #0 only */ in build_dac_controls()
699 return -EINVAL; in build_dac_controls()
702 err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); in build_dac_controls()
718 if (ak->type == SND_AK4528) in build_adc_controls()
720 for (idx = 0; idx < ak->num_adcs;) { in build_adc_controls()
722 if (! ak->adc_info || ! ak->adc_info[mixer_ch].name) { in build_adc_controls()
724 knew.index = mixer_ch + ak->idx_offset * 2; in build_adc_controls()
727 knew.name = ak->adc_info[mixer_ch].name; in build_adc_controls()
728 num_stereo = ak->adc_info[mixer_ch].num_channels; in build_adc_controls()
744 if (ak->type == SND_AK5365) in build_adc_controls()
752 err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); in build_adc_controls()
756 if (ak->type == SND_AK5365 && (idx % 2) == 0) { in build_adc_controls()
757 if (! ak->adc_info || in build_adc_controls()
758 ! ak->adc_info[mixer_ch].switch_name) { in build_adc_controls()
760 knew.index = mixer_ch + ak->idx_offset * 2; in build_adc_controls()
762 knew.name = ak->adc_info[mixer_ch].switch_name; in build_adc_controls()
771 err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); in build_adc_controls()
776 if (!ak->adc_info || in build_adc_controls()
777 !ak->adc_info[mixer_ch].selector_name) { in build_adc_controls()
779 knew.index = mixer_ch + ak->idx_offset * 2; in build_adc_controls()
781 knew.name = ak->adc_info[mixer_ch].selector_name; in build_adc_controls()
788 /* input selector control: reg. 1, bits 0-2. in build_adc_controls()
789 * mis-use 'shift' to pass mixer_ch */ in build_adc_controls()
792 err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); in build_adc_controls()
811 knew.index = idx + ak->idx_offset; in build_deemphasis()
817 switch (ak->type) { in build_deemphasis()
825 int shift = idx == 3 ? 6 : (2 - idx) * 2; in build_deemphasis()
838 return -EINVAL; in build_deemphasis()
840 err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); in build_deemphasis()
850 struct snd_akm4xxx *ak = entry->private_data; in proc_regs_read()
851 int reg, val, chip; in proc_regs_read() local
852 for (chip = 0; chip < ak->num_chips; chip++) { in proc_regs_read()
853 for (reg = 0; reg < ak->total_regs; reg++) { in proc_regs_read()
854 val = snd_akm4xxx_get(ak, chip, reg); in proc_regs_read()
855 snd_iprintf(buffer, "chip %d: 0x%02x = 0x%02x\n", chip, in proc_regs_read()
863 return snd_card_ro_proc_new(ak->card, ak->name, ak, proc_regs_read); in proc_init()
877 if (ak->type == SND_AK4355 || ak->type == SND_AK4358) in snd_akm4xxx_build_controls()
879 else if (ak->type == SND_AK4620) in snd_akm4xxx_build_controls()
882 num_emphs = ak->num_dacs / 2; in snd_akm4xxx_build_controls()