Lines Matching refs:tas
83 struct tas { struct
101 static int tas_reset_init(struct tas *tas); argument
103 static struct tas *codec_to_tas(struct aoa_codec *codec) in codec_to_tas()
105 return container_of(codec, struct tas, codec); in codec_to_tas()
108 static inline int tas_write_reg(struct tas *tas, u8 reg, u8 len, u8 *data) in tas_write_reg() argument
111 return i2c_smbus_write_byte_data(tas->i2c, reg, *data); in tas_write_reg()
113 return i2c_smbus_write_i2c_block_data(tas->i2c, reg, len, data); in tas_write_reg()
116 static void tas3004_set_drc(struct tas *tas) in tas3004_set_drc() argument
120 if (tas->drc_enabled) in tas3004_set_drc()
125 if (tas->drc_range > 0xef) in tas3004_set_drc()
127 else if (tas->drc_range < 0) in tas3004_set_drc()
130 val[2] = tas->drc_range; in tas3004_set_drc()
135 tas_write_reg(tas, TAS_REG_DRC, 6, val); in tas3004_set_drc()
138 static void tas_set_treble(struct tas *tas) in tas_set_treble() argument
142 tmp = tas3004_treble(tas->treble); in tas_set_treble()
143 tas_write_reg(tas, TAS_REG_TREBLE, 1, &tmp); in tas_set_treble()
146 static void tas_set_bass(struct tas *tas) in tas_set_bass() argument
150 tmp = tas3004_bass(tas->bass); in tas_set_bass()
151 tas_write_reg(tas, TAS_REG_BASS, 1, &tmp); in tas_set_bass()
154 static void tas_set_volume(struct tas *tas) in tas_set_volume() argument
160 left = tas->cached_volume_l; in tas_set_volume()
161 right = tas->cached_volume_r; in tas_set_volume()
166 if (tas->mute_l) left = 0; in tas_set_volume()
167 if (tas->mute_r) right = 0; in tas_set_volume()
183 tas_write_reg(tas, TAS_REG_VOL, 6, block); in tas_set_volume()
186 static void tas_set_mixer(struct tas *tas) in tas_set_mixer() argument
193 val = tas->mixer_l[i]; in tas_set_mixer()
200 tas_write_reg(tas, TAS_REG_LMIX, 9, block); in tas_set_mixer()
203 val = tas->mixer_r[i]; in tas_set_mixer()
210 tas_write_reg(tas, TAS_REG_RMIX, 9, block); in tas_set_mixer()
237 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_vol_get() local
239 mutex_lock(&tas->mtx); in tas_snd_vol_get()
240 ucontrol->value.integer.value[0] = tas->cached_volume_l; in tas_snd_vol_get()
241 ucontrol->value.integer.value[1] = tas->cached_volume_r; in tas_snd_vol_get()
242 mutex_unlock(&tas->mtx); in tas_snd_vol_get()
249 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_vol_put() local
258 mutex_lock(&tas->mtx); in tas_snd_vol_put()
259 if (tas->cached_volume_l == ucontrol->value.integer.value[0] in tas_snd_vol_put()
260 && tas->cached_volume_r == ucontrol->value.integer.value[1]) { in tas_snd_vol_put()
261 mutex_unlock(&tas->mtx); in tas_snd_vol_put()
265 tas->cached_volume_l = ucontrol->value.integer.value[0]; in tas_snd_vol_put()
266 tas->cached_volume_r = ucontrol->value.integer.value[1]; in tas_snd_vol_put()
267 if (tas->hw_enabled) in tas_snd_vol_put()
268 tas_set_volume(tas); in tas_snd_vol_put()
269 mutex_unlock(&tas->mtx); in tas_snd_vol_put()
287 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_mute_get() local
289 mutex_lock(&tas->mtx); in tas_snd_mute_get()
290 ucontrol->value.integer.value[0] = !tas->mute_l; in tas_snd_mute_get()
291 ucontrol->value.integer.value[1] = !tas->mute_r; in tas_snd_mute_get()
292 mutex_unlock(&tas->mtx); in tas_snd_mute_get()
299 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_mute_put() local
301 mutex_lock(&tas->mtx); in tas_snd_mute_put()
302 if (tas->mute_l == !ucontrol->value.integer.value[0] in tas_snd_mute_put()
303 && tas->mute_r == !ucontrol->value.integer.value[1]) { in tas_snd_mute_put()
304 mutex_unlock(&tas->mtx); in tas_snd_mute_put()
308 tas->mute_l = !ucontrol->value.integer.value[0]; in tas_snd_mute_put()
309 tas->mute_r = !ucontrol->value.integer.value[1]; in tas_snd_mute_put()
310 if (tas->hw_enabled) in tas_snd_mute_put()
311 tas_set_volume(tas); in tas_snd_mute_put()
312 mutex_unlock(&tas->mtx); in tas_snd_mute_put()
338 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_mixer_get() local
341 mutex_lock(&tas->mtx); in tas_snd_mixer_get()
342 ucontrol->value.integer.value[0] = tas->mixer_l[idx]; in tas_snd_mixer_get()
343 ucontrol->value.integer.value[1] = tas->mixer_r[idx]; in tas_snd_mixer_get()
344 mutex_unlock(&tas->mtx); in tas_snd_mixer_get()
352 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_mixer_put() local
355 mutex_lock(&tas->mtx); in tas_snd_mixer_put()
356 if (tas->mixer_l[idx] == ucontrol->value.integer.value[0] in tas_snd_mixer_put()
357 && tas->mixer_r[idx] == ucontrol->value.integer.value[1]) { in tas_snd_mixer_put()
358 mutex_unlock(&tas->mtx); in tas_snd_mixer_put()
362 tas->mixer_l[idx] = ucontrol->value.integer.value[0]; in tas_snd_mixer_put()
363 tas->mixer_r[idx] = ucontrol->value.integer.value[1]; in tas_snd_mixer_put()
365 if (tas->hw_enabled) in tas_snd_mixer_put()
366 tas_set_mixer(tas); in tas_snd_mixer_put()
367 mutex_unlock(&tas->mtx); in tas_snd_mixer_put()
398 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_drc_range_get() local
400 mutex_lock(&tas->mtx); in tas_snd_drc_range_get()
401 ucontrol->value.integer.value[0] = tas->drc_range; in tas_snd_drc_range_get()
402 mutex_unlock(&tas->mtx); in tas_snd_drc_range_get()
409 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_drc_range_put() local
415 mutex_lock(&tas->mtx); in tas_snd_drc_range_put()
416 if (tas->drc_range == ucontrol->value.integer.value[0]) { in tas_snd_drc_range_put()
417 mutex_unlock(&tas->mtx); in tas_snd_drc_range_put()
421 tas->drc_range = ucontrol->value.integer.value[0]; in tas_snd_drc_range_put()
422 if (tas->hw_enabled) in tas_snd_drc_range_put()
423 tas3004_set_drc(tas); in tas_snd_drc_range_put()
424 mutex_unlock(&tas->mtx); in tas_snd_drc_range_put()
442 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_drc_switch_get() local
444 mutex_lock(&tas->mtx); in tas_snd_drc_switch_get()
445 ucontrol->value.integer.value[0] = tas->drc_enabled; in tas_snd_drc_switch_get()
446 mutex_unlock(&tas->mtx); in tas_snd_drc_switch_get()
453 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_drc_switch_put() local
455 mutex_lock(&tas->mtx); in tas_snd_drc_switch_put()
456 if (tas->drc_enabled == ucontrol->value.integer.value[0]) { in tas_snd_drc_switch_put()
457 mutex_unlock(&tas->mtx); in tas_snd_drc_switch_put()
461 tas->drc_enabled = !!ucontrol->value.integer.value[0]; in tas_snd_drc_switch_put()
462 if (tas->hw_enabled) in tas_snd_drc_switch_put()
463 tas3004_set_drc(tas); in tas_snd_drc_switch_put()
464 mutex_unlock(&tas->mtx); in tas_snd_drc_switch_put()
488 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_capture_source_get() local
490 mutex_lock(&tas->mtx); in tas_snd_capture_source_get()
491 ucontrol->value.enumerated.item[0] = !!(tas->acr & TAS_ACR_INPUT_B); in tas_snd_capture_source_get()
492 mutex_unlock(&tas->mtx); in tas_snd_capture_source_get()
499 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_capture_source_put() local
504 mutex_lock(&tas->mtx); in tas_snd_capture_source_put()
505 oldacr = tas->acr; in tas_snd_capture_source_put()
512 tas->acr &= ~(TAS_ACR_INPUT_B | TAS_ACR_B_MONAUREAL); in tas_snd_capture_source_put()
514 tas->acr |= TAS_ACR_INPUT_B | TAS_ACR_B_MONAUREAL | in tas_snd_capture_source_put()
516 if (oldacr == tas->acr) { in tas_snd_capture_source_put()
517 mutex_unlock(&tas->mtx); in tas_snd_capture_source_put()
520 if (tas->hw_enabled) in tas_snd_capture_source_put()
521 tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr); in tas_snd_capture_source_put()
522 mutex_unlock(&tas->mtx); in tas_snd_capture_source_put()
559 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_treble_get() local
561 mutex_lock(&tas->mtx); in tas_snd_treble_get()
562 ucontrol->value.integer.value[0] = tas->treble; in tas_snd_treble_get()
563 mutex_unlock(&tas->mtx); in tas_snd_treble_get()
570 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_treble_put() local
575 mutex_lock(&tas->mtx); in tas_snd_treble_put()
576 if (tas->treble == ucontrol->value.integer.value[0]) { in tas_snd_treble_put()
577 mutex_unlock(&tas->mtx); in tas_snd_treble_put()
581 tas->treble = ucontrol->value.integer.value[0]; in tas_snd_treble_put()
582 if (tas->hw_enabled) in tas_snd_treble_put()
583 tas_set_treble(tas); in tas_snd_treble_put()
584 mutex_unlock(&tas->mtx); in tas_snd_treble_put()
610 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_bass_get() local
612 mutex_lock(&tas->mtx); in tas_snd_bass_get()
613 ucontrol->value.integer.value[0] = tas->bass; in tas_snd_bass_get()
614 mutex_unlock(&tas->mtx); in tas_snd_bass_get()
621 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_bass_put() local
626 mutex_lock(&tas->mtx); in tas_snd_bass_put()
627 if (tas->bass == ucontrol->value.integer.value[0]) { in tas_snd_bass_put()
628 mutex_unlock(&tas->mtx); in tas_snd_bass_put()
632 tas->bass = ucontrol->value.integer.value[0]; in tas_snd_bass_put()
633 if (tas->hw_enabled) in tas_snd_bass_put()
634 tas_set_bass(tas); in tas_snd_bass_put()
635 mutex_unlock(&tas->mtx); in tas_snd_bass_put()
671 static int tas_reset_init(struct tas *tas) in tas_reset_init() argument
675 tas->codec.gpio->methods->all_amps_off(tas->codec.gpio); in tas_reset_init()
677 tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 0); in tas_reset_init()
679 tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 1); in tas_reset_init()
681 tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 0); in tas_reset_init()
683 tas->codec.gpio->methods->all_amps_restore(tas->codec.gpio); in tas_reset_init()
686 if (tas_write_reg(tas, TAS_REG_MCS, 1, &tmp)) in tas_reset_init()
689 tas->acr |= TAS_ACR_ANALOG_PDOWN; in tas_reset_init()
690 if (tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr)) in tas_reset_init()
694 if (tas_write_reg(tas, TAS_REG_MCS2, 1, &tmp)) in tas_reset_init()
697 tas3004_set_drc(tas); in tas_reset_init()
700 tas->treble = TAS3004_TREBLE_ZERO; in tas_reset_init()
701 tas->bass = TAS3004_BASS_ZERO; in tas_reset_init()
702 tas_set_treble(tas); in tas_reset_init()
703 tas_set_bass(tas); in tas_reset_init()
705 tas->acr &= ~TAS_ACR_ANALOG_PDOWN; in tas_reset_init()
706 if (tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr)) in tas_reset_init()
716 struct tas *tas = cii->codec_data; in tas_switch_clock() local
721 tas->codec.gpio->methods->all_amps_off(tas->codec.gpio); in tas_switch_clock()
722 tas->hw_enabled = 0; in tas_switch_clock()
726 mutex_lock(&tas->mtx); in tas_switch_clock()
727 tas_reset_init(tas); in tas_switch_clock()
728 tas_set_volume(tas); in tas_switch_clock()
729 tas_set_mixer(tas); in tas_switch_clock()
730 tas->hw_enabled = 1; in tas_switch_clock()
731 tas->codec.gpio->methods->all_amps_restore(tas->codec.gpio); in tas_switch_clock()
732 mutex_unlock(&tas->mtx); in tas_switch_clock()
745 static int tas_suspend(struct tas *tas) in tas_suspend() argument
747 mutex_lock(&tas->mtx); in tas_suspend()
748 tas->hw_enabled = 0; in tas_suspend()
749 tas->acr |= TAS_ACR_ANALOG_PDOWN; in tas_suspend()
750 tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr); in tas_suspend()
751 mutex_unlock(&tas->mtx); in tas_suspend()
755 static int tas_resume(struct tas *tas) in tas_resume() argument
758 mutex_lock(&tas->mtx); in tas_resume()
759 tas_reset_init(tas); in tas_resume()
760 tas_set_volume(tas); in tas_resume()
761 tas_set_mixer(tas); in tas_resume()
762 tas->hw_enabled = 1; in tas_resume()
763 mutex_unlock(&tas->mtx); in tas_resume()
798 struct tas *tas = codec_to_tas(codec); in tas_init_codec() local
801 if (!tas->codec.gpio || !tas->codec.gpio->methods) { in tas_init_codec()
806 mutex_lock(&tas->mtx); in tas_init_codec()
807 if (tas_reset_init(tas)) { in tas_init_codec()
809 mutex_unlock(&tas->mtx); in tas_init_codec()
812 tas->hw_enabled = 1; in tas_init_codec()
813 mutex_unlock(&tas->mtx); in tas_init_codec()
815 if (tas->codec.soundbus_dev->attach_codec(tas->codec.soundbus_dev, in tas_init_codec()
817 &tas_codec_info, tas)) { in tas_init_codec()
822 if (aoa_snd_device_new(SNDRV_DEV_CODEC, tas, &ops)) { in tas_init_codec()
826 err = aoa_snd_ctl_add(snd_ctl_new1(&volume_control, tas)); in tas_init_codec()
830 err = aoa_snd_ctl_add(snd_ctl_new1(&mute_control, tas)); in tas_init_codec()
834 err = aoa_snd_ctl_add(snd_ctl_new1(&pcm1_control, tas)); in tas_init_codec()
838 err = aoa_snd_ctl_add(snd_ctl_new1(&monitor_control, tas)); in tas_init_codec()
842 err = aoa_snd_ctl_add(snd_ctl_new1(&capture_source_control, tas)); in tas_init_codec()
846 err = aoa_snd_ctl_add(snd_ctl_new1(&drc_range_control, tas)); in tas_init_codec()
850 err = aoa_snd_ctl_add(snd_ctl_new1(&drc_switch_control, tas)); in tas_init_codec()
854 err = aoa_snd_ctl_add(snd_ctl_new1(&treble_control, tas)); in tas_init_codec()
858 err = aoa_snd_ctl_add(snd_ctl_new1(&bass_control, tas)); in tas_init_codec()
864 tas->codec.soundbus_dev->detach_codec(tas->codec.soundbus_dev, tas); in tas_init_codec()
865 snd_device_free(aoa_get_card(), tas); in tas_init_codec()
871 struct tas *tas = codec_to_tas(codec); in tas_exit_codec() local
873 if (!tas->codec.soundbus_dev) in tas_exit_codec()
875 tas->codec.soundbus_dev->detach_codec(tas->codec.soundbus_dev, tas); in tas_exit_codec()
883 struct tas *tas; in tas_i2c_probe() local
885 tas = kzalloc(sizeof(struct tas), GFP_KERNEL); in tas_i2c_probe()
887 if (!tas) in tas_i2c_probe()
890 mutex_init(&tas->mtx); in tas_i2c_probe()
891 tas->i2c = client; in tas_i2c_probe()
892 i2c_set_clientdata(client, tas); in tas_i2c_probe()
895 tas->drc_range = TAS3004_DRC_MAX / 2; in tas_i2c_probe()
897 strlcpy(tas->codec.name, "tas", MAX_CODEC_NAME_LEN); in tas_i2c_probe()
898 tas->codec.owner = THIS_MODULE; in tas_i2c_probe()
899 tas->codec.init = tas_init_codec; in tas_i2c_probe()
900 tas->codec.exit = tas_exit_codec; in tas_i2c_probe()
901 tas->codec.node = of_node_get(node); in tas_i2c_probe()
903 if (aoa_codec_register(&tas->codec)) { in tas_i2c_probe()
911 mutex_destroy(&tas->mtx); in tas_i2c_probe()
912 kfree(tas); in tas_i2c_probe()
918 struct tas *tas = i2c_get_clientdata(client); in tas_i2c_remove() local
921 aoa_codec_unregister(&tas->codec); in tas_i2c_remove()
922 of_node_put(tas->codec.node); in tas_i2c_remove()
925 tas_write_reg(tas, TAS_REG_ACR, 1, &tmp); in tas_i2c_remove()
927 mutex_destroy(&tas->mtx); in tas_i2c_remove()
928 kfree(tas); in tas_i2c_remove()