Lines Matching +full:audio +full:- +full:gain +full:- +full:db

1 // SPDX-License-Identifier: GPL-2.0
21 u16 gain; member
28 u8 spi_tx_buf; /* Cannot use stack area for SPI (dma-safe memory) */
29 u8 spi_rx_buf; /* Cannot use stack area for SPI (dma-safe memory) */
55 .tx_buf = &idt821034->spi_tx_buf, in idt821034_8bit_write()
59 .tx_buf = &idt821034->spi_tx_buf, in idt821034_8bit_write()
64 idt821034->spi_tx_buf = val; in idt821034_8bit_write()
66 dev_vdbg(&idt821034->spi->dev, "spi xfer wr 0x%x\n", val); in idt821034_8bit_write()
68 return spi_sync_transfer(idt821034->spi, xfer, 2); in idt821034_8bit_write()
85 .tx_buf = &idt821034->spi_tx_buf, in idt821034_8bit_read()
86 .rx_buf = &idt821034->spi_rx_buf, in idt821034_8bit_read()
90 .tx_buf = &idt821034->spi_tx_buf, in idt821034_8bit_read()
96 idt821034->spi_tx_buf = valw; in idt821034_8bit_read()
98 ret = spi_sync_transfer(idt821034->spi, xfer, 2); in idt821034_8bit_read()
102 *valr = idt821034->spi_rx_buf; in idt821034_8bit_read()
104 dev_vdbg(&idt821034->spi->dev, "spi xfer wr 0x%x, rd 0x%x\n", in idt821034_8bit_read()
124 dev_dbg(&idt821034->spi->dev, "set_channel_power(%u, 0x%x)\n", ch, power); in idt821034_set_channel_power()
126 conf = IDT821034_MODE_CODEC(ch) | idt821034->cache.codec_conf; in idt821034_set_channel_power()
131 idt821034->cache.ch[ch].rx_slot); in idt821034_set_channel_power()
138 idt821034->cache.ch[ch].tx_slot); in idt821034_set_channel_power()
148 idt821034->cache.ch[ch].power = power; in idt821034_set_channel_power()
155 return idt821034->cache.ch[ch].power; in idt821034_get_channel_power()
168 dev_dbg(&idt821034->spi->dev, "set_codec_conf(0x%x)\n", codec_conf); in idt821034_set_codec_conf()
180 if (idt821034->cache.ch[0].power & IDT821034_CONF_PWRUP_RX) { in idt821034_set_codec_conf()
182 ts = idt821034->cache.ch[0].rx_slot; in idt821034_set_codec_conf()
183 } else if (idt821034->cache.ch[0].power & IDT821034_CONF_PWRUP_TX) { in idt821034_set_codec_conf()
185 ts = idt821034->cache.ch[0].tx_slot; in idt821034_set_codec_conf()
190 /* Write configuration register and time-slot register */ in idt821034_set_codec_conf()
195 idt821034->cache.codec_conf = codec_conf; in idt821034_set_codec_conf()
201 return idt821034->cache.codec_conf; in idt821034_get_codec_conf()
213 dev_dbg(&idt821034->spi->dev, "set_channel_ts(%u, 0x%x, %d)\n", ch, ch_dir, ts_num); in idt821034_set_channel_ts()
215 conf = IDT821034_MODE_CODEC(ch) | idt821034->cache.codec_conf; in idt821034_set_channel_ts()
218 if (idt821034->cache.ch[ch].power & IDT821034_CONF_PWRUP_RX) { in idt821034_set_channel_ts()
225 idt821034->cache.ch[ch].rx_slot = ts_num; in idt821034_set_channel_ts()
228 if (idt821034->cache.ch[ch].power & IDT821034_CONF_PWRUP_TX) { in idt821034_set_channel_ts()
235 idt821034->cache.ch[ch].tx_slot = ts_num; in idt821034_set_channel_ts()
250 dev_dbg(&idt821034->spi->dev, "set_slic_conf(%u, 0x%x)\n", ch, slic_dir); in idt821034_set_slic_conf()
253 ret = idt821034_2x8bit_write(idt821034, conf, idt821034->cache.ch[ch].slic_control); in idt821034_set_slic_conf()
257 idt821034->cache.ch[ch].slic_conf = slic_dir; in idt821034_set_slic_conf()
264 return idt821034->cache.ch[ch].slic_conf; in idt821034_get_slic_conf()
272 dev_dbg(&idt821034->spi->dev, "write_slic_raw(%u, 0x%x)\n", ch, slic_raw); in idt821034_write_slic_raw()
283 conf = IDT821034_MODE_SLIC(ch) | idt821034->cache.ch[ch].slic_conf; in idt821034_write_slic_raw()
288 idt821034->cache.ch[ch].slic_control = slic_raw; in idt821034_write_slic_raw()
294 return idt821034->cache.ch[ch].slic_control; in idt821034_get_written_slic_raw()
314 val = IDT821034_MODE_SLIC(ch) | idt821034->cache.ch[ch].slic_conf; in idt821034_read_slic_raw()
319 ret = idt821034_8bit_read(idt821034, idt821034->cache.ch[ch].slic_control, slic_raw); in idt821034_read_slic_raw()
323 dev_dbg(&idt821034->spi->dev, "read_slic_raw(%i) 0x%x\n", ch, *slic_raw); in idt821034_read_slic_raw()
328 /* Gain type values that can be used in 'gain_type' (cannot be ORed) */
338 dev_dbg(&idt821034->spi->dev, "set_gain_channel(%u, 0x%x, 0x%x-%d)\n", in idt821034_set_gain_channel()
342 * The gain programming coefficients should be calculated as: in idt821034_set_gain_channel()
347 * gain_X is the target gain; in idt821034_set_gain_channel()
350 * gain_R is the target gain; in idt821034_set_gain_channel()
353 * A gain programming coefficient is 14-bit wide and in binary format. in idt821034_set_gain_channel()
361 * coefficient. To program a +3 dB gain in transmit path and a -3.5 dB in idt821034_set_gain_channel()
362 * gain in receive path: in idt821034_set_gain_channel()
364 * Linear Code of +3dB = 10^(3/20)= 1.412537545 in idt821034_set_gain_channel()
370 * Linear Code of -3.5dB = 10^(-3.5/20) = 0.668343917 in idt821034_set_gain_channel()
404 struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; in idt821034_kctrl_gain_get()
407 int min = mc->min; in idt821034_kctrl_gain_get()
408 int max = mc->max; in idt821034_kctrl_gain_get()
409 unsigned int mask = (1 << fls(max)) - 1; in idt821034_kctrl_gain_get()
410 unsigned int invert = mc->invert; in idt821034_kctrl_gain_get()
414 ch = IDT821034_ID_GET_CHAN(mc->reg); in idt821034_kctrl_gain_get()
416 mutex_lock(&idt821034->mutex); in idt821034_kctrl_gain_get()
417 if (IDT821034_ID_IS_OUT(mc->reg)) in idt821034_kctrl_gain_get()
418 val = idt821034->amps.ch[ch].amp_out.gain; in idt821034_kctrl_gain_get()
420 val = idt821034->amps.ch[ch].amp_in.gain; in idt821034_kctrl_gain_get()
421 mutex_unlock(&idt821034->mutex); in idt821034_kctrl_gain_get()
423 ucontrol->value.integer.value[0] = val & mask; in idt821034_kctrl_gain_get()
425 ucontrol->value.integer.value[0] = max - ucontrol->value.integer.value[0]; in idt821034_kctrl_gain_get()
427 ucontrol->value.integer.value[0] = ucontrol->value.integer.value[0] - min; in idt821034_kctrl_gain_get()
435 struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; in idt821034_kctrl_gain_put()
439 int min = mc->min; in idt821034_kctrl_gain_put()
440 int max = mc->max; in idt821034_kctrl_gain_put()
441 unsigned int mask = (1 << fls(max)) - 1; in idt821034_kctrl_gain_put()
442 unsigned int invert = mc->invert; in idt821034_kctrl_gain_put()
448 val = ucontrol->value.integer.value[0]; in idt821034_kctrl_gain_put()
449 if (val > max - min) in idt821034_kctrl_gain_put()
450 return -EINVAL; in idt821034_kctrl_gain_put()
453 val = (max - val) & mask; in idt821034_kctrl_gain_put()
457 ch = IDT821034_ID_GET_CHAN(mc->reg); in idt821034_kctrl_gain_put()
459 mutex_lock(&idt821034->mutex); in idt821034_kctrl_gain_put()
461 if (IDT821034_ID_IS_OUT(mc->reg)) { in idt821034_kctrl_gain_put()
462 amp = &idt821034->amps.ch[ch].amp_out; in idt821034_kctrl_gain_put()
465 amp = &idt821034->amps.ch[ch].amp_in; in idt821034_kctrl_gain_put()
469 if (amp->gain == val) { in idt821034_kctrl_gain_put()
474 if (!amp->is_muted) { in idt821034_kctrl_gain_put()
480 amp->gain = val; in idt821034_kctrl_gain_put()
483 mutex_unlock(&idt821034->mutex); in idt821034_kctrl_gain_put()
492 int id = kcontrol->private_value; in idt821034_kctrl_mute_get()
498 mutex_lock(&idt821034->mutex); in idt821034_kctrl_mute_get()
500 idt821034->amps.ch[ch].amp_out.is_muted : in idt821034_kctrl_mute_get()
501 idt821034->amps.ch[ch].amp_in.is_muted; in idt821034_kctrl_mute_get()
502 mutex_unlock(&idt821034->mutex); in idt821034_kctrl_mute_get()
504 ucontrol->value.integer.value[0] = !is_muted; in idt821034_kctrl_mute_get()
514 int id = kcontrol->private_value; in idt821034_kctrl_mute_put()
522 is_mute = !ucontrol->value.integer.value[0]; in idt821034_kctrl_mute_put()
524 mutex_lock(&idt821034->mutex); in idt821034_kctrl_mute_put()
527 amp = &idt821034->amps.ch[ch].amp_out; in idt821034_kctrl_mute_put()
530 amp = &idt821034->amps.ch[ch].amp_in; in idt821034_kctrl_mute_put()
534 if (amp->is_muted == is_mute) { in idt821034_kctrl_mute_put()
540 is_mute ? 0 : amp->gain); in idt821034_kctrl_mute_put()
544 amp->is_muted = is_mute; in idt821034_kctrl_mute_put()
547 mutex_unlock(&idt821034->mutex); in idt821034_kctrl_mute_put()
551 static const DECLARE_TLV_DB_LINEAR(idt821034_gain_in, -6520, 1306);
552 #define IDT821034_GAIN_IN_MIN_RAW 1 /* -65.20 dB -> 10^(-65.2/20.0) * 1820 = 1 */
553 #define IDT821034_GAIN_IN_MAX_RAW 8191 /* 13.06 dB -> 10^(13.06/20.0) * 1820 = 8191 */
554 #define IDT821034_GAIN_IN_INIT_RAW 1820 /* 0dB -> 10^(0/20) * 1820 = 1820 */
556 static const DECLARE_TLV_DB_LINEAR(idt821034_gain_out, -6798, 1029);
557 #define IDT821034_GAIN_OUT_MIN_RAW 1 /* -67.98 dB -> 10^(-67.98/20.0) * 2506 = 1*/
558 #define IDT821034_GAIN_OUT_MAX_RAW 8191 /* 10.29 dB -> 10^(10.29/20.0) * 2506 = 8191 */
559 #define IDT821034_GAIN_OUT_INIT_RAW 2506 /* 0dB -> 10^(0/20) * 2506 = 2506 */
622 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in idt821034_power_event()
624 unsigned int id = w->shift; in idt821034_power_event()
632 mutex_lock(&idt821034->mutex); in idt821034_power_event()
641 mutex_unlock(&idt821034->mutex); in idt821034_power_event()
700 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(dai->component); in idt821034_dai_set_tdm_slot()
707 case 0: /* Not set -> default 8 */ in idt821034_dai_set_tdm_slot()
711 dev_err(dai->dev, "tdm slot width %d not supported\n", width); in idt821034_dai_set_tdm_slot()
712 return -EINVAL; in idt821034_dai_set_tdm_slot()
720 mutex_lock(&idt821034->mutex); in idt821034_dai_set_tdm_slot()
722 mutex_unlock(&idt821034->mutex); in idt821034_dai_set_tdm_slot()
724 dev_err(dai->dev, "ch%u set tx tdm slot failed (%d)\n", in idt821034_dai_set_tdm_slot()
734 dev_err(dai->dev, "too much tx slots defined (mask = 0x%x) support max %d\n", in idt821034_dai_set_tdm_slot()
736 return -EINVAL; in idt821034_dai_set_tdm_slot()
738 idt821034->max_ch_playback = ch; in idt821034_dai_set_tdm_slot()
745 mutex_lock(&idt821034->mutex); in idt821034_dai_set_tdm_slot()
747 mutex_unlock(&idt821034->mutex); in idt821034_dai_set_tdm_slot()
749 dev_err(dai->dev, "ch%u set rx tdm slot failed (%d)\n", in idt821034_dai_set_tdm_slot()
759 dev_err(dai->dev, "too much rx slots defined (mask = 0x%x) support max %d\n", in idt821034_dai_set_tdm_slot()
761 return -EINVAL; in idt821034_dai_set_tdm_slot()
763 idt821034->max_ch_capture = ch; in idt821034_dai_set_tdm_slot()
770 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(dai->component); in idt821034_dai_set_fmt()
774 mutex_lock(&idt821034->mutex); in idt821034_dai_set_fmt()
786 dev_err(dai->dev, "Unsupported DAI format 0x%x\n", in idt821034_dai_set_fmt()
788 ret = -EINVAL; in idt821034_dai_set_fmt()
793 mutex_unlock(&idt821034->mutex); in idt821034_dai_set_fmt()
801 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(dai->component); in idt821034_dai_hw_params()
805 mutex_lock(&idt821034->mutex); in idt821034_dai_hw_params()
817 dev_err(dai->dev, "Unsupported PCM format 0x%x\n", in idt821034_dai_hw_params()
819 ret = -EINVAL; in idt821034_dai_hw_params()
824 mutex_unlock(&idt821034->mutex); in idt821034_dai_hw_params()
838 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(dai->component); in idt821034_dai_startup()
842 max_ch = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? in idt821034_dai_startup()
843 idt821034->max_ch_playback : idt821034->max_ch_capture; in idt821034_dai_startup()
850 ret = snd_pcm_hw_constraint_minmax(substream->runtime, SNDRV_PCM_HW_PARAM_CHANNELS, in idt821034_dai_startup()
855 ret = snd_pcm_hw_constraint_list(substream->runtime, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, in idt821034_dai_startup()
901 mutex_lock(&idt821034->mutex); in idt821034_reset_audio()
908 idt821034->amps.ch[i].amp_out.gain = IDT821034_GAIN_OUT_INIT_RAW; in idt821034_reset_audio()
909 idt821034->amps.ch[i].amp_out.is_muted = false; in idt821034_reset_audio()
911 idt821034->amps.ch[i].amp_out.gain); in idt821034_reset_audio()
915 idt821034->amps.ch[i].amp_in.gain = IDT821034_GAIN_IN_INIT_RAW; in idt821034_reset_audio()
916 idt821034->amps.ch[i].amp_in.is_muted = false; in idt821034_reset_audio()
918 idt821034->amps.ch[i].amp_in.gain); in idt821034_reset_audio()
929 mutex_unlock(&idt821034->mutex); in idt821034_reset_audio()
938 /* reset idt821034 audio part*/ in idt821034_component_probe()
968 mutex_lock(&idt821034->mutex); in idt821034_chip_gpio_set()
977 dev_err(&idt821034->spi->dev, "set gpio %d (%u, 0x%x) failed (%d)\n", in idt821034_chip_gpio_set()
981 mutex_unlock(&idt821034->mutex); in idt821034_chip_gpio_set()
992 mutex_lock(&idt821034->mutex); in idt821034_chip_gpio_get()
994 mutex_unlock(&idt821034->mutex); in idt821034_chip_gpio_get()
996 dev_err(&idt821034->spi->dev, "get gpio %d (%u, 0x%x) failed (%d)\n", in idt821034_chip_gpio_get()
1016 mutex_lock(&idt821034->mutex); in idt821034_chip_get_direction()
1018 mutex_unlock(&idt821034->mutex); in idt821034_chip_get_direction()
1033 return -EPERM; in idt821034_chip_direction_input()
1035 mutex_lock(&idt821034->mutex); in idt821034_chip_direction_input()
1041 dev_err(&idt821034->spi->dev, "dir in gpio %d (%u, 0x%x) failed (%d)\n", in idt821034_chip_direction_input()
1045 mutex_unlock(&idt821034->mutex); in idt821034_chip_direction_input()
1059 mutex_lock(&idt821034->mutex); in idt821034_chip_direction_output()
1065 dev_err(&idt821034->spi->dev, "dir in gpio %d (%u, 0x%x) failed (%d)\n", in idt821034_chip_direction_output()
1069 mutex_unlock(&idt821034->mutex); in idt821034_chip_direction_output()
1078 mutex_lock(&idt821034->mutex); in idt821034_reset_gpio()
1094 mutex_unlock(&idt821034->mutex); in idt821034_reset_gpio()
1106 idt821034->gpio_chip.owner = THIS_MODULE; in idt821034_gpio_init()
1107 idt821034->gpio_chip.label = dev_name(&idt821034->spi->dev); in idt821034_gpio_init()
1108 idt821034->gpio_chip.parent = &idt821034->spi->dev; in idt821034_gpio_init()
1109 idt821034->gpio_chip.base = -1; in idt821034_gpio_init()
1110 idt821034->gpio_chip.ngpio = 5 * 4; /* 5 GPIOs on 4 channels */ in idt821034_gpio_init()
1111 idt821034->gpio_chip.get_direction = idt821034_chip_get_direction; in idt821034_gpio_init()
1112 idt821034->gpio_chip.direction_input = idt821034_chip_direction_input; in idt821034_gpio_init()
1113 idt821034->gpio_chip.direction_output = idt821034_chip_direction_output; in idt821034_gpio_init()
1114 idt821034->gpio_chip.get = idt821034_chip_gpio_get; in idt821034_gpio_init()
1115 idt821034->gpio_chip.set = idt821034_chip_gpio_set; in idt821034_gpio_init()
1116 idt821034->gpio_chip.can_sleep = true; in idt821034_gpio_init()
1118 return devm_gpiochip_add_data(&idt821034->spi->dev, &idt821034->gpio_chip, in idt821034_gpio_init()
1127 spi->bits_per_word = 8; in idt821034_spi_probe()
1132 idt821034 = devm_kzalloc(&spi->dev, sizeof(*idt821034), GFP_KERNEL); in idt821034_spi_probe()
1134 return -ENOMEM; in idt821034_spi_probe()
1136 idt821034->spi = spi; in idt821034_spi_probe()
1138 mutex_init(&idt821034->mutex); in idt821034_spi_probe()
1142 ret = devm_snd_soc_register_component(&spi->dev, &idt821034_component_driver, in idt821034_spi_probe()