63 #include <linux/i2c.h>
67 #include <linux/module.h>
69 #include <linux/slab.h>
79 #include "../soundbus/soundbus.h"
81 #define PFX "snd-aoa-codec-tas: "
102 static int tas_reset_init(
struct tas *
tas);
117 static void tas3004_set_drc(
struct tas *tas)
119 unsigned char val[6];
139 static void tas_set_treble(
struct tas *tas)
143 tmp = tas3004_treble(tas->
treble);
147 static void tas_set_bass(
struct tas *tas)
151 tmp = tas3004_bass(tas->
bass);
155 static void tas_set_volume(
struct tas *tas)
164 if (left > 177) left = 177;
165 if (right > 177) right = 177;
167 if (tas->
mute_l) left = 0;
168 if (tas->
mute_r) right = 0;
176 tmp = tas_gaintable[
left];
180 tmp = tas_gaintable[
right];
187 static void tas_set_mixer(
struct tas *tas)
195 if (val > 177) val = 177;
196 tmp = tas_gaintable[
val];
197 block[3*i+0] = tmp>>16;
198 block[3*i+1] = tmp>>8;
205 if (val > 177) val = 177;
206 tmp = tas_gaintable[
val];
207 block[3*i+0] = tmp>>16;
208 block[3*i+1] = tmp>>8;
222 .dev_register = tas_dev_register,
225 static int tas_snd_vol_info(
struct snd_kcontrol *kcontrol,
235 static int tas_snd_vol_get(
struct snd_kcontrol *kcontrol,
247 static int tas_snd_vol_put(
struct snd_kcontrol *kcontrol,
252 if (ucontrol->
value.integer.value[0] < 0 ||
253 ucontrol->
value.integer.value[0] > 177)
255 if (ucontrol->
value.integer.value[1] < 0 ||
256 ucontrol->
value.integer.value[1] > 177)
276 .name =
"Master Playback Volume",
278 .info = tas_snd_vol_info,
279 .get = tas_snd_vol_get,
280 .put = tas_snd_vol_put,
283 #define tas_snd_mute_info snd_ctl_boolean_stereo_info
285 static int tas_snd_mute_get(
struct snd_kcontrol *kcontrol,
297 static int tas_snd_mute_put(
struct snd_kcontrol *kcontrol,
303 if (tas->
mute_l == !ucontrol->
value.integer.value[0]
304 && tas->
mute_r == !ucontrol->
value.integer.value[1]) {
319 .name =
"Master Playback Switch",
322 .get = tas_snd_mute_get,
323 .put = tas_snd_mute_put,
326 static int tas_snd_mixer_info(
struct snd_kcontrol *kcontrol,
336 static int tas_snd_mixer_get(
struct snd_kcontrol *kcontrol,
350 static int tas_snd_mixer_put(
struct snd_kcontrol *kcontrol,
357 if (tas->
mixer_l[idx] == ucontrol->
value.integer.value[0]
358 && tas->
mixer_r[idx] == ucontrol->
value.integer.value[1]) {
372 #define MIXER_CONTROL(n,descr,idx) \
373 static struct snd_kcontrol_new n##_control = { \
374 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
375 .name = descr " Playback Volume", \
376 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
377 .info = tas_snd_mixer_info, \
378 .get = tas_snd_mixer_get, \
379 .put = tas_snd_mixer_put, \
380 .private_value = idx, \
386 static int tas_snd_drc_range_info(
struct snd_kcontrol *kcontrol,
396 static int tas_snd_drc_range_get(
struct snd_kcontrol *kcontrol,
407 static int tas_snd_drc_range_put(
struct snd_kcontrol *kcontrol,
412 if (ucontrol->
value.integer.value[0] < 0 ||
424 tas3004_set_drc(tas);
433 .info = tas_snd_drc_range_info,
434 .get = tas_snd_drc_range_get,
435 .put = tas_snd_drc_range_put,
438 #define tas_snd_drc_switch_info snd_ctl_boolean_mono_info
440 static int tas_snd_drc_switch_get(
struct snd_kcontrol *kcontrol,
451 static int tas_snd_drc_switch_put(
struct snd_kcontrol *kcontrol,
464 tas3004_set_drc(tas);
471 .name =
"DRC Range Switch",
474 .get = tas_snd_drc_switch_get,
475 .put = tas_snd_drc_switch_put,
478 static int tas_snd_capture_source_info(
struct snd_kcontrol *kcontrol,
481 static char *texts[] = {
"Line-In",
"Microphone" };
492 static int tas_snd_capture_source_get(
struct snd_kcontrol *kcontrol,
503 static int tas_snd_capture_source_put(
struct snd_kcontrol *kcontrol,
509 if (ucontrol->
value.enumerated.item[0] > 1)
520 if (ucontrol->
value.enumerated.item[0])
523 if (oldacr == tas->
acr) {
546 .name =
"Capture Source",
548 .info = tas_snd_capture_source_info,
549 .get = tas_snd_capture_source_get,
550 .put = tas_snd_capture_source_put,
553 static int tas_snd_treble_info(
struct snd_kcontrol *kcontrol,
563 static int tas_snd_treble_get(
struct snd_kcontrol *kcontrol,
574 static int tas_snd_treble_put(
struct snd_kcontrol *kcontrol,
583 if (tas->
treble == ucontrol->
value.integer.value[0]) {
599 .info = tas_snd_treble_info,
600 .get = tas_snd_treble_get,
601 .put = tas_snd_treble_put,
604 static int tas_snd_bass_info(
struct snd_kcontrol *kcontrol,
614 static int tas_snd_bass_get(
struct snd_kcontrol *kcontrol,
620 ucontrol->
value.integer.value[0] = tas->
bass;
625 static int tas_snd_bass_put(
struct snd_kcontrol *kcontrol,
634 if (tas->
bass == ucontrol->
value.integer.value[0]) {
639 tas->
bass = ucontrol->
value.integer.value[0];
650 .info = tas_snd_bass_info,
651 .get = tas_snd_bass_get,
652 .put = tas_snd_bass_put,
678 static int tas_reset_init(
struct tas *tas)
682 tas->
codec.gpio->methods->all_amps_off(tas->
codec.gpio);
684 tas->
codec.gpio->methods->set_hw_reset(tas->
codec.gpio, 0);
686 tas->
codec.gpio->methods->set_hw_reset(tas->
codec.gpio, 1);
688 tas->
codec.gpio->methods->set_hw_reset(tas->
codec.gpio, 0);
690 tas->
codec.gpio->methods->all_amps_restore(tas->
codec.gpio);
704 tas3004_set_drc(tas);
728 tas->
codec.gpio->methods->all_amps_off(tas->
codec.gpio);
738 tas->
codec.gpio->methods->all_amps_restore(tas->
codec.gpio);
752 static int tas_suspend(
struct tas *tas)
762 static int tas_resume(
struct tas *tas)
784 #define _tas_suspend NULL
785 #define _tas_resume NULL
789 .transfers = tas_transfers,
793 .sysclock_factor = 256,
797 .usable = tas_usable,
798 .switch_clock = tas_switch_clock,
805 struct tas *tas = codec_to_tas(codec);
808 if (!tas->
codec.gpio || !tas->
codec.gpio->methods) {
814 if (tas_reset_init(tas)) {
822 if (tas->
codec.soundbus_dev->attach_codec(tas->
codec.soundbus_dev,
824 &tas_codec_info, tas)) {
871 tas->
codec.soundbus_dev->detach_codec(tas->
codec.soundbus_dev, tas);
876 static void tas_exit_codec(
struct aoa_codec *codec)
878 struct tas *tas = codec_to_tas(codec);
880 if (!tas->
codec.soundbus_dev)
882 tas->
codec.soundbus_dev->detach_codec(tas->
codec.soundbus_dev, tas);
892 tas = kzalloc(
sizeof(
struct tas),
GFP_KERNEL);
899 i2c_set_clientdata(client, tas);
906 tas->
codec.init = tas_init_codec;
907 tas->
codec.exit = tas_exit_codec;
908 tas->
codec.node = of_node_get(node);
914 "snd-aoa-codec-tas: tas found, addr 0x%02x on %s\n",
923 static int tas_i2c_remove(
struct i2c_client *client)
925 struct tas *tas = i2c_get_clientdata(client);
929 of_node_put(tas->
codec.node);
940 {
"MAC,tas3004", 0 },
947 .name =
"aoa_codec_tas",
950 .probe = tas_i2c_probe,
951 .remove = tas_i2c_remove,
952 .id_table = tas_i2c_id,