Lines Matching +full:integer +full:- +full:n
1 // SPDX-License-Identifier: GPL-2.0-only
8 * - How to distinguish between 3004 and versions?
11 * - This codec driver doesn't honour the 'connected'
15 * - Driver assumes that the microphone is always
17 * the input. This should also be a codec-dependent
23 * - As Apple notes in their code, the tas3004 seems
36 * - this should actually register *two* aoa_codec
71 MODULE_DESCRIPTION("tas codec driver for snd-aoa");
74 #include "tas-gain-table.h"
75 #include "tas-basstreble.h"
79 #define PFX "snd-aoa-codec-tas: "
110 return i2c_smbus_write_byte_data(tas->i2c, reg, *data); in tas_write_reg()
112 return i2c_smbus_write_i2c_block_data(tas->i2c, reg, len, data); in tas_write_reg()
119 if (tas->drc_enabled) in tas3004_set_drc()
124 if (tas->drc_range > 0xef) in tas3004_set_drc()
126 else if (tas->drc_range < 0) in tas3004_set_drc()
129 val[2] = tas->drc_range; in tas3004_set_drc()
141 tmp = tas3004_treble(tas->treble); in tas_set_treble()
149 tmp = tas3004_bass(tas->bass); in tas_set_bass()
159 left = tas->cached_volume_l; in tas_set_volume()
160 right = tas->cached_volume_r; in tas_set_volume()
165 if (tas->mute_l) left = 0; in tas_set_volume()
166 if (tas->mute_r) right = 0; in tas_set_volume()
192 val = tas->mixer_l[i]; in tas_set_mixer()
202 val = tas->mixer_r[i]; in tas_set_mixer()
226 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in tas_snd_vol_info()
227 uinfo->count = 2; in tas_snd_vol_info()
228 uinfo->value.integer.min = 0; in tas_snd_vol_info()
229 uinfo->value.integer.max = 177; in tas_snd_vol_info()
238 mutex_lock(&tas->mtx); in tas_snd_vol_get()
239 ucontrol->value.integer.value[0] = tas->cached_volume_l; in tas_snd_vol_get()
240 ucontrol->value.integer.value[1] = tas->cached_volume_r; in tas_snd_vol_get()
241 mutex_unlock(&tas->mtx); in tas_snd_vol_get()
250 if (ucontrol->value.integer.value[0] < 0 || in tas_snd_vol_put()
251 ucontrol->value.integer.value[0] > 177) in tas_snd_vol_put()
252 return -EINVAL; in tas_snd_vol_put()
253 if (ucontrol->value.integer.value[1] < 0 || in tas_snd_vol_put()
254 ucontrol->value.integer.value[1] > 177) in tas_snd_vol_put()
255 return -EINVAL; in tas_snd_vol_put()
257 mutex_lock(&tas->mtx); in tas_snd_vol_put()
258 if (tas->cached_volume_l == ucontrol->value.integer.value[0] in tas_snd_vol_put()
259 && tas->cached_volume_r == ucontrol->value.integer.value[1]) { in tas_snd_vol_put()
260 mutex_unlock(&tas->mtx); in tas_snd_vol_put()
264 tas->cached_volume_l = ucontrol->value.integer.value[0]; in tas_snd_vol_put()
265 tas->cached_volume_r = ucontrol->value.integer.value[1]; in tas_snd_vol_put()
266 if (tas->hw_enabled) in tas_snd_vol_put()
268 mutex_unlock(&tas->mtx); in tas_snd_vol_put()
288 mutex_lock(&tas->mtx); in tas_snd_mute_get()
289 ucontrol->value.integer.value[0] = !tas->mute_l; in tas_snd_mute_get()
290 ucontrol->value.integer.value[1] = !tas->mute_r; in tas_snd_mute_get()
291 mutex_unlock(&tas->mtx); in tas_snd_mute_get()
300 mutex_lock(&tas->mtx); in tas_snd_mute_put()
301 if (tas->mute_l == !ucontrol->value.integer.value[0] in tas_snd_mute_put()
302 && tas->mute_r == !ucontrol->value.integer.value[1]) { in tas_snd_mute_put()
303 mutex_unlock(&tas->mtx); in tas_snd_mute_put()
307 tas->mute_l = !ucontrol->value.integer.value[0]; in tas_snd_mute_put()
308 tas->mute_r = !ucontrol->value.integer.value[1]; in tas_snd_mute_put()
309 if (tas->hw_enabled) in tas_snd_mute_put()
311 mutex_unlock(&tas->mtx); in tas_snd_mute_put()
327 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in tas_snd_mixer_info()
328 uinfo->count = 2; in tas_snd_mixer_info()
329 uinfo->value.integer.min = 0; in tas_snd_mixer_info()
330 uinfo->value.integer.max = 177; in tas_snd_mixer_info()
338 int idx = kcontrol->private_value; in tas_snd_mixer_get()
340 mutex_lock(&tas->mtx); in tas_snd_mixer_get()
341 ucontrol->value.integer.value[0] = tas->mixer_l[idx]; in tas_snd_mixer_get()
342 ucontrol->value.integer.value[1] = tas->mixer_r[idx]; in tas_snd_mixer_get()
343 mutex_unlock(&tas->mtx); in tas_snd_mixer_get()
352 int idx = kcontrol->private_value; in tas_snd_mixer_put()
354 mutex_lock(&tas->mtx); in tas_snd_mixer_put()
355 if (tas->mixer_l[idx] == ucontrol->value.integer.value[0] in tas_snd_mixer_put()
356 && tas->mixer_r[idx] == ucontrol->value.integer.value[1]) { in tas_snd_mixer_put()
357 mutex_unlock(&tas->mtx); in tas_snd_mixer_put()
361 tas->mixer_l[idx] = ucontrol->value.integer.value[0]; in tas_snd_mixer_put()
362 tas->mixer_r[idx] = ucontrol->value.integer.value[1]; in tas_snd_mixer_put()
364 if (tas->hw_enabled) in tas_snd_mixer_put()
366 mutex_unlock(&tas->mtx); in tas_snd_mixer_put()
370 #define MIXER_CONTROL(n,descr,idx) \ argument
371 static const struct snd_kcontrol_new n##_control = { \
387 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in tas_snd_drc_range_info()
388 uinfo->count = 1; in tas_snd_drc_range_info()
389 uinfo->value.integer.min = 0; in tas_snd_drc_range_info()
390 uinfo->value.integer.max = TAS3004_DRC_MAX; in tas_snd_drc_range_info()
399 mutex_lock(&tas->mtx); in tas_snd_drc_range_get()
400 ucontrol->value.integer.value[0] = tas->drc_range; in tas_snd_drc_range_get()
401 mutex_unlock(&tas->mtx); in tas_snd_drc_range_get()
410 if (ucontrol->value.integer.value[0] < 0 || in tas_snd_drc_range_put()
411 ucontrol->value.integer.value[0] > TAS3004_DRC_MAX) in tas_snd_drc_range_put()
412 return -EINVAL; in tas_snd_drc_range_put()
414 mutex_lock(&tas->mtx); in tas_snd_drc_range_put()
415 if (tas->drc_range == ucontrol->value.integer.value[0]) { in tas_snd_drc_range_put()
416 mutex_unlock(&tas->mtx); in tas_snd_drc_range_put()
420 tas->drc_range = ucontrol->value.integer.value[0]; in tas_snd_drc_range_put()
421 if (tas->hw_enabled) in tas_snd_drc_range_put()
423 mutex_unlock(&tas->mtx); in tas_snd_drc_range_put()
443 mutex_lock(&tas->mtx); in tas_snd_drc_switch_get()
444 ucontrol->value.integer.value[0] = tas->drc_enabled; in tas_snd_drc_switch_get()
445 mutex_unlock(&tas->mtx); in tas_snd_drc_switch_get()
454 mutex_lock(&tas->mtx); in tas_snd_drc_switch_put()
455 if (tas->drc_enabled == ucontrol->value.integer.value[0]) { in tas_snd_drc_switch_put()
456 mutex_unlock(&tas->mtx); in tas_snd_drc_switch_put()
460 tas->drc_enabled = !!ucontrol->value.integer.value[0]; in tas_snd_drc_switch_put()
461 if (tas->hw_enabled) in tas_snd_drc_switch_put()
463 mutex_unlock(&tas->mtx); in tas_snd_drc_switch_put()
479 static const char * const texts[] = { "Line-In", "Microphone" }; in tas_snd_capture_source_info()
489 mutex_lock(&tas->mtx); in tas_snd_capture_source_get()
490 ucontrol->value.enumerated.item[0] = !!(tas->acr & TAS_ACR_INPUT_B); in tas_snd_capture_source_get()
491 mutex_unlock(&tas->mtx); in tas_snd_capture_source_get()
501 if (ucontrol->value.enumerated.item[0] > 1) in tas_snd_capture_source_put()
502 return -EINVAL; in tas_snd_capture_source_put()
503 mutex_lock(&tas->mtx); in tas_snd_capture_source_put()
504 oldacr = tas->acr; in tas_snd_capture_source_put()
511 tas->acr &= ~(TAS_ACR_INPUT_B | TAS_ACR_B_MONAUREAL); in tas_snd_capture_source_put()
512 if (ucontrol->value.enumerated.item[0]) in tas_snd_capture_source_put()
513 tas->acr |= TAS_ACR_INPUT_B | TAS_ACR_B_MONAUREAL | in tas_snd_capture_source_put()
515 if (oldacr == tas->acr) { in tas_snd_capture_source_put()
516 mutex_unlock(&tas->mtx); in tas_snd_capture_source_put()
519 if (tas->hw_enabled) in tas_snd_capture_source_put()
520 tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr); in tas_snd_capture_source_put()
521 mutex_unlock(&tas->mtx); in tas_snd_capture_source_put()
548 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in tas_snd_treble_info()
549 uinfo->count = 1; in tas_snd_treble_info()
550 uinfo->value.integer.min = TAS3004_TREBLE_MIN; in tas_snd_treble_info()
551 uinfo->value.integer.max = TAS3004_TREBLE_MAX; in tas_snd_treble_info()
560 mutex_lock(&tas->mtx); in tas_snd_treble_get()
561 ucontrol->value.integer.value[0] = tas->treble; in tas_snd_treble_get()
562 mutex_unlock(&tas->mtx); in tas_snd_treble_get()
571 if (ucontrol->value.integer.value[0] < TAS3004_TREBLE_MIN || in tas_snd_treble_put()
572 ucontrol->value.integer.value[0] > TAS3004_TREBLE_MAX) in tas_snd_treble_put()
573 return -EINVAL; in tas_snd_treble_put()
574 mutex_lock(&tas->mtx); in tas_snd_treble_put()
575 if (tas->treble == ucontrol->value.integer.value[0]) { in tas_snd_treble_put()
576 mutex_unlock(&tas->mtx); in tas_snd_treble_put()
580 tas->treble = ucontrol->value.integer.value[0]; in tas_snd_treble_put()
581 if (tas->hw_enabled) in tas_snd_treble_put()
583 mutex_unlock(&tas->mtx); in tas_snd_treble_put()
599 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in tas_snd_bass_info()
600 uinfo->count = 1; in tas_snd_bass_info()
601 uinfo->value.integer.min = TAS3004_BASS_MIN; in tas_snd_bass_info()
602 uinfo->value.integer.max = TAS3004_BASS_MAX; in tas_snd_bass_info()
611 mutex_lock(&tas->mtx); in tas_snd_bass_get()
612 ucontrol->value.integer.value[0] = tas->bass; in tas_snd_bass_get()
613 mutex_unlock(&tas->mtx); in tas_snd_bass_get()
622 if (ucontrol->value.integer.value[0] < TAS3004_BASS_MIN || in tas_snd_bass_put()
623 ucontrol->value.integer.value[0] > TAS3004_BASS_MAX) in tas_snd_bass_put()
624 return -EINVAL; in tas_snd_bass_put()
625 mutex_lock(&tas->mtx); in tas_snd_bass_put()
626 if (tas->bass == ucontrol->value.integer.value[0]) { in tas_snd_bass_put()
627 mutex_unlock(&tas->mtx); in tas_snd_bass_put()
631 tas->bass = ucontrol->value.integer.value[0]; in tas_snd_bass_put()
632 if (tas->hw_enabled) in tas_snd_bass_put()
634 mutex_unlock(&tas->mtx); in tas_snd_bass_put()
674 tas->codec.gpio->methods->all_amps_off(tas->codec.gpio); in tas_reset_init()
676 tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 0); in tas_reset_init()
678 tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 1); in tas_reset_init()
680 tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 0); in tas_reset_init()
682 tas->codec.gpio->methods->all_amps_restore(tas->codec.gpio); in tas_reset_init()
688 tas->acr |= TAS_ACR_ANALOG_PDOWN; in tas_reset_init()
689 if (tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr)) in tas_reset_init()
699 tas->treble = TAS3004_TREBLE_ZERO; in tas_reset_init()
700 tas->bass = TAS3004_BASS_ZERO; in tas_reset_init()
704 tas->acr &= ~TAS_ACR_ANALOG_PDOWN; in tas_reset_init()
705 if (tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr)) in tas_reset_init()
710 return -ENODEV; in tas_reset_init()
715 struct tas *tas = cii->codec_data; in tas_switch_clock()
720 tas->codec.gpio->methods->all_amps_off(tas->codec.gpio); in tas_switch_clock()
721 tas->hw_enabled = 0; in tas_switch_clock()
724 /* Clocks are back, re-init the codec */ in tas_switch_clock()
725 mutex_lock(&tas->mtx); in tas_switch_clock()
729 tas->hw_enabled = 1; in tas_switch_clock()
730 tas->codec.gpio->methods->all_amps_restore(tas->codec.gpio); in tas_switch_clock()
731 mutex_unlock(&tas->mtx); in tas_switch_clock()
735 return -EINVAL; in tas_switch_clock()
746 mutex_lock(&tas->mtx); in tas_suspend()
747 tas->hw_enabled = 0; in tas_suspend()
748 tas->acr |= TAS_ACR_ANALOG_PDOWN; in tas_suspend()
749 tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr); in tas_suspend()
750 mutex_unlock(&tas->mtx); in tas_suspend()
757 mutex_lock(&tas->mtx); in tas_resume()
761 tas->hw_enabled = 1; in tas_resume()
762 mutex_unlock(&tas->mtx); in tas_resume()
768 return tas_suspend(cii->codec_data); in _tas_suspend()
773 return tas_resume(cii->codec_data); in _tas_resume()
800 if (!tas->codec.gpio || !tas->codec.gpio->methods) { in tas_init_codec()
801 printk(KERN_ERR PFX "gpios not assigned!!\n"); in tas_init_codec()
802 return -EINVAL; in tas_init_codec()
805 mutex_lock(&tas->mtx); in tas_init_codec()
807 printk(KERN_ERR PFX "tas failed to initialise\n"); in tas_init_codec()
808 mutex_unlock(&tas->mtx); in tas_init_codec()
809 return -ENXIO; in tas_init_codec()
811 tas->hw_enabled = 1; in tas_init_codec()
812 mutex_unlock(&tas->mtx); in tas_init_codec()
814 if (tas->codec.soundbus_dev->attach_codec(tas->codec.soundbus_dev, in tas_init_codec()
817 printk(KERN_ERR PFX "error attaching tas to soundbus\n"); in tas_init_codec()
818 return -ENODEV; in tas_init_codec()
822 printk(KERN_ERR PFX "failed to create tas snd device!\n"); in tas_init_codec()
823 return -ENODEV; in tas_init_codec()
863 tas->codec.soundbus_dev->detach_codec(tas->codec.soundbus_dev, tas); in tas_init_codec()
872 if (!tas->codec.soundbus_dev) in tas_exit_codec()
874 tas->codec.soundbus_dev->detach_codec(tas->codec.soundbus_dev, tas); in tas_exit_codec()
880 struct device_node *node = client->dev.of_node; in tas_i2c_probe()
886 return -ENOMEM; in tas_i2c_probe()
888 mutex_init(&tas->mtx); in tas_i2c_probe()
889 tas->i2c = client; in tas_i2c_probe()
893 tas->drc_range = TAS3004_DRC_MAX / 2; in tas_i2c_probe()
895 strscpy(tas->codec.name, "tas", MAX_CODEC_NAME_LEN); in tas_i2c_probe()
896 tas->codec.owner = THIS_MODULE; in tas_i2c_probe()
897 tas->codec.init = tas_init_codec; in tas_i2c_probe()
898 tas->codec.exit = tas_exit_codec; in tas_i2c_probe()
899 tas->codec.node = of_node_get(node); in tas_i2c_probe()
901 if (aoa_codec_register(&tas->codec)) { in tas_i2c_probe()
905 "snd-aoa-codec-tas: tas found, addr 0x%02x on %pOF\n", in tas_i2c_probe()
906 (unsigned int)client->addr, node); in tas_i2c_probe()
909 mutex_destroy(&tas->mtx); in tas_i2c_probe()
911 return -EINVAL; in tas_i2c_probe()
919 aoa_codec_unregister(&tas->codec); in tas_i2c_remove()
920 of_node_put(tas->codec.node); in tas_i2c_remove()
925 mutex_destroy(&tas->mtx); in tas_i2c_remove()