Lines Matching refs:tas

82 struct tas {  struct
100 static int tas_reset_init(struct tas *tas); argument
102 static struct tas *codec_to_tas(struct aoa_codec *codec) in codec_to_tas()
104 return container_of(codec, struct tas, codec); in codec_to_tas()
107 static inline int tas_write_reg(struct tas *tas, u8 reg, u8 len, u8 *data) in tas_write_reg() argument
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()
115 static void tas3004_set_drc(struct tas *tas) in tas3004_set_drc() argument
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()
134 tas_write_reg(tas, TAS_REG_DRC, 6, val); in tas3004_set_drc()
137 static void tas_set_treble(struct tas *tas) in tas_set_treble() argument
141 tmp = tas3004_treble(tas->treble); in tas_set_treble()
142 tas_write_reg(tas, TAS_REG_TREBLE, 1, &tmp); in tas_set_treble()
145 static void tas_set_bass(struct tas *tas) in tas_set_bass() argument
149 tmp = tas3004_bass(tas->bass); in tas_set_bass()
150 tas_write_reg(tas, TAS_REG_BASS, 1, &tmp); in tas_set_bass()
153 static void tas_set_volume(struct tas *tas) in tas_set_volume() argument
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()
182 tas_write_reg(tas, TAS_REG_VOL, 6, block); in tas_set_volume()
185 static void tas_set_mixer(struct tas *tas) in tas_set_mixer() argument
192 val = tas->mixer_l[i]; in tas_set_mixer()
199 tas_write_reg(tas, TAS_REG_LMIX, 9, block); in tas_set_mixer()
202 val = tas->mixer_r[i]; in tas_set_mixer()
209 tas_write_reg(tas, TAS_REG_RMIX, 9, block); in tas_set_mixer()
236 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_vol_get() local
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()
248 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_vol_put() local
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()
267 tas_set_volume(tas); in tas_snd_vol_put()
268 mutex_unlock(&tas->mtx); in tas_snd_vol_put()
286 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_mute_get() local
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()
298 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_mute_put() local
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()
310 tas_set_volume(tas); in tas_snd_mute_put()
311 mutex_unlock(&tas->mtx); in tas_snd_mute_put()
337 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_mixer_get() local
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()
351 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_mixer_put() local
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()
365 tas_set_mixer(tas); in tas_snd_mixer_put()
366 mutex_unlock(&tas->mtx); in tas_snd_mixer_put()
397 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_drc_range_get() local
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()
408 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_drc_range_put() local
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()
422 tas3004_set_drc(tas); in tas_snd_drc_range_put()
423 mutex_unlock(&tas->mtx); in tas_snd_drc_range_put()
441 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_drc_switch_get() local
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()
452 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_drc_switch_put() local
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()
462 tas3004_set_drc(tas); in tas_snd_drc_switch_put()
463 mutex_unlock(&tas->mtx); in tas_snd_drc_switch_put()
487 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_capture_source_get() local
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()
498 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_capture_source_put() local
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()
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()
558 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_treble_get() local
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()
569 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_treble_put() local
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()
582 tas_set_treble(tas); in tas_snd_treble_put()
583 mutex_unlock(&tas->mtx); in tas_snd_treble_put()
609 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_bass_get() local
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()
620 struct tas *tas = snd_kcontrol_chip(kcontrol); in tas_snd_bass_put() local
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()
633 tas_set_bass(tas); in tas_snd_bass_put()
634 mutex_unlock(&tas->mtx); in tas_snd_bass_put()
670 static int tas_reset_init(struct tas *tas) in tas_reset_init() argument
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()
685 if (tas_write_reg(tas, TAS_REG_MCS, 1, &tmp)) 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()
693 if (tas_write_reg(tas, TAS_REG_MCS2, 1, &tmp)) in tas_reset_init()
696 tas3004_set_drc(tas); in tas_reset_init()
699 tas->treble = TAS3004_TREBLE_ZERO; in tas_reset_init()
700 tas->bass = TAS3004_BASS_ZERO; in tas_reset_init()
701 tas_set_treble(tas); in tas_reset_init()
702 tas_set_bass(tas); 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()
715 struct tas *tas = cii->codec_data; in tas_switch_clock() local
720 tas->codec.gpio->methods->all_amps_off(tas->codec.gpio); in tas_switch_clock()
721 tas->hw_enabled = 0; in tas_switch_clock()
725 mutex_lock(&tas->mtx); in tas_switch_clock()
726 tas_reset_init(tas); in tas_switch_clock()
727 tas_set_volume(tas); in tas_switch_clock()
728 tas_set_mixer(tas); 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()
744 static int tas_suspend(struct tas *tas) in tas_suspend() argument
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()
754 static int tas_resume(struct tas *tas) in tas_resume() argument
757 mutex_lock(&tas->mtx); in tas_resume()
758 tas_reset_init(tas); in tas_resume()
759 tas_set_volume(tas); in tas_resume()
760 tas_set_mixer(tas); in tas_resume()
761 tas->hw_enabled = 1; in tas_resume()
762 mutex_unlock(&tas->mtx); in tas_resume()
797 struct tas *tas = codec_to_tas(codec); in tas_init_codec() local
800 if (!tas->codec.gpio || !tas->codec.gpio->methods) { in tas_init_codec()
805 mutex_lock(&tas->mtx); in tas_init_codec()
806 if (tas_reset_init(tas)) { in tas_init_codec()
808 mutex_unlock(&tas->mtx); 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()
816 &tas_codec_info, tas)) { in tas_init_codec()
821 if (aoa_snd_device_new(SNDRV_DEV_CODEC, tas, &ops)) { in tas_init_codec()
825 err = aoa_snd_ctl_add(snd_ctl_new1(&volume_control, tas)); in tas_init_codec()
829 err = aoa_snd_ctl_add(snd_ctl_new1(&mute_control, tas)); in tas_init_codec()
833 err = aoa_snd_ctl_add(snd_ctl_new1(&pcm1_control, tas)); in tas_init_codec()
837 err = aoa_snd_ctl_add(snd_ctl_new1(&monitor_control, tas)); in tas_init_codec()
841 err = aoa_snd_ctl_add(snd_ctl_new1(&capture_source_control, tas)); in tas_init_codec()
845 err = aoa_snd_ctl_add(snd_ctl_new1(&drc_range_control, tas)); in tas_init_codec()
849 err = aoa_snd_ctl_add(snd_ctl_new1(&drc_switch_control, tas)); in tas_init_codec()
853 err = aoa_snd_ctl_add(snd_ctl_new1(&treble_control, tas)); in tas_init_codec()
857 err = aoa_snd_ctl_add(snd_ctl_new1(&bass_control, tas)); in tas_init_codec()
863 tas->codec.soundbus_dev->detach_codec(tas->codec.soundbus_dev, tas); in tas_init_codec()
864 snd_device_free(aoa_get_card(), tas); in tas_init_codec()
870 struct tas *tas = codec_to_tas(codec); in tas_exit_codec() local
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()
882 struct tas *tas; in tas_i2c_probe() local
884 tas = kzalloc(sizeof(struct tas), GFP_KERNEL); in tas_i2c_probe()
886 if (!tas) in tas_i2c_probe()
889 mutex_init(&tas->mtx); in tas_i2c_probe()
890 tas->i2c = client; in tas_i2c_probe()
891 i2c_set_clientdata(client, tas); in tas_i2c_probe()
894 tas->drc_range = TAS3004_DRC_MAX / 2; in tas_i2c_probe()
896 strscpy(tas->codec.name, "tas", MAX_CODEC_NAME_LEN); in tas_i2c_probe()
897 tas->codec.owner = THIS_MODULE; in tas_i2c_probe()
898 tas->codec.init = tas_init_codec; in tas_i2c_probe()
899 tas->codec.exit = tas_exit_codec; in tas_i2c_probe()
900 tas->codec.node = of_node_get(node); in tas_i2c_probe()
902 if (aoa_codec_register(&tas->codec)) { in tas_i2c_probe()
910 mutex_destroy(&tas->mtx); in tas_i2c_probe()
911 kfree(tas); in tas_i2c_probe()
917 struct tas *tas = i2c_get_clientdata(client); in tas_i2c_remove() local
920 aoa_codec_unregister(&tas->codec); in tas_i2c_remove()
921 of_node_put(tas->codec.node); in tas_i2c_remove()
924 tas_write_reg(tas, TAS_REG_ACR, 1, &tmp); in tas_i2c_remove()
926 mutex_destroy(&tas->mtx); in tas_i2c_remove()
927 kfree(tas); in tas_i2c_remove()