Lines Matching refs:tas

84 struct tas {  struct
102 static int tas_reset_init(struct tas *tas); argument
104 static struct tas *codec_to_tas(struct aoa_codec *codec) in codec_to_tas()
106 return container_of(codec, struct tas, codec); in codec_to_tas()
109 static inline int tas_write_reg(struct tas *tas, u8 reg, u8 len, u8 *data) in tas_write_reg() argument
112 return i2c_smbus_write_byte_data(tas->i2c, reg, *data); in tas_write_reg()
114 return i2c_smbus_write_i2c_block_data(tas->i2c, reg, len, data); in tas_write_reg()
117 static void tas3004_set_drc(struct tas *tas) in tas3004_set_drc() argument
121 if (tas->drc_enabled) in tas3004_set_drc()
126 if (tas->drc_range > 0xef) in tas3004_set_drc()
128 else if (tas->drc_range < 0) in tas3004_set_drc()
131 val[2] = tas->drc_range; in tas3004_set_drc()
136 tas_write_reg(tas, TAS_REG_DRC, 6, val); in tas3004_set_drc()
139 static void tas_set_treble(struct tas *tas) in tas_set_treble() argument
143 tmp = tas3004_treble(tas->treble); in tas_set_treble()
144 tas_write_reg(tas, TAS_REG_TREBLE, 1, &tmp); in tas_set_treble()
147 static void tas_set_bass(struct tas *tas) in tas_set_bass() argument
151 tmp = tas3004_bass(tas->bass); in tas_set_bass()
152 tas_write_reg(tas, TAS_REG_BASS, 1, &tmp); in tas_set_bass()
155 static void tas_set_volume(struct tas *tas) in tas_set_volume() argument
161 left = tas->cached_volume_l; in tas_set_volume()
162 right = tas->cached_volume_r; in tas_set_volume()
167 if (tas->mute_l) left = 0; in tas_set_volume()
168 if (tas->mute_r) right = 0; in tas_set_volume()
184 tas_write_reg(tas, TAS_REG_VOL, 6, block); in tas_set_volume()
187 static void tas_set_mixer(struct tas *tas) in tas_set_mixer() argument
194 val = tas->mixer_l[i]; in tas_set_mixer()
201 tas_write_reg(tas, TAS_REG_LMIX, 9, block); in tas_set_mixer()
204 val = tas->mixer_r[i]; in tas_set_mixer()
211 tas_write_reg(tas, TAS_REG_RMIX, 9, block); in tas_set_mixer()
238 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_vol_get() local
240 mutex_lock(&tas->mtx); in tas_snd_vol_get()
241 ucontrol->value.integer.value[0] = tas->cached_volume_l; in tas_snd_vol_get()
242 ucontrol->value.integer.value[1] = tas->cached_volume_r; in tas_snd_vol_get()
243 mutex_unlock(&tas->mtx); in tas_snd_vol_get()
250 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_vol_put() local
259 mutex_lock(&tas->mtx); in tas_snd_vol_put()
260 if (tas->cached_volume_l == ucontrol->value.integer.value[0] in tas_snd_vol_put()
261 && tas->cached_volume_r == ucontrol->value.integer.value[1]) { in tas_snd_vol_put()
262 mutex_unlock(&tas->mtx); in tas_snd_vol_put()
266 tas->cached_volume_l = ucontrol->value.integer.value[0]; in tas_snd_vol_put()
267 tas->cached_volume_r = ucontrol->value.integer.value[1]; in tas_snd_vol_put()
268 if (tas->hw_enabled) in tas_snd_vol_put()
269 tas_set_volume(tas); in tas_snd_vol_put()
270 mutex_unlock(&tas->mtx); in tas_snd_vol_put()
288 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_mute_get() local
290 mutex_lock(&tas->mtx); in tas_snd_mute_get()
291 ucontrol->value.integer.value[0] = !tas->mute_l; in tas_snd_mute_get()
292 ucontrol->value.integer.value[1] = !tas->mute_r; in tas_snd_mute_get()
293 mutex_unlock(&tas->mtx); in tas_snd_mute_get()
300 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_mute_put() local
302 mutex_lock(&tas->mtx); in tas_snd_mute_put()
303 if (tas->mute_l == !ucontrol->value.integer.value[0] in tas_snd_mute_put()
304 && tas->mute_r == !ucontrol->value.integer.value[1]) { in tas_snd_mute_put()
305 mutex_unlock(&tas->mtx); in tas_snd_mute_put()
309 tas->mute_l = !ucontrol->value.integer.value[0]; in tas_snd_mute_put()
310 tas->mute_r = !ucontrol->value.integer.value[1]; in tas_snd_mute_put()
311 if (tas->hw_enabled) in tas_snd_mute_put()
312 tas_set_volume(tas); in tas_snd_mute_put()
313 mutex_unlock(&tas->mtx); in tas_snd_mute_put()
339 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_mixer_get() local
342 mutex_lock(&tas->mtx); in tas_snd_mixer_get()
343 ucontrol->value.integer.value[0] = tas->mixer_l[idx]; in tas_snd_mixer_get()
344 ucontrol->value.integer.value[1] = tas->mixer_r[idx]; in tas_snd_mixer_get()
345 mutex_unlock(&tas->mtx); in tas_snd_mixer_get()
353 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_mixer_put() local
356 mutex_lock(&tas->mtx); in tas_snd_mixer_put()
357 if (tas->mixer_l[idx] == ucontrol->value.integer.value[0] in tas_snd_mixer_put()
358 && tas->mixer_r[idx] == ucontrol->value.integer.value[1]) { in tas_snd_mixer_put()
359 mutex_unlock(&tas->mtx); in tas_snd_mixer_put()
363 tas->mixer_l[idx] = ucontrol->value.integer.value[0]; in tas_snd_mixer_put()
364 tas->mixer_r[idx] = ucontrol->value.integer.value[1]; in tas_snd_mixer_put()
366 if (tas->hw_enabled) in tas_snd_mixer_put()
367 tas_set_mixer(tas); in tas_snd_mixer_put()
368 mutex_unlock(&tas->mtx); in tas_snd_mixer_put()
399 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_drc_range_get() local
401 mutex_lock(&tas->mtx); in tas_snd_drc_range_get()
402 ucontrol->value.integer.value[0] = tas->drc_range; in tas_snd_drc_range_get()
403 mutex_unlock(&tas->mtx); in tas_snd_drc_range_get()
410 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_drc_range_put() local
416 mutex_lock(&tas->mtx); in tas_snd_drc_range_put()
417 if (tas->drc_range == ucontrol->value.integer.value[0]) { in tas_snd_drc_range_put()
418 mutex_unlock(&tas->mtx); in tas_snd_drc_range_put()
422 tas->drc_range = ucontrol->value.integer.value[0]; in tas_snd_drc_range_put()
423 if (tas->hw_enabled) in tas_snd_drc_range_put()
424 tas3004_set_drc(tas); in tas_snd_drc_range_put()
425 mutex_unlock(&tas->mtx); in tas_snd_drc_range_put()
443 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_drc_switch_get() local
445 mutex_lock(&tas->mtx); in tas_snd_drc_switch_get()
446 ucontrol->value.integer.value[0] = tas->drc_enabled; in tas_snd_drc_switch_get()
447 mutex_unlock(&tas->mtx); in tas_snd_drc_switch_get()
454 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_drc_switch_put() local
456 mutex_lock(&tas->mtx); in tas_snd_drc_switch_put()
457 if (tas->drc_enabled == ucontrol->value.integer.value[0]) { in tas_snd_drc_switch_put()
458 mutex_unlock(&tas->mtx); in tas_snd_drc_switch_put()
462 tas->drc_enabled = !!ucontrol->value.integer.value[0]; in tas_snd_drc_switch_put()
463 if (tas->hw_enabled) in tas_snd_drc_switch_put()
464 tas3004_set_drc(tas); in tas_snd_drc_switch_put()
465 mutex_unlock(&tas->mtx); in tas_snd_drc_switch_put()
489 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_capture_source_get() local
491 mutex_lock(&tas->mtx); in tas_snd_capture_source_get()
492 ucontrol->value.enumerated.item[0] = !!(tas->acr & TAS_ACR_INPUT_B); in tas_snd_capture_source_get()
493 mutex_unlock(&tas->mtx); in tas_snd_capture_source_get()
500 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_capture_source_put() local
505 mutex_lock(&tas->mtx); in tas_snd_capture_source_put()
506 oldacr = tas->acr; in tas_snd_capture_source_put()
513 tas->acr &= ~(TAS_ACR_INPUT_B | TAS_ACR_B_MONAUREAL); in tas_snd_capture_source_put()
515 tas->acr |= TAS_ACR_INPUT_B | TAS_ACR_B_MONAUREAL | in tas_snd_capture_source_put()
517 if (oldacr == tas->acr) { in tas_snd_capture_source_put()
518 mutex_unlock(&tas->mtx); in tas_snd_capture_source_put()
521 if (tas->hw_enabled) in tas_snd_capture_source_put()
522 tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr); in tas_snd_capture_source_put()
523 mutex_unlock(&tas->mtx); in tas_snd_capture_source_put()
560 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_treble_get() local
562 mutex_lock(&tas->mtx); in tas_snd_treble_get()
563 ucontrol->value.integer.value[0] = tas->treble; in tas_snd_treble_get()
564 mutex_unlock(&tas->mtx); in tas_snd_treble_get()
571 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_treble_put() local
576 mutex_lock(&tas->mtx); in tas_snd_treble_put()
577 if (tas->treble == ucontrol->value.integer.value[0]) { in tas_snd_treble_put()
578 mutex_unlock(&tas->mtx); in tas_snd_treble_put()
582 tas->treble = ucontrol->value.integer.value[0]; in tas_snd_treble_put()
583 if (tas->hw_enabled) in tas_snd_treble_put()
584 tas_set_treble(tas); in tas_snd_treble_put()
585 mutex_unlock(&tas->mtx); in tas_snd_treble_put()
611 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_bass_get() local
613 mutex_lock(&tas->mtx); in tas_snd_bass_get()
614 ucontrol->value.integer.value[0] = tas->bass; in tas_snd_bass_get()
615 mutex_unlock(&tas->mtx); in tas_snd_bass_get()
622 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_bass_put() local
627 mutex_lock(&tas->mtx); in tas_snd_bass_put()
628 if (tas->bass == ucontrol->value.integer.value[0]) { in tas_snd_bass_put()
629 mutex_unlock(&tas->mtx); in tas_snd_bass_put()
633 tas->bass = ucontrol->value.integer.value[0]; in tas_snd_bass_put()
634 if (tas->hw_enabled) in tas_snd_bass_put()
635 tas_set_bass(tas); in tas_snd_bass_put()
636 mutex_unlock(&tas->mtx); in tas_snd_bass_put()
672 static int tas_reset_init(struct tas *tas) in tas_reset_init() argument
676 tas->codec.gpio->methods->all_amps_off(tas->codec.gpio); in tas_reset_init()
678 tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 0); in tas_reset_init()
680 tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 1); in tas_reset_init()
682 tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 0); in tas_reset_init()
684 tas->codec.gpio->methods->all_amps_restore(tas->codec.gpio); in tas_reset_init()
687 if (tas_write_reg(tas, TAS_REG_MCS, 1, &tmp)) in tas_reset_init()
690 tas->acr |= TAS_ACR_ANALOG_PDOWN; in tas_reset_init()
691 if (tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr)) in tas_reset_init()
695 if (tas_write_reg(tas, TAS_REG_MCS2, 1, &tmp)) in tas_reset_init()
698 tas3004_set_drc(tas); in tas_reset_init()
701 tas->treble = TAS3004_TREBLE_ZERO; in tas_reset_init()
702 tas->bass = TAS3004_BASS_ZERO; in tas_reset_init()
703 tas_set_treble(tas); in tas_reset_init()
704 tas_set_bass(tas); in tas_reset_init()
706 tas->acr &= ~TAS_ACR_ANALOG_PDOWN; in tas_reset_init()
707 if (tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr)) in tas_reset_init()
717 struct tas *tas = cii->codec_data; in tas_switch_clock() local
722 tas->codec.gpio->methods->all_amps_off(tas->codec.gpio); in tas_switch_clock()
723 tas->hw_enabled = 0; in tas_switch_clock()
727 mutex_lock(&tas->mtx); in tas_switch_clock()
728 tas_reset_init(tas); in tas_switch_clock()
729 tas_set_volume(tas); in tas_switch_clock()
730 tas_set_mixer(tas); in tas_switch_clock()
731 tas->hw_enabled = 1; in tas_switch_clock()
732 tas->codec.gpio->methods->all_amps_restore(tas->codec.gpio); in tas_switch_clock()
733 mutex_unlock(&tas->mtx); in tas_switch_clock()
746 static int tas_suspend(struct tas *tas) in tas_suspend() argument
748 mutex_lock(&tas->mtx); in tas_suspend()
749 tas->hw_enabled = 0; in tas_suspend()
750 tas->acr |= TAS_ACR_ANALOG_PDOWN; in tas_suspend()
751 tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr); in tas_suspend()
752 mutex_unlock(&tas->mtx); in tas_suspend()
756 static int tas_resume(struct tas *tas) in tas_resume() argument
759 mutex_lock(&tas->mtx); in tas_resume()
760 tas_reset_init(tas); in tas_resume()
761 tas_set_volume(tas); in tas_resume()
762 tas_set_mixer(tas); in tas_resume()
763 tas->hw_enabled = 1; in tas_resume()
764 mutex_unlock(&tas->mtx); in tas_resume()
799 struct tas *tas = codec_to_tas(codec); in tas_init_codec() local
802 if (!tas->codec.gpio || !tas->codec.gpio->methods) { in tas_init_codec()
807 mutex_lock(&tas->mtx); in tas_init_codec()
808 if (tas_reset_init(tas)) { in tas_init_codec()
810 mutex_unlock(&tas->mtx); in tas_init_codec()
813 tas->hw_enabled = 1; in tas_init_codec()
814 mutex_unlock(&tas->mtx); in tas_init_codec()
816 if (tas->codec.soundbus_dev->attach_codec(tas->codec.soundbus_dev, in tas_init_codec()
818 &tas_codec_info, tas)) { in tas_init_codec()
823 if (aoa_snd_device_new(SNDRV_DEV_CODEC, tas, &ops)) { in tas_init_codec()
827 err = aoa_snd_ctl_add(snd_ctl_new1(&volume_control, tas)); in tas_init_codec()
831 err = aoa_snd_ctl_add(snd_ctl_new1(&mute_control, tas)); in tas_init_codec()
835 err = aoa_snd_ctl_add(snd_ctl_new1(&pcm1_control, tas)); in tas_init_codec()
839 err = aoa_snd_ctl_add(snd_ctl_new1(&monitor_control, tas)); in tas_init_codec()
843 err = aoa_snd_ctl_add(snd_ctl_new1(&capture_source_control, tas)); in tas_init_codec()
847 err = aoa_snd_ctl_add(snd_ctl_new1(&drc_range_control, tas)); in tas_init_codec()
851 err = aoa_snd_ctl_add(snd_ctl_new1(&drc_switch_control, tas)); in tas_init_codec()
855 err = aoa_snd_ctl_add(snd_ctl_new1(&treble_control, tas)); in tas_init_codec()
859 err = aoa_snd_ctl_add(snd_ctl_new1(&bass_control, tas)); in tas_init_codec()
865 tas->codec.soundbus_dev->detach_codec(tas->codec.soundbus_dev, tas); in tas_init_codec()
866 snd_device_free(aoa_get_card(), tas); in tas_init_codec()
872 struct tas *tas = codec_to_tas(codec); in tas_exit_codec() local
874 if (!tas->codec.soundbus_dev) in tas_exit_codec()
876 tas->codec.soundbus_dev->detach_codec(tas->codec.soundbus_dev, tas); in tas_exit_codec()
884 struct tas *tas; in tas_i2c_probe() local
886 tas = kzalloc(sizeof(struct tas), GFP_KERNEL); in tas_i2c_probe()
888 if (!tas) in tas_i2c_probe()
891 mutex_init(&tas->mtx); in tas_i2c_probe()
892 tas->i2c = client; in tas_i2c_probe()
893 i2c_set_clientdata(client, tas); in tas_i2c_probe()
896 tas->drc_range = TAS3004_DRC_MAX / 2; in tas_i2c_probe()
898 strlcpy(tas->codec.name, "tas", MAX_CODEC_NAME_LEN); in tas_i2c_probe()
899 tas->codec.owner = THIS_MODULE; in tas_i2c_probe()
900 tas->codec.init = tas_init_codec; in tas_i2c_probe()
901 tas->codec.exit = tas_exit_codec; in tas_i2c_probe()
902 tas->codec.node = of_node_get(node); in tas_i2c_probe()
904 if (aoa_codec_register(&tas->codec)) { in tas_i2c_probe()
912 mutex_destroy(&tas->mtx); in tas_i2c_probe()
913 kfree(tas); in tas_i2c_probe()
919 struct tas *tas = i2c_get_clientdata(client); in tas_i2c_remove() local
922 aoa_codec_unregister(&tas->codec); in tas_i2c_remove()
923 of_node_put(tas->codec.node); in tas_i2c_remove()
926 tas_write_reg(tas, TAS_REG_ACR, 1, &tmp); in tas_i2c_remove()
928 mutex_destroy(&tas->mtx); in tas_i2c_remove()
929 kfree(tas); in tas_i2c_remove()