Lines Matching +full:rx +full:- +full:ts +full:- +full:max

1 // SPDX-License-Identifier: GPL-2.0
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,
59 .tx_buf = &idt821034->spi_tx_buf,
64 idt821034->spi_tx_buf = val;
66 dev_vdbg(&idt821034->spi->dev, "spi xfer wr 0x%x\n", val);
68 return spi_sync_transfer(idt821034->spi, xfer, 2);
85 .tx_buf = &idt821034->spi_tx_buf,
86 .rx_buf = &idt821034->spi_rx_buf,
90 .tx_buf = &idt821034->spi_tx_buf,
96 idt821034->spi_tx_buf = valw;
98 ret = spi_sync_transfer(idt821034->spi, xfer, 2);
102 *valr = idt821034->spi_rx_buf;
104 dev_vdbg(&idt821034->spi->dev, "spi xfer wr 0x%x, rd 0x%x\n",
124 dev_dbg(&idt821034->spi->dev, "set_channel_power(%u, 0x%x)\n", ch, power);
126 conf = IDT821034_MODE_CODEC(ch) | idt821034->cache.codec_conf;
131 idt821034->cache.ch[ch].rx_slot);
138 idt821034->cache.ch[ch].tx_slot);
148 idt821034->cache.ch[ch].power = power;
155 return idt821034->cache.ch[ch].power;
165 u8 ts;
168 dev_dbg(&idt821034->spi->dev, "set_codec_conf(0x%x)\n", codec_conf);
180 if (idt821034->cache.ch[0].power & IDT821034_CONF_PWRUP_RX) {
182 ts = idt821034->cache.ch[0].rx_slot;
183 } else if (idt821034->cache.ch[0].power & IDT821034_CONF_PWRUP_TX) {
185 ts = idt821034->cache.ch[0].tx_slot;
187 ts = 0x00;
190 /* Write configuration register and time-slot register */
191 ret = idt821034_2x8bit_write(idt821034, conf, ts);
195 idt821034->cache.codec_conf = codec_conf;
201 return idt821034->cache.codec_conf;
213 dev_dbg(&idt821034->spi->dev, "set_channel_ts(%u, 0x%x, %d)\n", ch, ch_dir, ts_num);
215 conf = IDT821034_MODE_CODEC(ch) | idt821034->cache.codec_conf;
218 if (idt821034->cache.ch[ch].power & IDT821034_CONF_PWRUP_RX) {
225 idt821034->cache.ch[ch].rx_slot = ts_num;
228 if (idt821034->cache.ch[ch].power & IDT821034_CONF_PWRUP_TX) {
235 idt821034->cache.ch[ch].tx_slot = ts_num;
250 dev_dbg(&idt821034->spi->dev, "set_slic_conf(%u, 0x%x)\n", ch, slic_dir);
253 ret = idt821034_2x8bit_write(idt821034, conf, idt821034->cache.ch[ch].slic_control);
257 idt821034->cache.ch[ch].slic_conf = slic_dir;
264 return idt821034->cache.ch[ch].slic_conf;
272 dev_dbg(&idt821034->spi->dev, "write_slic_raw(%u, 0x%x)\n", ch, slic_raw);
283 conf = IDT821034_MODE_SLIC(ch) | idt821034->cache.ch[ch].slic_conf;
288 idt821034->cache.ch[ch].slic_control = slic_raw;
294 return idt821034->cache.ch[ch].slic_control;
314 val = IDT821034_MODE_SLIC(ch) | idt821034->cache.ch[ch].slic_conf;
319 ret = idt821034_8bit_read(idt821034, idt821034->cache.ch[ch].slic_control, slic_raw);
323 dev_dbg(&idt821034->spi->dev, "read_slic_raw(%i) 0x%x\n", ch, *slic_raw);
338 dev_dbg(&idt821034->spi->dev, "set_gain_channel(%u, 0x%x, 0x%x-%d)\n",
353 * A gain programming coefficient is 14-bit wide and in binary format.
361 * coefficient. To program a +3 dB gain in transmit path and a -3.5 dB
370 * Linear Code of -3.5dB = 10^(-3.5/20) = 0.668343917
404 struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;
407 int min = mc->min;
408 int max = mc->max;
409 unsigned int mask = (1 << fls(max)) - 1;
410 unsigned int invert = mc->invert;
414 ch = IDT821034_ID_GET_CHAN(mc->reg);
416 mutex_lock(&idt821034->mutex);
417 if (IDT821034_ID_IS_OUT(mc->reg))
418 val = idt821034->amps.ch[ch].amp_out.gain;
420 val = idt821034->amps.ch[ch].amp_in.gain;
421 mutex_unlock(&idt821034->mutex);
423 ucontrol->value.integer.value[0] = val & mask;
425 ucontrol->value.integer.value[0] = max - ucontrol->value.integer.value[0];
427 ucontrol->value.integer.value[0] = ucontrol->value.integer.value[0] - min;
435 struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;
439 int min = mc->min;
440 int max = mc->max;
441 unsigned int mask = (1 << fls(max)) - 1;
442 unsigned int invert = mc->invert;
448 val = ucontrol->value.integer.value[0];
449 if (val > max - min)
450 return -EINVAL;
453 val = (max - val) & mask;
457 ch = IDT821034_ID_GET_CHAN(mc->reg);
459 mutex_lock(&idt821034->mutex);
461 if (IDT821034_ID_IS_OUT(mc->reg)) {
462 amp = &idt821034->amps.ch[ch].amp_out;
465 amp = &idt821034->amps.ch[ch].amp_in;
469 if (amp->gain == val) {
474 if (!amp->is_muted) {
480 amp->gain = val;
483 mutex_unlock(&idt821034->mutex);
492 int id = kcontrol->private_value;
498 mutex_lock(&idt821034->mutex);
500 idt821034->amps.ch[ch].amp_out.is_muted :
501 idt821034->amps.ch[ch].amp_in.is_muted;
502 mutex_unlock(&idt821034->mutex);
504 ucontrol->value.integer.value[0] = !is_muted;
514 int id = kcontrol->private_value;
522 is_mute = !ucontrol->value.integer.value[0];
524 mutex_lock(&idt821034->mutex);
527 amp = &idt821034->amps.ch[ch].amp_out;
530 amp = &idt821034->amps.ch[ch].amp_in;
534 if (amp->is_muted == is_mute) {
540 is_mute ? 0 : amp->gain);
544 amp->is_muted = is_mute;
547 mutex_unlock(&idt821034->mutex);
551 static const DECLARE_TLV_DB_LINEAR(idt821034_gain_in, -300, 1300);
552 #define IDT821034_GAIN_IN_MIN_RAW 1288 /* -3.0 dB -> 10^(-3.0/20.0) * 1820 = 1288 */
553 #define IDT821034_GAIN_IN_MAX_RAW 8130 /* 13.0 dB -> 10^(13.0/20.0) * 1820 = 8130 */
554 #define IDT821034_GAIN_IN_INIT_RAW 1820 /* 0dB -> 10^(0/20) * 1820 = 1820 */
556 static const DECLARE_TLV_DB_LINEAR(idt821034_gain_out, -1300, 300);
557 #define IDT821034_GAIN_OUT_MIN_RAW 561 /* -13.0 dB -> 10^(-13.0/20.0) * 2506 = 561 */
558 #define IDT821034_GAIN_OUT_MAX_RAW 3540 /* 3.0 dB -> 10^(3.0/20.0) * 2506 = 3540 */
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);
624 unsigned int id = w->shift;
632 mutex_lock(&idt821034->mutex);
641 mutex_unlock(&idt821034->mutex);
700 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(dai->component);
707 case 0: /* Not set -> default 8 */
711 dev_err(dai->dev, "tdm slot width %d not supported\n", width);
712 return -EINVAL;
720 mutex_lock(&idt821034->mutex);
722 mutex_unlock(&idt821034->mutex);
724 dev_err(dai->dev, "ch%u set tx tdm slot failed (%d)\n",
734 dev_err(dai->dev, "too much tx slots defined (mask = 0x%x) support max %d\n",
736 return -EINVAL;
738 idt821034->max_ch_playback = ch;
745 mutex_lock(&idt821034->mutex);
747 mutex_unlock(&idt821034->mutex);
749 dev_err(dai->dev, "ch%u set rx tdm slot failed (%d)\n",
759 dev_err(dai->dev, "too much rx slots defined (mask = 0x%x) support max %d\n",
761 return -EINVAL;
763 idt821034->max_ch_capture = ch;
770 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(dai->component);
774 mutex_lock(&idt821034->mutex);
786 dev_err(dai->dev, "Unsupported DAI format 0x%x\n",
788 ret = -EINVAL;
793 mutex_unlock(&idt821034->mutex);
801 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(dai->component);
805 mutex_lock(&idt821034->mutex);
817 dev_err(dai->dev, "Unsupported PCM format 0x%x\n",
819 ret = -EINVAL;
824 mutex_unlock(&idt821034->mutex);
838 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(dai->component);
842 max_ch = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
843 idt821034->max_ch_playback : idt821034->max_ch_capture;
846 * Disable stream support (min = 0, max = 0) if no timeslots were
850 ret = snd_pcm_hw_constraint_minmax(substream->runtime, SNDRV_PCM_HW_PARAM_CHANNELS,
855 ret = snd_pcm_hw_constraint_list(substream->runtime, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
901 mutex_lock(&idt821034->mutex);
908 idt821034->amps.ch[i].amp_out.gain = IDT821034_GAIN_OUT_INIT_RAW;
909 idt821034->amps.ch[i].amp_out.is_muted = false;
911 idt821034->amps.ch[i].amp_out.gain);
915 idt821034->amps.ch[i].amp_in.gain = IDT821034_GAIN_IN_INIT_RAW;
916 idt821034->amps.ch[i].amp_in.is_muted = false;
918 idt821034->amps.ch[i].amp_in.gain);
929 mutex_unlock(&idt821034->mutex);
969 mutex_lock(&idt821034->mutex);
978 mutex_unlock(&idt821034->mutex);
981 dev_err(&idt821034->spi->dev, "set gpio %d (%u, 0x%x) failed (%d)\n",
995 mutex_lock(&idt821034->mutex);
997 mutex_unlock(&idt821034->mutex);
999 dev_err(&idt821034->spi->dev, "get gpio %d (%u, 0x%x) failed (%d)\n",
1019 mutex_lock(&idt821034->mutex);
1021 mutex_unlock(&idt821034->mutex);
1036 return -EPERM;
1038 mutex_lock(&idt821034->mutex);
1044 dev_err(&idt821034->spi->dev, "dir in gpio %d (%u, 0x%x) failed (%d)\n",
1048 mutex_unlock(&idt821034->mutex);
1064 mutex_lock(&idt821034->mutex);
1070 dev_err(&idt821034->spi->dev, "dir out gpio %d (%u, 0x%x) failed (%d)\n",
1074 mutex_unlock(&idt821034->mutex);
1083 mutex_lock(&idt821034->mutex);
1099 mutex_unlock(&idt821034->mutex);
1111 idt821034->gpio_chip.owner = THIS_MODULE;
1112 idt821034->gpio_chip.label = dev_name(&idt821034->spi->dev);
1113 idt821034->gpio_chip.parent = &idt821034->spi->dev;
1114 idt821034->gpio_chip.base = -1;
1115 idt821034->gpio_chip.ngpio = 5 * 4; /* 5 GPIOs on 4 channels */
1116 idt821034->gpio_chip.get_direction = idt821034_chip_get_direction;
1117 idt821034->gpio_chip.direction_input = idt821034_chip_direction_input;
1118 idt821034->gpio_chip.direction_output = idt821034_chip_direction_output;
1119 idt821034->gpio_chip.get = idt821034_chip_gpio_get;
1120 idt821034->gpio_chip.set = idt821034_chip_gpio_set;
1121 idt821034->gpio_chip.can_sleep = true;
1123 return devm_gpiochip_add_data(&idt821034->spi->dev, &idt821034->gpio_chip,
1132 spi->bits_per_word = 8;
1137 idt821034 = devm_kzalloc(&spi->dev, sizeof(*idt821034), GFP_KERNEL);
1139 return -ENOMEM;
1141 idt821034->spi = spi;
1143 mutex_init(&idt821034->mutex);
1147 ret = devm_snd_soc_register_component(&spi->dev, &idt821034_component_driver,