1 // SPDX-License-Identifier: GPL-2.0-only
3 * Apple Onboard Audio driver for tas codec
5 * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
8 * - How to distinguish between 3004 and versions?
11 * - This codec driver doesn't honour the 'connected'
12 * property of the aoa_codec struct, hence if
13 * it is used in machines where not everything is
14 * connected it will display wrong mixer elements.
15 * - Driver assumes that the microphone is always
16 * monaureal and connected to the right channel of
17 * the input. This should also be a codec-dependent
18 * flag, maybe the codec should have 3 different
19 * bits for the three different possibilities how
20 * it can be hooked up...
21 * But as long as I don't see any hardware hooked
23 * - As Apple notes in their code, the tas3004 seems
24 * to delay the right channel by one sample. You can
25 * see this when for example recording stereo in
26 * audacity, or recording the tas output via cable
27 * on another machine (use a sinus generator or so).
28 * I tried programming the BiQuads but couldn't
29 * make the delay work, maybe someone can read the
30 * datasheet and fix it. The relevant Apple comment
31 * is in AppleTAS3004Audio.cpp lines 1637 ff. Note
32 * that their comment describing how they program
33 * the filters sucks...
36 * - this should actually register *two* aoa_codec
37 * structs since it has two inputs. Then it must
38 * use the prepare callback to forbid running the
39 * secondary output on a different clock.
40 * Also, whatever bus knows how to do this must
41 * provide two soundbus_dev devices and the fabric
42 * must be able to link them correctly.
44 * I don't even know if Apple ever uses the second
45 * port on the tas3004 though, I don't think their
46 * i2s controllers can even do it. OTOH, they all
47 * derive the clocks from common clocks, so it
48 * might just be possible. The framework allows the
49 * codec to refine the transfer_info items in the
50 * usable callback, so we can simply remove the
51 * rates the second instance is not using when it
53 * Maybe we'll need to make the sound busses have
54 * a 'clock group id' value so the codec can
55 * determine if the two outputs can be driven at
56 * the same time. But that is likely overkill, up
57 * to the fabric to not link them up incorrectly,
58 * and up to the hardware designer to not wire
59 * them up in some weird unusable way.
61 #include <linux/i2c.h>
62 #include <asm/pmac_low_i2c.h>
64 #include <linux/delay.h>
65 #include <linux/module.h>
66 #include <linux/mutex.h>
67 #include <linux/slab.h>
69 MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
70 MODULE_LICENSE("GPL");
71 MODULE_DESCRIPTION("tas codec driver for snd-aoa");
74 #include "tas-gain-table.h"
75 #include "tas-basstreble.h"
77 #include "../soundbus/soundbus.h"
79 #define PFX "snd-aoa-codec-tas: "
83 struct aoa_codec codec;
84 struct i2c_client *i2c;
85 u32 mute_l:1, mute_r:1 ,
89 u8 cached_volume_l, cached_volume_r;
90 u8 mixer_l[3], mixer_r[3];
94 /* protects hardware access against concurrency from
95 * userspace when hitting controls and during
96 * codec init/suspend/resume */
100 static int tas_reset_init(struct tas *tas);
102 static struct tas *codec_to_tas(struct aoa_codec *codec)
104 return container_of(codec, struct tas, codec);
107 static inline int tas_write_reg(struct tas *tas, u8 reg, u8 len, u8 *data)
110 return i2c_smbus_write_byte_data(tas->i2c, reg, *data);
112 return i2c_smbus_write_i2c_block_data(tas->i2c, reg, len, data);
115 static void tas3004_set_drc(struct tas *tas)
117 unsigned char val[6];
119 if (tas->drc_enabled)
120 val[0] = 0x50; /* 3:1 above threshold */
122 val[0] = 0x51; /* disabled */
123 val[1] = 0x02; /* 1:1 below threshold */
124 if (tas->drc_range > 0xef)
126 else if (tas->drc_range < 0)
129 val[2] = tas->drc_range;
134 tas_write_reg(tas, TAS_REG_DRC, 6, val);
137 static void tas_set_treble(struct tas *tas)
141 tmp = tas3004_treble(tas->treble);
142 tas_write_reg(tas, TAS_REG_TREBLE, 1, &tmp);
145 static void tas_set_bass(struct tas *tas)
149 tmp = tas3004_bass(tas->bass);
150 tas_write_reg(tas, TAS_REG_BASS, 1, &tmp);
153 static void tas_set_volume(struct tas *tas)
159 left = tas->cached_volume_l;
160 right = tas->cached_volume_r;
162 if (left > 177) left = 177;
163 if (right > 177) right = 177;
165 if (tas->mute_l) left = 0;
166 if (tas->mute_r) right = 0;
168 /* analysing the volume and mixer tables shows
169 * that they are similar enough when we shift
170 * the mixer table down by 4 bits. The error
171 * is miniscule, in just one item the error
172 * is 1, at a value of 0x07f17b (mixer table
173 * value is 0x07f17a) */
174 tmp = tas_gaintable[left];
178 tmp = tas_gaintable[right];
182 tas_write_reg(tas, TAS_REG_VOL, 6, block);
185 static void tas_set_mixer(struct tas *tas)
192 val = tas->mixer_l[i];
193 if (val > 177) val = 177;
194 tmp = tas_gaintable[val];
195 block[3*i+0] = tmp>>16;
196 block[3*i+1] = tmp>>8;
199 tas_write_reg(tas, TAS_REG_LMIX, 9, block);
202 val = tas->mixer_r[i];
203 if (val > 177) val = 177;
204 tmp = tas_gaintable[val];
205 block[3*i+0] = tmp>>16;
206 block[3*i+1] = tmp>>8;
209 tas_write_reg(tas, TAS_REG_RMIX, 9, block);
214 static int tas_dev_register(struct snd_device *dev)
219 static const struct snd_device_ops ops = {
220 .dev_register = tas_dev_register,
223 static int tas_snd_vol_info(struct snd_kcontrol *kcontrol,
224 struct snd_ctl_elem_info *uinfo)
226 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
228 uinfo->value.integer.min = 0;
229 uinfo->value.integer.max = 177;
233 static int tas_snd_vol_get(struct snd_kcontrol *kcontrol,
234 struct snd_ctl_elem_value *ucontrol)
236 struct tas *tas = snd_kcontrol_chip(kcontrol);
238 mutex_lock(&tas->mtx);
239 ucontrol->value.integer.value[0] = tas->cached_volume_l;
240 ucontrol->value.integer.value[1] = tas->cached_volume_r;
241 mutex_unlock(&tas->mtx);
245 static int tas_snd_vol_put(struct snd_kcontrol *kcontrol,
246 struct snd_ctl_elem_value *ucontrol)
248 struct tas *tas = snd_kcontrol_chip(kcontrol);
250 if (ucontrol->value.integer.value[0] < 0 ||
251 ucontrol->value.integer.value[0] > 177)
253 if (ucontrol->value.integer.value[1] < 0 ||
254 ucontrol->value.integer.value[1] > 177)
257 mutex_lock(&tas->mtx);
258 if (tas->cached_volume_l == ucontrol->value.integer.value[0]
259 && tas->cached_volume_r == ucontrol->value.integer.value[1]) {
260 mutex_unlock(&tas->mtx);
264 tas->cached_volume_l = ucontrol->value.integer.value[0];
265 tas->cached_volume_r = ucontrol->value.integer.value[1];
268 mutex_unlock(&tas->mtx);
272 static const struct snd_kcontrol_new volume_control = {
273 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
274 .name = "Master Playback Volume",
275 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
276 .info = tas_snd_vol_info,
277 .get = tas_snd_vol_get,
278 .put = tas_snd_vol_put,
281 #define tas_snd_mute_info snd_ctl_boolean_stereo_info
283 static int tas_snd_mute_get(struct snd_kcontrol *kcontrol,
284 struct snd_ctl_elem_value *ucontrol)
286 struct tas *tas = snd_kcontrol_chip(kcontrol);
288 mutex_lock(&tas->mtx);
289 ucontrol->value.integer.value[0] = !tas->mute_l;
290 ucontrol->value.integer.value[1] = !tas->mute_r;
291 mutex_unlock(&tas->mtx);
295 static int tas_snd_mute_put(struct snd_kcontrol *kcontrol,
296 struct snd_ctl_elem_value *ucontrol)
298 struct tas *tas = snd_kcontrol_chip(kcontrol);
300 mutex_lock(&tas->mtx);
301 if (tas->mute_l == !ucontrol->value.integer.value[0]
302 && tas->mute_r == !ucontrol->value.integer.value[1]) {
303 mutex_unlock(&tas->mtx);
307 tas->mute_l = !ucontrol->value.integer.value[0];
308 tas->mute_r = !ucontrol->value.integer.value[1];
311 mutex_unlock(&tas->mtx);
315 static const struct snd_kcontrol_new mute_control = {
316 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
317 .name = "Master Playback Switch",
318 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
319 .info = tas_snd_mute_info,
320 .get = tas_snd_mute_get,
321 .put = tas_snd_mute_put,
324 static int tas_snd_mixer_info(struct snd_kcontrol *kcontrol,
325 struct snd_ctl_elem_info *uinfo)
327 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
329 uinfo->value.integer.min = 0;
330 uinfo->value.integer.max = 177;
334 static int tas_snd_mixer_get(struct snd_kcontrol *kcontrol,
335 struct snd_ctl_elem_value *ucontrol)
337 struct tas *tas = snd_kcontrol_chip(kcontrol);
338 int idx = kcontrol->private_value;
340 mutex_lock(&tas->mtx);
341 ucontrol->value.integer.value[0] = tas->mixer_l[idx];
342 ucontrol->value.integer.value[1] = tas->mixer_r[idx];
343 mutex_unlock(&tas->mtx);
348 static int tas_snd_mixer_put(struct snd_kcontrol *kcontrol,
349 struct snd_ctl_elem_value *ucontrol)
351 struct tas *tas = snd_kcontrol_chip(kcontrol);
352 int idx = kcontrol->private_value;
354 mutex_lock(&tas->mtx);
355 if (tas->mixer_l[idx] == ucontrol->value.integer.value[0]
356 && tas->mixer_r[idx] == ucontrol->value.integer.value[1]) {
357 mutex_unlock(&tas->mtx);
361 tas->mixer_l[idx] = ucontrol->value.integer.value[0];
362 tas->mixer_r[idx] = ucontrol->value.integer.value[1];
366 mutex_unlock(&tas->mtx);
370 #define MIXER_CONTROL(n,descr,idx) \
371 static const struct snd_kcontrol_new n##_control = { \
372 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
373 .name = descr " Playback Volume", \
374 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
375 .info = tas_snd_mixer_info, \
376 .get = tas_snd_mixer_get, \
377 .put = tas_snd_mixer_put, \
378 .private_value = idx, \
381 MIXER_CONTROL(pcm1, "PCM", 0);
382 MIXER_CONTROL(monitor, "Monitor", 2);
384 static int tas_snd_drc_range_info(struct snd_kcontrol *kcontrol,
385 struct snd_ctl_elem_info *uinfo)
387 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
389 uinfo->value.integer.min = 0;
390 uinfo->value.integer.max = TAS3004_DRC_MAX;
394 static int tas_snd_drc_range_get(struct snd_kcontrol *kcontrol,
395 struct snd_ctl_elem_value *ucontrol)
397 struct tas *tas = snd_kcontrol_chip(kcontrol);
399 mutex_lock(&tas->mtx);
400 ucontrol->value.integer.value[0] = tas->drc_range;
401 mutex_unlock(&tas->mtx);
405 static int tas_snd_drc_range_put(struct snd_kcontrol *kcontrol,
406 struct snd_ctl_elem_value *ucontrol)
408 struct tas *tas = snd_kcontrol_chip(kcontrol);
410 if (ucontrol->value.integer.value[0] < 0 ||
411 ucontrol->value.integer.value[0] > TAS3004_DRC_MAX)
414 mutex_lock(&tas->mtx);
415 if (tas->drc_range == ucontrol->value.integer.value[0]) {
416 mutex_unlock(&tas->mtx);
420 tas->drc_range = ucontrol->value.integer.value[0];
422 tas3004_set_drc(tas);
423 mutex_unlock(&tas->mtx);
427 static const struct snd_kcontrol_new drc_range_control = {
428 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
430 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
431 .info = tas_snd_drc_range_info,
432 .get = tas_snd_drc_range_get,
433 .put = tas_snd_drc_range_put,
436 #define tas_snd_drc_switch_info snd_ctl_boolean_mono_info
438 static int tas_snd_drc_switch_get(struct snd_kcontrol *kcontrol,
439 struct snd_ctl_elem_value *ucontrol)
441 struct tas *tas = snd_kcontrol_chip(kcontrol);
443 mutex_lock(&tas->mtx);
444 ucontrol->value.integer.value[0] = tas->drc_enabled;
445 mutex_unlock(&tas->mtx);
449 static int tas_snd_drc_switch_put(struct snd_kcontrol *kcontrol,
450 struct snd_ctl_elem_value *ucontrol)
452 struct tas *tas = snd_kcontrol_chip(kcontrol);
454 mutex_lock(&tas->mtx);
455 if (tas->drc_enabled == ucontrol->value.integer.value[0]) {
456 mutex_unlock(&tas->mtx);
460 tas->drc_enabled = !!ucontrol->value.integer.value[0];
462 tas3004_set_drc(tas);
463 mutex_unlock(&tas->mtx);
467 static const struct snd_kcontrol_new drc_switch_control = {
468 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
469 .name = "DRC Range Switch",
470 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
471 .info = tas_snd_drc_switch_info,
472 .get = tas_snd_drc_switch_get,
473 .put = tas_snd_drc_switch_put,
476 static int tas_snd_capture_source_info(struct snd_kcontrol *kcontrol,
477 struct snd_ctl_elem_info *uinfo)
479 static const char * const texts[] = { "Line-In", "Microphone" };
481 return snd_ctl_enum_info(uinfo, 1, 2, texts);
484 static int tas_snd_capture_source_get(struct snd_kcontrol *kcontrol,
485 struct snd_ctl_elem_value *ucontrol)
487 struct tas *tas = snd_kcontrol_chip(kcontrol);
489 mutex_lock(&tas->mtx);
490 ucontrol->value.enumerated.item[0] = !!(tas->acr & TAS_ACR_INPUT_B);
491 mutex_unlock(&tas->mtx);
495 static int tas_snd_capture_source_put(struct snd_kcontrol *kcontrol,
496 struct snd_ctl_elem_value *ucontrol)
498 struct tas *tas = snd_kcontrol_chip(kcontrol);
501 if (ucontrol->value.enumerated.item[0] > 1)
503 mutex_lock(&tas->mtx);
507 * Despite what the data sheet says in one place, the
508 * TAS_ACR_B_MONAUREAL bit forces mono output even when
509 * input A (line in) is selected.
511 tas->acr &= ~(TAS_ACR_INPUT_B | TAS_ACR_B_MONAUREAL);
512 if (ucontrol->value.enumerated.item[0])
513 tas->acr |= TAS_ACR_INPUT_B | TAS_ACR_B_MONAUREAL |
514 TAS_ACR_B_MON_SEL_RIGHT;
515 if (oldacr == tas->acr) {
516 mutex_unlock(&tas->mtx);
520 tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr);
521 mutex_unlock(&tas->mtx);
525 static const struct snd_kcontrol_new capture_source_control = {
526 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
527 /* If we name this 'Input Source', it properly shows up in
528 * alsamixer as a selection, * but it's shown under the
529 * 'Playback' category.
530 * If I name it 'Capture Source', it shows up in strange
531 * ways (two bools of which one can be selected at a
532 * time) but at least it's shown in the 'Capture'
534 * I was told that this was due to backward compatibility,
535 * but I don't understand then why the mangling is *not*
536 * done when I name it "Input Source".....
538 .name = "Capture Source",
539 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
540 .info = tas_snd_capture_source_info,
541 .get = tas_snd_capture_source_get,
542 .put = tas_snd_capture_source_put,
545 static int tas_snd_treble_info(struct snd_kcontrol *kcontrol,
546 struct snd_ctl_elem_info *uinfo)
548 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
550 uinfo->value.integer.min = TAS3004_TREBLE_MIN;
551 uinfo->value.integer.max = TAS3004_TREBLE_MAX;
555 static int tas_snd_treble_get(struct snd_kcontrol *kcontrol,
556 struct snd_ctl_elem_value *ucontrol)
558 struct tas *tas = snd_kcontrol_chip(kcontrol);
560 mutex_lock(&tas->mtx);
561 ucontrol->value.integer.value[0] = tas->treble;
562 mutex_unlock(&tas->mtx);
566 static int tas_snd_treble_put(struct snd_kcontrol *kcontrol,
567 struct snd_ctl_elem_value *ucontrol)
569 struct tas *tas = snd_kcontrol_chip(kcontrol);
571 if (ucontrol->value.integer.value[0] < TAS3004_TREBLE_MIN ||
572 ucontrol->value.integer.value[0] > TAS3004_TREBLE_MAX)
574 mutex_lock(&tas->mtx);
575 if (tas->treble == ucontrol->value.integer.value[0]) {
576 mutex_unlock(&tas->mtx);
580 tas->treble = ucontrol->value.integer.value[0];
583 mutex_unlock(&tas->mtx);
587 static const struct snd_kcontrol_new treble_control = {
588 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
590 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
591 .info = tas_snd_treble_info,
592 .get = tas_snd_treble_get,
593 .put = tas_snd_treble_put,
596 static int tas_snd_bass_info(struct snd_kcontrol *kcontrol,
597 struct snd_ctl_elem_info *uinfo)
599 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
601 uinfo->value.integer.min = TAS3004_BASS_MIN;
602 uinfo->value.integer.max = TAS3004_BASS_MAX;
606 static int tas_snd_bass_get(struct snd_kcontrol *kcontrol,
607 struct snd_ctl_elem_value *ucontrol)
609 struct tas *tas = snd_kcontrol_chip(kcontrol);
611 mutex_lock(&tas->mtx);
612 ucontrol->value.integer.value[0] = tas->bass;
613 mutex_unlock(&tas->mtx);
617 static int tas_snd_bass_put(struct snd_kcontrol *kcontrol,
618 struct snd_ctl_elem_value *ucontrol)
620 struct tas *tas = snd_kcontrol_chip(kcontrol);
622 if (ucontrol->value.integer.value[0] < TAS3004_BASS_MIN ||
623 ucontrol->value.integer.value[0] > TAS3004_BASS_MAX)
625 mutex_lock(&tas->mtx);
626 if (tas->bass == ucontrol->value.integer.value[0]) {
627 mutex_unlock(&tas->mtx);
631 tas->bass = ucontrol->value.integer.value[0];
634 mutex_unlock(&tas->mtx);
638 static const struct snd_kcontrol_new bass_control = {
639 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
641 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
642 .info = tas_snd_bass_info,
643 .get = tas_snd_bass_get,
644 .put = tas_snd_bass_put,
647 static struct transfer_info tas_transfers[] = {
650 .formats = SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_S24_BE,
651 .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
656 .formats = SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_S24_BE,
657 .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
663 static int tas_usable(struct codec_info_item *cii,
664 struct transfer_info *ti,
665 struct transfer_info *out)
670 static int tas_reset_init(struct tas *tas)
674 tas->codec.gpio->methods->all_amps_off(tas->codec.gpio);
676 tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 0);
678 tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 1);
680 tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 0);
682 tas->codec.gpio->methods->all_amps_restore(tas->codec.gpio);
684 tmp = TAS_MCS_SCLK64 | TAS_MCS_SPORT_MODE_I2S | TAS_MCS_SPORT_WL_24BIT;
685 if (tas_write_reg(tas, TAS_REG_MCS, 1, &tmp))
688 tas->acr |= TAS_ACR_ANALOG_PDOWN;
689 if (tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr))
693 if (tas_write_reg(tas, TAS_REG_MCS2, 1, &tmp))
696 tas3004_set_drc(tas);
698 /* Set treble & bass to 0dB */
699 tas->treble = TAS3004_TREBLE_ZERO;
700 tas->bass = TAS3004_BASS_ZERO;
704 tas->acr &= ~TAS_ACR_ANALOG_PDOWN;
705 if (tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr))
713 static int tas_switch_clock(struct codec_info_item *cii, enum clock_switch clock)
715 struct tas *tas = cii->codec_data;
718 case CLOCK_SWITCH_PREPARE_SLAVE:
719 /* Clocks are going away, mute mute mute */
720 tas->codec.gpio->methods->all_amps_off(tas->codec.gpio);
723 case CLOCK_SWITCH_SLAVE:
724 /* Clocks are back, re-init the codec */
725 mutex_lock(&tas->mtx);
730 tas->codec.gpio->methods->all_amps_restore(tas->codec.gpio);
731 mutex_unlock(&tas->mtx);
734 /* doesn't happen as of now */
741 /* we are controlled via i2c and assume that is always up
742 * If that wasn't the case, we'd have to suspend once
743 * our i2c device is suspended, and then take note of that! */
744 static int tas_suspend(struct tas *tas)
746 mutex_lock(&tas->mtx);
748 tas->acr |= TAS_ACR_ANALOG_PDOWN;
749 tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr);
750 mutex_unlock(&tas->mtx);
754 static int tas_resume(struct tas *tas)
757 mutex_lock(&tas->mtx);
762 mutex_unlock(&tas->mtx);
766 static int _tas_suspend(struct codec_info_item *cii, pm_message_t state)
768 return tas_suspend(cii->codec_data);
771 static int _tas_resume(struct codec_info_item *cii)
773 return tas_resume(cii->codec_data);
775 #else /* CONFIG_PM */
776 #define _tas_suspend NULL
777 #define _tas_resume NULL
778 #endif /* CONFIG_PM */
780 static struct codec_info tas_codec_info = {
781 .transfers = tas_transfers,
782 /* in theory, we can drive it at 512 too...
783 * but so far the framework doesn't allow
784 * for that and I don't see much point in it. */
785 .sysclock_factor = 256,
786 /* same here, could be 32 for just one 16 bit format */
788 .owner = THIS_MODULE,
789 .usable = tas_usable,
790 .switch_clock = tas_switch_clock,
791 .suspend = _tas_suspend,
792 .resume = _tas_resume,
795 static int tas_init_codec(struct aoa_codec *codec)
797 struct tas *tas = codec_to_tas(codec);
800 if (!tas->codec.gpio || !tas->codec.gpio->methods) {
801 printk(KERN_ERR PFX "gpios not assigned!!\n");
805 mutex_lock(&tas->mtx);
806 if (tas_reset_init(tas)) {
807 printk(KERN_ERR PFX "tas failed to initialise\n");
808 mutex_unlock(&tas->mtx);
812 mutex_unlock(&tas->mtx);
814 if (tas->codec.soundbus_dev->attach_codec(tas->codec.soundbus_dev,
816 &tas_codec_info, tas)) {
817 printk(KERN_ERR PFX "error attaching tas to soundbus\n");
821 if (aoa_snd_device_new(SNDRV_DEV_CODEC, tas, &ops)) {
822 printk(KERN_ERR PFX "failed to create tas snd device!\n");
825 err = aoa_snd_ctl_add(snd_ctl_new1(&volume_control, tas));
829 err = aoa_snd_ctl_add(snd_ctl_new1(&mute_control, tas));
833 err = aoa_snd_ctl_add(snd_ctl_new1(&pcm1_control, tas));
837 err = aoa_snd_ctl_add(snd_ctl_new1(&monitor_control, tas));
841 err = aoa_snd_ctl_add(snd_ctl_new1(&capture_source_control, tas));
845 err = aoa_snd_ctl_add(snd_ctl_new1(&drc_range_control, tas));
849 err = aoa_snd_ctl_add(snd_ctl_new1(&drc_switch_control, tas));
853 err = aoa_snd_ctl_add(snd_ctl_new1(&treble_control, tas));
857 err = aoa_snd_ctl_add(snd_ctl_new1(&bass_control, tas));
863 tas->codec.soundbus_dev->detach_codec(tas->codec.soundbus_dev, tas);
864 snd_device_free(aoa_get_card(), tas);
868 static void tas_exit_codec(struct aoa_codec *codec)
870 struct tas *tas = codec_to_tas(codec);
872 if (!tas->codec.soundbus_dev)
874 tas->codec.soundbus_dev->detach_codec(tas->codec.soundbus_dev, tas);
878 static int tas_i2c_probe(struct i2c_client *client,
879 const struct i2c_device_id *id)
881 struct device_node *node = client->dev.of_node;
884 tas = kzalloc(sizeof(struct tas), GFP_KERNEL);
889 mutex_init(&tas->mtx);
891 i2c_set_clientdata(client, tas);
893 /* seems that half is a saner default */
894 tas->drc_range = TAS3004_DRC_MAX / 2;
896 strscpy(tas->codec.name, "tas", MAX_CODEC_NAME_LEN);
897 tas->codec.owner = THIS_MODULE;
898 tas->codec.init = tas_init_codec;
899 tas->codec.exit = tas_exit_codec;
900 tas->codec.node = of_node_get(node);
902 if (aoa_codec_register(&tas->codec)) {
906 "snd-aoa-codec-tas: tas found, addr 0x%02x on %pOF\n",
907 (unsigned int)client->addr, node);
910 mutex_destroy(&tas->mtx);
915 static int tas_i2c_remove(struct i2c_client *client)
917 struct tas *tas = i2c_get_clientdata(client);
918 u8 tmp = TAS_ACR_ANALOG_PDOWN;
920 aoa_codec_unregister(&tas->codec);
921 of_node_put(tas->codec.node);
923 /* power down codec chip */
924 tas_write_reg(tas, TAS_REG_ACR, 1, &tmp);
926 mutex_destroy(&tas->mtx);
931 static const struct i2c_device_id tas_i2c_id[] = {
932 { "MAC,tas3004", 0 },
935 MODULE_DEVICE_TABLE(i2c,tas_i2c_id);
937 static struct i2c_driver tas_driver = {
939 .name = "aoa_codec_tas",
941 .probe = tas_i2c_probe,
942 .remove = tas_i2c_remove,
943 .id_table = tas_i2c_id,
946 module_i2c_driver(tas_driver);