Lines Matching +full:hifi +full:- +full:asrc +full:- +full:be
1 // SPDX-License-Identifier: GPL-2.0-only
27 #include <sound/tlv320dac33-plat.h>
32 * It can be configured to hold 16bit or 24bit samples
49 (((samples)*5000) / (((burstrate)*5000) / ((burstrate) - (playrate))))
88 unsigned int alarm_threshold; /* set to be half of LATENCY_TIME_MS */
115 0x00, 0x00, 0x00, 0x00, /* 0x00 - 0x03 */
116 0x00, 0x00, 0x00, 0x00, /* 0x04 - 0x07 */
117 0x00, 0x00, 0x00, 0x00, /* 0x08 - 0x0b */
118 0x00, 0x00, 0x00, 0x00, /* 0x0c - 0x0f */
119 0x00, 0x00, 0x00, 0x00, /* 0x10 - 0x13 */
120 0x00, 0x00, 0x00, 0x00, /* 0x14 - 0x17 */
121 0x00, 0x00, 0x00, 0x00, /* 0x18 - 0x1b */
122 0x00, 0x00, 0x00, 0x00, /* 0x1c - 0x1f */
123 0x00, 0x00, 0x00, 0x00, /* 0x20 - 0x23 */
124 0x00, 0x00, 0x00, 0x00, /* 0x24 - 0x27 */
125 0x00, 0x00, 0x00, 0x00, /* 0x28 - 0x2b */
126 0x00, 0x00, 0x00, 0x80, /* 0x2c - 0x2f */
127 0x80, 0x00, 0x00, 0x00, /* 0x30 - 0x33 */
128 0x00, 0x00, 0x00, 0x00, /* 0x34 - 0x37 */
129 0x00, 0x00, /* 0x38 - 0x39 */
130 /* Registers 0x3a - 0x3f are reserved */
131 0x00, 0x00, /* 0x3a - 0x3b */
132 0x00, 0x00, 0x00, 0x00, /* 0x3c - 0x3f */
134 0x00, 0x00, 0x00, 0x00, /* 0x40 - 0x43 */
135 0x00, 0x80, /* 0x44 - 0x45 */
136 /* Registers 0x46 - 0x47 are reserved */
137 0x80, 0x80, /* 0x46 - 0x47 */
139 0x80, 0x00, 0x00, /* 0x48 - 0x4a */
140 /* Registers 0x4b - 0x7c are reserved */
142 0x00, 0x00, 0x00, 0x00, /* 0x4c - 0x4f */
143 0x00, 0x00, 0x00, 0x00, /* 0x50 - 0x53 */
144 0x00, 0x00, 0x00, 0x00, /* 0x54 - 0x57 */
145 0x00, 0x00, 0x00, 0x00, /* 0x58 - 0x5b */
146 0x00, 0x00, 0x00, 0x00, /* 0x5c - 0x5f */
147 0x00, 0x00, 0x00, 0x00, /* 0x60 - 0x63 */
148 0x00, 0x00, 0x00, 0x00, /* 0x64 - 0x67 */
149 0x00, 0x00, 0x00, 0x00, /* 0x68 - 0x6b */
150 0x00, 0x00, 0x00, 0x00, /* 0x6c - 0x6f */
151 0x00, 0x00, 0x00, 0x00, /* 0x70 - 0x73 */
152 0x00, 0x00, 0x00, 0x00, /* 0x74 - 0x77 */
153 0x00, 0x00, 0x00, 0x00, /* 0x78 - 0x7b */
156 0xda, 0x33, 0x03, /* 0x7d - 0x7f */
164 u8 *cache = dac33->reg_cache; in dac33_read_reg_cache()
175 u8 *cache = dac33->reg_cache; in dac33_write_reg_cache()
191 if (dac33->chip_power) { in dac33_read()
192 val = i2c_smbus_read_byte_data(dac33->i2c, value[0]); in dac33_read()
194 dev_err(component->dev, "Read failed (%d)\n", val); in dac33_read()
224 if (dac33->chip_power) { in dac33_write()
225 ret = i2c_master_send(dac33->i2c, data, 2); in dac33_write()
227 dev_err(component->dev, "Write failed (%d)\n", ret); in dac33_write()
241 mutex_lock(&dac33->mutex); in dac33_write_locked()
243 mutex_unlock(&dac33->mutex); in dac33_write_locked()
269 if (dac33->chip_power) { in dac33_write16()
272 ret = i2c_master_send(dac33->i2c, data, 3); in dac33_write16()
274 dev_err(component->dev, "Write failed (%d)\n", ret); in dac33_write16()
286 if (unlikely(!dac33->chip_power)) in dac33_init_chip()
368 mutex_lock(&dac33->mutex); in dac33_hard_power()
371 if (unlikely(power == dac33->chip_power)) { in dac33_hard_power()
372 dev_dbg(component->dev, "Trying to set the same power state: %s\n", in dac33_hard_power()
378 ret = regulator_bulk_enable(ARRAY_SIZE(dac33->supplies), in dac33_hard_power()
379 dac33->supplies); in dac33_hard_power()
381 dev_err(component->dev, in dac33_hard_power()
386 if (dac33->power_gpio >= 0) in dac33_hard_power()
387 gpio_set_value(dac33->power_gpio, 1); in dac33_hard_power()
389 dac33->chip_power = 1; in dac33_hard_power()
392 if (dac33->power_gpio >= 0) in dac33_hard_power()
393 gpio_set_value(dac33->power_gpio, 0); in dac33_hard_power()
395 ret = regulator_bulk_disable(ARRAY_SIZE(dac33->supplies), in dac33_hard_power()
396 dac33->supplies); in dac33_hard_power()
398 dev_err(component->dev, in dac33_hard_power()
403 dac33->chip_power = 0; in dac33_hard_power()
407 mutex_unlock(&dac33->mutex); in dac33_hard_power()
414 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in dac33_playback_event()
419 if (likely(dac33->substream)) { in dac33_playback_event()
420 dac33_calculate_times(dac33->substream, component); in dac33_playback_event()
421 dac33_prepare_chip(dac33->substream, component); in dac33_playback_event()
437 ucontrol->value.enumerated.item[0] = dac33->fifo_mode; in dac33_get_fifo_mode()
449 if (dac33->fifo_mode == ucontrol->value.enumerated.item[0]) in dac33_set_fifo_mode()
453 return -EPERM; in dac33_set_fifo_mode()
455 if (ucontrol->value.enumerated.item[0] >= DAC33_FIFO_LAST_MODE) in dac33_set_fifo_mode()
456 ret = -EINVAL; in dac33_set_fifo_mode()
458 dac33->fifo_mode = ucontrol->value.enumerated.item[0]; in dac33_set_fifo_mode()
472 "Line -12dB DAC 0dB", "Line -6dB DAC 6dB",
486 * from 0 dB to -63.5 in 0.5 dB steps
487 * Need to be inverted later on:
489 * 0x7f == -63.5 dB
491 static DECLARE_TLV_DB_SCALE(dac_digivol_tlv, -6350, 50, 0);
647 struct snd_soc_component *component = dac33->component; in dac33_prefill_handler()
651 switch (dac33->fifo_mode) { in dac33_prefill_handler()
654 DAC33_THRREG(dac33->nsample)); in dac33_prefill_handler()
657 spin_lock_irqsave(&dac33->lock, flags); in dac33_prefill_handler()
658 dac33->t_stamp2 = ktime_to_us(ktime_get()); in dac33_prefill_handler()
659 dac33->t_stamp1 = dac33->t_stamp2; in dac33_prefill_handler()
660 spin_unlock_irqrestore(&dac33->lock, flags); in dac33_prefill_handler()
663 DAC33_THRREG(dac33->alarm_threshold)); in dac33_prefill_handler()
665 delay = SAMPLES_TO_US(dac33->burst_rate, in dac33_prefill_handler()
666 dac33->alarm_threshold) + 1000; in dac33_prefill_handler()
672 spin_lock_irqsave(&dac33->lock, flags); in dac33_prefill_handler()
673 dac33->t_stamp1 = ktime_to_us(ktime_get()); in dac33_prefill_handler()
675 dac33->t_stamp1 -= dac33->mode7_us_to_lthr; in dac33_prefill_handler()
676 spin_unlock_irqrestore(&dac33->lock, flags); in dac33_prefill_handler()
685 dev_warn(component->dev, "Unhandled FIFO mode: %d\n", in dac33_prefill_handler()
686 dac33->fifo_mode); in dac33_prefill_handler()
693 struct snd_soc_component *component = dac33->component; in dac33_playback_handler()
696 switch (dac33->fifo_mode) { in dac33_playback_handler()
699 spin_lock_irqsave(&dac33->lock, flags); in dac33_playback_handler()
700 dac33->t_stamp2 = ktime_to_us(ktime_get()); in dac33_playback_handler()
701 spin_unlock_irqrestore(&dac33->lock, flags); in dac33_playback_handler()
704 DAC33_THRREG(dac33->nsample)); in dac33_playback_handler()
710 dev_warn(component->dev, "Unhandled FIFO mode: %d\n", in dac33_playback_handler()
711 dac33->fifo_mode); in dac33_playback_handler()
723 component = dac33->component; in dac33_work()
725 mutex_lock(&dac33->mutex); in dac33_work()
726 switch (dac33->state) { in dac33_work()
728 dac33->state = DAC33_PLAYBACK; in dac33_work()
737 dac33->state = DAC33_IDLE; in dac33_work()
747 mutex_unlock(&dac33->mutex); in dac33_work()
756 spin_lock_irqsave(&dac33->lock, flags); in dac33_interrupt_handler()
757 dac33->t_stamp1 = ktime_to_us(ktime_get()); in dac33_interrupt_handler()
758 spin_unlock_irqrestore(&dac33->lock, flags); in dac33_interrupt_handler()
761 if (dac33->fifo_mode != DAC33_FIFO_MODE7) in dac33_interrupt_handler()
762 schedule_work(&dac33->work); in dac33_interrupt_handler()
775 } while (((reg & 0x03) != DAC33_OSCSTATUS_NORMAL) && timeout--); in dac33_oscwait()
777 dev_err(component->dev, in dac33_oscwait()
784 struct snd_soc_component *component = dai->component; in dac33_startup()
788 dac33->substream = substream; in dac33_startup()
796 struct snd_soc_component *component = dai->component; in dac33_shutdown()
799 dac33->substream = NULL; in dac33_shutdown()
808 struct snd_soc_component *component = dai->component; in dac33_hw_params()
817 dev_err(component->dev, "unsupported rate %d\n", in dac33_hw_params()
819 return -EINVAL; in dac33_hw_params()
824 dac33->fifo_size = DAC33_FIFO_SIZE_16BIT; in dac33_hw_params()
825 dac33->burst_rate = CALC_BURST_RATE(dac33->burst_bclkdiv, 32); in dac33_hw_params()
828 dac33->fifo_size = DAC33_FIFO_SIZE_24BIT; in dac33_hw_params()
829 dac33->burst_rate = CALC_BURST_RATE(dac33->burst_bclkdiv, 64); in dac33_hw_params()
832 dev_err(component->dev, "unsupported width %d\n", in dac33_hw_params()
834 return -EINVAL; in dac33_hw_params()
857 switch (substream->runtime->rate) { in dac33_prepare_chip()
860 oscset = CALC_OSCSET(substream->runtime->rate, dac33->refclk); in dac33_prepare_chip()
861 ratioset = CALC_RATIOSET(substream->runtime->rate, in dac33_prepare_chip()
862 dac33->refclk); in dac33_prepare_chip()
865 dev_err(component->dev, "unsupported rate %d\n", in dac33_prepare_chip()
866 substream->runtime->rate); in dac33_prepare_chip()
867 return -EINVAL; in dac33_prepare_chip()
878 switch (substream->runtime->format) { in dac33_prepare_chip()
887 dev_err(component->dev, "unsupported format %d\n", in dac33_prepare_chip()
888 substream->runtime->format); in dac33_prepare_chip()
889 return -EINVAL; in dac33_prepare_chip()
892 mutex_lock(&dac33->mutex); in dac33_prepare_chip()
894 if (!dac33->chip_power) { in dac33_prepare_chip()
899 mutex_unlock(&dac33->mutex); in dac33_prepare_chip()
928 if (dac33->fifo_mode) { in dac33_prepare_chip()
930 /* 50-51 : ASRC Control registers */ in dac33_prepare_chip()
941 /* 50-51 : ASRC Control registers */ in dac33_prepare_chip()
947 switch (dac33->fifo_mode) { in dac33_prepare_chip()
963 switch (dac33->fifo_mode) { in dac33_prepare_chip()
973 if (dac33->keep_bclk) in dac33_prepare_chip()
987 if (dac33->keep_bclk) in dac33_prepare_chip()
1016 if (dac33->fifo_mode) in dac33_prepare_chip()
1018 dac33->burst_bclkdiv); in dac33_prepare_chip()
1020 if (substream->runtime->format == SNDRV_PCM_FORMAT_S16_LE) in dac33_prepare_chip()
1025 switch (dac33->fifo_mode) { in dac33_prepare_chip()
1028 DAC33_THRREG(dac33->alarm_threshold)); in dac33_prepare_chip()
1035 dac33_write16(component, DAC33_UTHR_MSB, DAC33_THRREG(dac33->uthr)); in dac33_prepare_chip()
1043 mutex_unlock(&dac33->mutex); in dac33_prepare_chip()
1052 unsigned int period_size = substream->runtime->period_size; in dac33_calculate_times()
1053 unsigned int rate = substream->runtime->rate; in dac33_calculate_times()
1057 if (!dac33->fifo_mode) in dac33_calculate_times()
1060 switch (dac33->fifo_mode) { in dac33_calculate_times()
1063 dac33->alarm_threshold = US_TO_SAMPLES(rate, in dac33_calculate_times()
1064 dac33->mode1_latency); in dac33_calculate_times()
1065 nsample_limit = dac33->fifo_size - dac33->alarm_threshold; in dac33_calculate_times()
1067 if (period_size <= dac33->alarm_threshold) in dac33_calculate_times()
1072 dac33->nsample = period_size * in dac33_calculate_times()
1073 ((dac33->alarm_threshold / period_size) + in dac33_calculate_times()
1074 ((dac33->alarm_threshold % period_size) ? in dac33_calculate_times()
1077 dac33->nsample = nsample_limit; in dac33_calculate_times()
1079 dac33->nsample = period_size; in dac33_calculate_times()
1081 dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate, in dac33_calculate_times()
1082 dac33->nsample); in dac33_calculate_times()
1083 dac33->t_stamp1 = 0; in dac33_calculate_times()
1084 dac33->t_stamp2 = 0; in dac33_calculate_times()
1087 dac33->uthr = UTHR_FROM_PERIOD_SIZE(period_size, rate, in dac33_calculate_times()
1088 dac33->burst_rate) + 9; in dac33_calculate_times()
1089 if (dac33->uthr > (dac33->fifo_size - DAC33_MODE7_MARGIN)) in dac33_calculate_times()
1090 dac33->uthr = dac33->fifo_size - DAC33_MODE7_MARGIN; in dac33_calculate_times()
1091 if (dac33->uthr < (DAC33_MODE7_MARGIN + 10)) in dac33_calculate_times()
1092 dac33->uthr = (DAC33_MODE7_MARGIN + 10); in dac33_calculate_times()
1094 dac33->mode7_us_to_lthr = in dac33_calculate_times()
1095 SAMPLES_TO_US(substream->runtime->rate, in dac33_calculate_times()
1096 dac33->uthr - DAC33_MODE7_MARGIN + 1); in dac33_calculate_times()
1097 dac33->t_stamp1 = 0; in dac33_calculate_times()
1108 struct snd_soc_component *component = dai->component; in dac33_pcm_trigger()
1116 if (dac33->fifo_mode) { in dac33_pcm_trigger()
1117 dac33->state = DAC33_PREFILL; in dac33_pcm_trigger()
1118 schedule_work(&dac33->work); in dac33_pcm_trigger()
1124 if (dac33->fifo_mode) { in dac33_pcm_trigger()
1125 dac33->state = DAC33_FLUSH; in dac33_pcm_trigger()
1126 schedule_work(&dac33->work); in dac33_pcm_trigger()
1130 ret = -EINVAL; in dac33_pcm_trigger()
1140 struct snd_soc_component *component = dai->component; in dac33_dai_delay()
1148 switch (dac33->fifo_mode) { in dac33_dai_delay()
1152 spin_lock_irqsave(&dac33->lock, flags); in dac33_dai_delay()
1153 t0 = dac33->t_stamp1; in dac33_dai_delay()
1154 t1 = dac33->t_stamp2; in dac33_dai_delay()
1155 spin_unlock_irqrestore(&dac33->lock, flags); in dac33_dai_delay()
1167 time_delta = t_now - t0; in dac33_dai_delay()
1169 substream->runtime->rate, in dac33_dai_delay()
1172 if (likely(dac33->alarm_threshold > samples_out)) in dac33_dai_delay()
1173 delay = dac33->alarm_threshold - samples_out; in dac33_dai_delay()
1176 } else if ((t_now - t1) <= dac33->mode1_us_burst) { in dac33_dai_delay()
1181 time_delta = t_now - t0; in dac33_dai_delay()
1183 substream->runtime->rate, in dac33_dai_delay()
1186 time_delta = t_now - t1; in dac33_dai_delay()
1188 dac33->burst_rate, in dac33_dai_delay()
1191 samples = dac33->alarm_threshold; in dac33_dai_delay()
1192 samples += (samples_in - samples_out); in dac33_dai_delay()
1203 time_delta = t_now - t0; in dac33_dai_delay()
1205 substream->runtime->rate, in dac33_dai_delay()
1208 samples_in = dac33->nsample; in dac33_dai_delay()
1209 samples = dac33->alarm_threshold; in dac33_dai_delay()
1210 samples += (samples_in - samples_out); in dac33_dai_delay()
1213 delay = samples > dac33->fifo_size ? in dac33_dai_delay()
1214 dac33->fifo_size : samples; in dac33_dai_delay()
1220 spin_lock_irqsave(&dac33->lock, flags); in dac33_dai_delay()
1221 t0 = dac33->t_stamp1; in dac33_dai_delay()
1222 uthr = dac33->uthr; in dac33_dai_delay()
1223 spin_unlock_irqrestore(&dac33->lock, flags); in dac33_dai_delay()
1239 time_delta = t_now - t0; in dac33_dai_delay()
1240 if (time_delta <= dac33->mode7_us_to_lthr) { in dac33_dai_delay()
1246 substream->runtime->rate, in dac33_dai_delay()
1250 delay = uthr - samples_out; in dac33_dai_delay()
1258 time_delta = time_delta - dac33->mode7_us_to_lthr; in dac33_dai_delay()
1261 substream->runtime->rate, in dac33_dai_delay()
1264 dac33->burst_rate, in dac33_dai_delay()
1266 delay = DAC33_MODE7_MARGIN + samples_in - samples_out; in dac33_dai_delay()
1273 dev_warn(component->dev, "Unhandled FIFO mode: %d\n", in dac33_dai_delay()
1274 dac33->fifo_mode); in dac33_dai_delay()
1284 struct snd_soc_component *component = codec_dai->component; in dac33_set_dai_sysclk()
1300 dev_err(component->dev, "Invalid clock ID (%d)\n", clk_id); in dac33_set_dai_sysclk()
1303 dac33->refclk = freq; in dac33_set_dai_sysclk()
1314 struct snd_soc_component *component = codec_dai->component; in dac33_set_dai_fmt()
1326 if (dac33->fifo_mode) { in dac33_set_dai_fmt()
1327 dev_err(component->dev, "FIFO mode requires provider mode\n"); in dac33_set_dai_fmt()
1328 return -EINVAL; in dac33_set_dai_fmt()
1333 return -EINVAL; in dac33_set_dai_fmt()
1353 dev_err(component->dev, "Unsupported format (%u)\n", in dac33_set_dai_fmt()
1355 return -EINVAL; in dac33_set_dai_fmt()
1369 dac33->component = component; in dac33_soc_probe()
1374 dev_err(component->dev, "Failed to power up component: %d\n", ret); in dac33_soc_probe()
1381 dev_err(component->dev, "Failed to read chip ID: %d\n", ret); in dac33_soc_probe()
1382 ret = -ENODEV; in dac33_soc_probe()
1387 if (dac33->irq >= 0) { in dac33_soc_probe()
1388 ret = request_irq(dac33->irq, dac33_interrupt_handler, in dac33_soc_probe()
1390 component->name, component); in dac33_soc_probe()
1392 dev_err(component->dev, "Could not request IRQ%d (%d)\n", in dac33_soc_probe()
1393 dac33->irq, ret); in dac33_soc_probe()
1394 dac33->irq = -1; in dac33_soc_probe()
1396 if (dac33->irq != -1) { in dac33_soc_probe()
1397 INIT_WORK(&dac33->work, dac33_work); in dac33_soc_probe()
1402 if (dac33->irq >= 0) in dac33_soc_probe()
1414 if (dac33->irq >= 0) { in dac33_soc_remove()
1415 free_irq(dac33->irq, dac33->component); in dac33_soc_remove()
1416 flush_work(&dac33->work); in dac33_soc_remove()
1451 .name = "tlv320dac33-hifi",
1469 if (client->dev.platform_data == NULL) { in dac33_i2c_probe()
1470 dev_err(&client->dev, "Platform data not set\n"); in dac33_i2c_probe()
1471 return -ENODEV; in dac33_i2c_probe()
1473 pdata = client->dev.platform_data; in dac33_i2c_probe()
1475 dac33 = devm_kzalloc(&client->dev, sizeof(struct tlv320dac33_priv), in dac33_i2c_probe()
1478 return -ENOMEM; in dac33_i2c_probe()
1480 dac33->reg_cache = devm_kmemdup(&client->dev, in dac33_i2c_probe()
1484 if (!dac33->reg_cache) in dac33_i2c_probe()
1485 return -ENOMEM; in dac33_i2c_probe()
1487 dac33->i2c = client; in dac33_i2c_probe()
1488 mutex_init(&dac33->mutex); in dac33_i2c_probe()
1489 spin_lock_init(&dac33->lock); in dac33_i2c_probe()
1493 dac33->power_gpio = pdata->power_gpio; in dac33_i2c_probe()
1494 dac33->burst_bclkdiv = pdata->burst_bclkdiv; in dac33_i2c_probe()
1495 dac33->keep_bclk = pdata->keep_bclk; in dac33_i2c_probe()
1496 dac33->mode1_latency = pdata->mode1_latency; in dac33_i2c_probe()
1497 if (!dac33->mode1_latency) in dac33_i2c_probe()
1498 dac33->mode1_latency = 10000; /* 10ms */ in dac33_i2c_probe()
1499 dac33->irq = client->irq; in dac33_i2c_probe()
1501 dac33->fifo_mode = DAC33_FIFO_BYPASS; in dac33_i2c_probe()
1504 if (dac33->power_gpio >= 0) { in dac33_i2c_probe()
1505 ret = gpio_request(dac33->power_gpio, "tlv320dac33 reset"); in dac33_i2c_probe()
1507 dev_err(&client->dev, in dac33_i2c_probe()
1509 dac33->power_gpio); in dac33_i2c_probe()
1512 gpio_direction_output(dac33->power_gpio, 0); in dac33_i2c_probe()
1515 for (i = 0; i < ARRAY_SIZE(dac33->supplies); i++) in dac33_i2c_probe()
1516 dac33->supplies[i].supply = dac33_supply_names[i]; in dac33_i2c_probe()
1518 ret = devm_regulator_bulk_get(&client->dev, ARRAY_SIZE(dac33->supplies), in dac33_i2c_probe()
1519 dac33->supplies); in dac33_i2c_probe()
1522 dev_err(&client->dev, "Failed to request supplies: %d\n", ret); in dac33_i2c_probe()
1526 ret = devm_snd_soc_register_component(&client->dev, in dac33_i2c_probe()
1533 if (dac33->power_gpio >= 0) in dac33_i2c_probe()
1534 gpio_free(dac33->power_gpio); in dac33_i2c_probe()
1543 if (unlikely(dac33->chip_power)) in dac33_i2c_remove()
1544 dac33_hard_power(dac33->component, 0); in dac33_i2c_remove()
1546 if (dac33->power_gpio >= 0) in dac33_i2c_remove()
1547 gpio_free(dac33->power_gpio); in dac33_i2c_remove()
1561 .name = "tlv320dac33-codec",