2 * Apple Onboard Audio driver for tas codec
4 * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
6 * GPL v2, can be found in COPYING.
9 * - How to distinguish between 3004 and versions?
12 * - This codec driver doesn't honour the 'connected'
13 * property of the aoa_codec struct, hence if
14 * it is used in machines where not everything is
15 * connected it will display wrong mixer elements.
16 * - Driver assumes that the microphone is always
17 * monaureal and connected to the right channel of
18 * the input. This should also be a codec-dependent
19 * flag, maybe the codec should have 3 different
20 * bits for the three different possibilities how
21 * it can be hooked up...
22 * But as long as I don't see any hardware hooked
24 * - As Apple notes in their code, the tas3004 seems
25 * to delay the right channel by one sample. You can
26 * see this when for example recording stereo in
27 * audacity, or recording the tas output via cable
28 * on another machine (use a sinus generator or so).
29 * I tried programming the BiQuads but couldn't
30 * make the delay work, maybe someone can read the
31 * datasheet and fix it. The relevant Apple comment
32 * is in AppleTAS3004Audio.cpp lines 1637 ff. Note
33 * that their comment describing how they program
34 * the filters sucks...
37 * - this should actually register *two* aoa_codec
38 * structs since it has two inputs. Then it must
39 * use the prepare callback to forbid running the
40 * secondary output on a different clock.
41 * Also, whatever bus knows how to do this must
42 * provide two soundbus_dev devices and the fabric
43 * must be able to link them correctly.
45 * I don't even know if Apple ever uses the second
46 * port on the tas3004 though, I don't think their
47 * i2s controllers can even do it. OTOH, they all
48 * derive the clocks from common clocks, so it
49 * might just be possible. The framework allows the
50 * codec to refine the transfer_info items in the
51 * usable callback, so we can simply remove the
52 * rates the second instance is not using when it
54 * Maybe we'll need to make the sound busses have
55 * a 'clock group id' value so the codec can
56 * determine if the two outputs can be driven at
57 * the same time. But that is likely overkill, up
58 * to the fabric to not link them up incorrectly,
59 * and up to the hardware designer to not wire
60 * them up in some weird unusable way.
63 #include <linux/i2c.h>
64 #include <linux/i2c-dev.h>
65 #include <asm/pmac_low_i2c.h>
67 #include <linux/delay.h>
68 #include <linux/module.h>
69 MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
70 MODULE_LICENSE("GPL");
71 MODULE_DESCRIPTION("tas codec driver for snd-aoa");
73 #include "snd-aoa-codec-tas.h"
74 #include "snd-aoa-codec-tas-gain-table.h"
75 #include "snd-aoa-codec-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];
96 static int tas_reset_init(struct tas *tas);
98 static struct tas *codec_to_tas(struct aoa_codec *codec)
100 return container_of(codec, struct tas, codec);
103 static inline int tas_write_reg(struct tas *tas, u8 reg, u8 len, u8 *data)
106 return i2c_smbus_write_byte_data(&tas->i2c, reg, *data);
108 return i2c_smbus_write_i2c_block_data(&tas->i2c, reg, len, data);
111 static void tas3004_set_drc(struct tas *tas)
113 unsigned char val[6];
115 if (tas->drc_enabled)
116 val[0] = 0x50; /* 3:1 above threshold */
118 val[0] = 0x51; /* disabled */
119 val[1] = 0x02; /* 1:1 below threshold */
120 if (tas->drc_range > 0xef)
122 else if (tas->drc_range < 0)
125 val[2] = tas->drc_range;
130 tas_write_reg(tas, TAS_REG_DRC, 6, val);
133 static void tas_set_treble(struct tas *tas)
137 tmp = tas3004_treble(tas->treble);
138 tas_write_reg(tas, TAS_REG_TREBLE, 1, &tmp);
141 static void tas_set_bass(struct tas *tas)
145 tmp = tas3004_bass(tas->bass);
146 tas_write_reg(tas, TAS_REG_BASS, 1, &tmp);
149 static void tas_set_volume(struct tas *tas)
155 left = tas->cached_volume_l;
156 right = tas->cached_volume_r;
158 if (left > 177) left = 177;
159 if (right > 177) right = 177;
161 if (tas->mute_l) left = 0;
162 if (tas->mute_r) right = 0;
164 /* analysing the volume and mixer tables shows
165 * that they are similar enough when we shift
166 * the mixer table down by 4 bits. The error
167 * is miniscule, in just one item the error
168 * is 1, at a value of 0x07f17b (mixer table
169 * value is 0x07f17a) */
170 tmp = tas_gaintable[left];
174 tmp = tas_gaintable[right];
178 tas_write_reg(tas, TAS_REG_VOL, 6, block);
181 static void tas_set_mixer(struct tas *tas)
188 val = tas->mixer_l[i];
189 if (val > 177) val = 177;
190 tmp = tas_gaintable[val];
191 block[3*i+0] = tmp>>16;
192 block[3*i+1] = tmp>>8;
195 tas_write_reg(tas, TAS_REG_LMIX, 9, block);
198 val = tas->mixer_r[i];
199 if (val > 177) val = 177;
200 tmp = tas_gaintable[val];
201 block[3*i+0] = tmp>>16;
202 block[3*i+1] = tmp>>8;
205 tas_write_reg(tas, TAS_REG_RMIX, 9, block);
210 static int tas_dev_register(struct snd_device *dev)
215 static struct snd_device_ops ops = {
216 .dev_register = tas_dev_register,
219 static int tas_snd_vol_info(struct snd_kcontrol *kcontrol,
220 struct snd_ctl_elem_info *uinfo)
222 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
224 uinfo->value.integer.min = 0;
225 uinfo->value.integer.max = 177;
229 static int tas_snd_vol_get(struct snd_kcontrol *kcontrol,
230 struct snd_ctl_elem_value *ucontrol)
232 struct tas *tas = snd_kcontrol_chip(kcontrol);
234 ucontrol->value.integer.value[0] = tas->cached_volume_l;
235 ucontrol->value.integer.value[1] = tas->cached_volume_r;
239 static int tas_snd_vol_put(struct snd_kcontrol *kcontrol,
240 struct snd_ctl_elem_value *ucontrol)
242 struct tas *tas = snd_kcontrol_chip(kcontrol);
244 if (tas->cached_volume_l == ucontrol->value.integer.value[0]
245 && tas->cached_volume_r == ucontrol->value.integer.value[1])
248 tas->cached_volume_l = ucontrol->value.integer.value[0];
249 tas->cached_volume_r = ucontrol->value.integer.value[1];
255 static struct snd_kcontrol_new volume_control = {
256 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
257 .name = "Master Playback Volume",
258 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
259 .info = tas_snd_vol_info,
260 .get = tas_snd_vol_get,
261 .put = tas_snd_vol_put,
264 static int tas_snd_mute_info(struct snd_kcontrol *kcontrol,
265 struct snd_ctl_elem_info *uinfo)
267 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
269 uinfo->value.integer.min = 0;
270 uinfo->value.integer.max = 1;
274 static int tas_snd_mute_get(struct snd_kcontrol *kcontrol,
275 struct snd_ctl_elem_value *ucontrol)
277 struct tas *tas = snd_kcontrol_chip(kcontrol);
279 ucontrol->value.integer.value[0] = !tas->mute_l;
280 ucontrol->value.integer.value[1] = !tas->mute_r;
284 static int tas_snd_mute_put(struct snd_kcontrol *kcontrol,
285 struct snd_ctl_elem_value *ucontrol)
287 struct tas *tas = snd_kcontrol_chip(kcontrol);
289 if (tas->mute_l == !ucontrol->value.integer.value[0]
290 && tas->mute_r == !ucontrol->value.integer.value[1])
293 tas->mute_l = !ucontrol->value.integer.value[0];
294 tas->mute_r = !ucontrol->value.integer.value[1];
300 static struct snd_kcontrol_new mute_control = {
301 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
302 .name = "Master Playback Switch",
303 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
304 .info = tas_snd_mute_info,
305 .get = tas_snd_mute_get,
306 .put = tas_snd_mute_put,
309 static int tas_snd_mixer_info(struct snd_kcontrol *kcontrol,
310 struct snd_ctl_elem_info *uinfo)
312 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
314 uinfo->value.integer.min = 0;
315 uinfo->value.integer.max = 177;
319 static int tas_snd_mixer_get(struct snd_kcontrol *kcontrol,
320 struct snd_ctl_elem_value *ucontrol)
322 struct tas *tas = snd_kcontrol_chip(kcontrol);
323 int idx = kcontrol->private_value;
325 ucontrol->value.integer.value[0] = tas->mixer_l[idx];
326 ucontrol->value.integer.value[1] = tas->mixer_r[idx];
331 static int tas_snd_mixer_put(struct snd_kcontrol *kcontrol,
332 struct snd_ctl_elem_value *ucontrol)
334 struct tas *tas = snd_kcontrol_chip(kcontrol);
335 int idx = kcontrol->private_value;
337 if (tas->mixer_l[idx] == ucontrol->value.integer.value[0]
338 && tas->mixer_r[idx] == ucontrol->value.integer.value[1])
341 tas->mixer_l[idx] = ucontrol->value.integer.value[0];
342 tas->mixer_r[idx] = ucontrol->value.integer.value[1];
349 #define MIXER_CONTROL(n,descr,idx) \
350 static struct snd_kcontrol_new n##_control = { \
351 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
352 .name = descr " Playback Volume", \
353 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
354 .info = tas_snd_mixer_info, \
355 .get = tas_snd_mixer_get, \
356 .put = tas_snd_mixer_put, \
357 .private_value = idx, \
360 MIXER_CONTROL(pcm1, "PCM", 0);
361 MIXER_CONTROL(monitor, "Monitor", 2);
363 static int tas_snd_drc_range_info(struct snd_kcontrol *kcontrol,
364 struct snd_ctl_elem_info *uinfo)
366 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
368 uinfo->value.integer.min = 0;
369 uinfo->value.integer.max = TAS3004_DRC_MAX;
373 static int tas_snd_drc_range_get(struct snd_kcontrol *kcontrol,
374 struct snd_ctl_elem_value *ucontrol)
376 struct tas *tas = snd_kcontrol_chip(kcontrol);
378 ucontrol->value.integer.value[0] = tas->drc_range;
382 static int tas_snd_drc_range_put(struct snd_kcontrol *kcontrol,
383 struct snd_ctl_elem_value *ucontrol)
385 struct tas *tas = snd_kcontrol_chip(kcontrol);
387 if (tas->drc_range == ucontrol->value.integer.value[0])
390 tas->drc_range = ucontrol->value.integer.value[0];
392 tas3004_set_drc(tas);
396 static struct snd_kcontrol_new drc_range_control = {
397 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
399 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
400 .info = tas_snd_drc_range_info,
401 .get = tas_snd_drc_range_get,
402 .put = tas_snd_drc_range_put,
405 static int tas_snd_drc_switch_info(struct snd_kcontrol *kcontrol,
406 struct snd_ctl_elem_info *uinfo)
408 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
410 uinfo->value.integer.min = 0;
411 uinfo->value.integer.max = 1;
415 static int tas_snd_drc_switch_get(struct snd_kcontrol *kcontrol,
416 struct snd_ctl_elem_value *ucontrol)
418 struct tas *tas = snd_kcontrol_chip(kcontrol);
420 ucontrol->value.integer.value[0] = tas->drc_enabled;
424 static int tas_snd_drc_switch_put(struct snd_kcontrol *kcontrol,
425 struct snd_ctl_elem_value *ucontrol)
427 struct tas *tas = snd_kcontrol_chip(kcontrol);
429 if (tas->drc_enabled == ucontrol->value.integer.value[0])
432 tas->drc_enabled = ucontrol->value.integer.value[0];
434 tas3004_set_drc(tas);
438 static struct snd_kcontrol_new drc_switch_control = {
439 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
440 .name = "DRC Range Switch",
441 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
442 .info = tas_snd_drc_switch_info,
443 .get = tas_snd_drc_switch_get,
444 .put = tas_snd_drc_switch_put,
447 static int tas_snd_capture_source_info(struct snd_kcontrol *kcontrol,
448 struct snd_ctl_elem_info *uinfo)
450 static char *texts[] = { "Line-In", "Microphone" };
452 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
454 uinfo->value.enumerated.items = 2;
455 if (uinfo->value.enumerated.item > 1)
456 uinfo->value.enumerated.item = 1;
457 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
461 static int tas_snd_capture_source_get(struct snd_kcontrol *kcontrol,
462 struct snd_ctl_elem_value *ucontrol)
464 struct tas *tas = snd_kcontrol_chip(kcontrol);
466 ucontrol->value.enumerated.item[0] = !!(tas->acr & TAS_ACR_INPUT_B);
470 static int tas_snd_capture_source_put(struct snd_kcontrol *kcontrol,
471 struct snd_ctl_elem_value *ucontrol)
473 struct tas *tas = snd_kcontrol_chip(kcontrol);
474 int oldacr = tas->acr;
476 tas->acr &= ~TAS_ACR_INPUT_B;
477 if (ucontrol->value.enumerated.item[0])
478 tas->acr |= TAS_ACR_INPUT_B;
479 if (oldacr == tas->acr)
482 tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr);
486 static struct snd_kcontrol_new capture_source_control = {
487 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
488 /* If we name this 'Input Source', it properly shows up in
489 * alsamixer as a selection, * but it's shown under the
490 * 'Playback' category.
491 * If I name it 'Capture Source', it shows up in strange
492 * ways (two bools of which one can be selected at a
493 * time) but at least it's shown in the 'Capture'
495 * I was told that this was due to backward compatibility,
496 * but I don't understand then why the mangling is *not*
497 * done when I name it "Input Source".....
499 .name = "Capture Source",
500 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
501 .info = tas_snd_capture_source_info,
502 .get = tas_snd_capture_source_get,
503 .put = tas_snd_capture_source_put,
506 static int tas_snd_treble_info(struct snd_kcontrol *kcontrol,
507 struct snd_ctl_elem_info *uinfo)
509 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
511 uinfo->value.integer.min = TAS3004_TREBLE_MIN;
512 uinfo->value.integer.max = TAS3004_TREBLE_MAX;
516 static int tas_snd_treble_get(struct snd_kcontrol *kcontrol,
517 struct snd_ctl_elem_value *ucontrol)
519 struct tas *tas = snd_kcontrol_chip(kcontrol);
521 ucontrol->value.integer.value[0] = tas->treble;
525 static int tas_snd_treble_put(struct snd_kcontrol *kcontrol,
526 struct snd_ctl_elem_value *ucontrol)
528 struct tas *tas = snd_kcontrol_chip(kcontrol);
530 if (tas->treble == ucontrol->value.integer.value[0])
533 tas->treble = ucontrol->value.integer.value[0];
539 static struct snd_kcontrol_new treble_control = {
540 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
542 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
543 .info = tas_snd_treble_info,
544 .get = tas_snd_treble_get,
545 .put = tas_snd_treble_put,
548 static int tas_snd_bass_info(struct snd_kcontrol *kcontrol,
549 struct snd_ctl_elem_info *uinfo)
551 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
553 uinfo->value.integer.min = TAS3004_BASS_MIN;
554 uinfo->value.integer.max = TAS3004_BASS_MAX;
558 static int tas_snd_bass_get(struct snd_kcontrol *kcontrol,
559 struct snd_ctl_elem_value *ucontrol)
561 struct tas *tas = snd_kcontrol_chip(kcontrol);
563 ucontrol->value.integer.value[0] = tas->bass;
567 static int tas_snd_bass_put(struct snd_kcontrol *kcontrol,
568 struct snd_ctl_elem_value *ucontrol)
570 struct tas *tas = snd_kcontrol_chip(kcontrol);
572 if (tas->bass == ucontrol->value.integer.value[0])
575 tas->bass = ucontrol->value.integer.value[0];
581 static struct snd_kcontrol_new bass_control = {
582 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
584 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
585 .info = tas_snd_bass_info,
586 .get = tas_snd_bass_get,
587 .put = tas_snd_bass_put,
590 static struct transfer_info tas_transfers[] = {
593 .formats = SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_S16_BE |
594 SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S24_BE,
595 .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
600 .formats = SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_S16_BE |
601 SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S24_BE,
602 .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
608 static int tas_usable(struct codec_info_item *cii,
609 struct transfer_info *ti,
610 struct transfer_info *out)
615 static int tas_reset_init(struct tas *tas)
619 tas->codec.gpio->methods->all_amps_off(tas->codec.gpio);
621 tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 0);
623 tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 1);
625 tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 0);
627 tas->codec.gpio->methods->all_amps_restore(tas->codec.gpio);
629 tmp = TAS_MCS_SCLK64 | TAS_MCS_SPORT_MODE_I2S | TAS_MCS_SPORT_WL_24BIT;
630 if (tas_write_reg(tas, TAS_REG_MCS, 1, &tmp))
633 tas->acr |= TAS_ACR_ANALOG_PDOWN | TAS_ACR_B_MONAUREAL |
634 TAS_ACR_B_MON_SEL_RIGHT;
635 if (tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr))
639 if (tas_write_reg(tas, TAS_REG_MCS2, 1, &tmp))
642 tas3004_set_drc(tas);
644 /* Set treble & bass to 0dB */
645 tas->treble = TAS3004_TREBLE_ZERO;
646 tas->bass = TAS3004_BASS_ZERO;
650 tas->acr &= ~TAS_ACR_ANALOG_PDOWN;
651 if (tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr))
657 static int tas_switch_clock(struct codec_info_item *cii, enum clock_switch clock)
659 struct tas *tas = cii->codec_data;
662 case CLOCK_SWITCH_PREPARE_SLAVE:
663 /* Clocks are going away, mute mute mute */
664 tas->codec.gpio->methods->all_amps_off(tas->codec.gpio);
667 case CLOCK_SWITCH_SLAVE:
668 /* Clocks are back, re-init the codec */
673 tas->codec.gpio->methods->all_amps_restore(tas->codec.gpio);
676 /* doesn't happen as of now */
682 /* we are controlled via i2c and assume that is always up
683 * If that wasn't the case, we'd have to suspend once
684 * our i2c device is suspended, and then take note of that! */
685 static int tas_suspend(struct tas *tas)
688 tas->acr |= TAS_ACR_ANALOG_PDOWN;
689 tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr);
693 static int tas_resume(struct tas *tas)
704 static int _tas_suspend(struct codec_info_item *cii, pm_message_t state)
706 return tas_suspend(cii->codec_data);
709 static int _tas_resume(struct codec_info_item *cii)
711 return tas_resume(cii->codec_data);
715 static struct codec_info tas_codec_info = {
716 .transfers = tas_transfers,
717 /* in theory, we can drive it at 512 too...
718 * but so far the framework doesn't allow
719 * for that and I don't see much point in it. */
720 .sysclock_factor = 256,
721 /* same here, could be 32 for just one 16 bit format */
723 .owner = THIS_MODULE,
724 .usable = tas_usable,
725 .switch_clock = tas_switch_clock,
727 .suspend = _tas_suspend,
728 .resume = _tas_resume,
732 static int tas_init_codec(struct aoa_codec *codec)
734 struct tas *tas = codec_to_tas(codec);
737 if (!tas->codec.gpio || !tas->codec.gpio->methods) {
738 printk(KERN_ERR PFX "gpios not assigned!!\n");
742 if (tas_reset_init(tas)) {
743 printk(KERN_ERR PFX "tas failed to initialise\n");
748 if (tas->codec.soundbus_dev->attach_codec(tas->codec.soundbus_dev,
750 &tas_codec_info, tas)) {
751 printk(KERN_ERR PFX "error attaching tas to soundbus\n");
755 if (aoa_snd_device_new(SNDRV_DEV_LOWLEVEL, tas, &ops)) {
756 printk(KERN_ERR PFX "failed to create tas snd device!\n");
759 err = aoa_snd_ctl_add(snd_ctl_new1(&volume_control, tas));
763 err = aoa_snd_ctl_add(snd_ctl_new1(&mute_control, tas));
767 err = aoa_snd_ctl_add(snd_ctl_new1(&pcm1_control, tas));
771 err = aoa_snd_ctl_add(snd_ctl_new1(&monitor_control, tas));
775 err = aoa_snd_ctl_add(snd_ctl_new1(&capture_source_control, tas));
779 err = aoa_snd_ctl_add(snd_ctl_new1(&drc_range_control, tas));
783 err = aoa_snd_ctl_add(snd_ctl_new1(&drc_switch_control, tas));
787 err = aoa_snd_ctl_add(snd_ctl_new1(&treble_control, tas));
791 err = aoa_snd_ctl_add(snd_ctl_new1(&bass_control, tas));
797 tas->codec.soundbus_dev->detach_codec(tas->codec.soundbus_dev, tas);
798 snd_device_free(aoa_get_card(), tas);
802 static void tas_exit_codec(struct aoa_codec *codec)
804 struct tas *tas = codec_to_tas(codec);
806 if (!tas->codec.soundbus_dev)
808 tas->codec.soundbus_dev->detach_codec(tas->codec.soundbus_dev, tas);
812 static struct i2c_driver tas_driver;
814 static int tas_create(struct i2c_adapter *adapter,
815 struct device_node *node,
820 tas = kzalloc(sizeof(struct tas), GFP_KERNEL);
825 tas->i2c.driver = &tas_driver;
826 tas->i2c.adapter = adapter;
827 tas->i2c.addr = addr;
828 /* seems that half is a saner default */
829 tas->drc_range = TAS3004_DRC_MAX / 2;
830 strlcpy(tas->i2c.name, "tas audio codec", I2C_NAME_SIZE-1);
832 if (i2c_attach_client(&tas->i2c)) {
833 printk(KERN_ERR PFX "failed to attach to i2c\n");
837 strlcpy(tas->codec.name, "tas", MAX_CODEC_NAME_LEN-1);
838 tas->codec.owner = THIS_MODULE;
839 tas->codec.init = tas_init_codec;
840 tas->codec.exit = tas_exit_codec;
841 tas->codec.node = of_node_get(node);
843 if (aoa_codec_register(&tas->codec)) {
847 "snd-aoa-codec-tas: tas found, addr 0x%02x on %s\n",
848 addr, node->full_name);
851 i2c_detach_client(&tas->i2c);
857 static int tas_i2c_attach(struct i2c_adapter *adapter)
859 struct device_node *busnode, *dev = NULL;
860 struct pmac_i2c_bus *bus;
862 bus = pmac_i2c_adapter_to_bus(adapter);
865 busnode = pmac_i2c_get_bus_node(bus);
867 while ((dev = of_get_next_child(busnode, dev)) != NULL) {
868 if (device_is_compatible(dev, "tas3004")) {
870 printk(KERN_DEBUG PFX "found tas3004\n");
871 addr = (u32 *) get_property(dev, "reg", NULL);
874 return tas_create(adapter, dev, ((*addr) >> 1) & 0x7f);
876 /* older machines have no 'codec' node with a 'compatible'
877 * property that says 'tas3004', they just have a 'deq'
878 * node without any such property... */
879 if (strcmp(dev->name, "deq") == 0) {
881 printk(KERN_DEBUG PFX "found 'deq' node\n");
882 _addr = (u32 *) get_property(dev, "i2c-address", NULL);
885 addr = ((*_addr) >> 1) & 0x7f;
886 /* now, if the address doesn't match any of the two
887 * that a tas3004 can have, we cannot handle this.
888 * I doubt it ever happens but hey. */
889 if (addr != 0x34 && addr != 0x35)
891 return tas_create(adapter, dev, addr);
897 static int tas_i2c_detach(struct i2c_client *client)
899 struct tas *tas = container_of(client, struct tas, i2c);
901 u8 tmp = TAS_ACR_ANALOG_PDOWN;
903 if ((err = i2c_detach_client(client)))
905 aoa_codec_unregister(&tas->codec);
906 of_node_put(tas->codec.node);
908 /* power down codec chip */
909 tas_write_reg(tas, TAS_REG_ACR, 1, &tmp);
915 static struct i2c_driver tas_driver = {
917 .name = "aoa_codec_tas",
918 .owner = THIS_MODULE,
920 .attach_adapter = tas_i2c_attach,
921 .detach_client = tas_i2c_detach,
924 static int __init tas_init(void)
926 return i2c_add_driver(&tas_driver);
929 static void __exit tas_exit(void)
931 i2c_del_driver(&tas_driver);
934 module_init(tas_init);
935 module_exit(tas_exit);