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.
62 #include <linux/i2c.h>
63 #include <asm/pmac_low_i2c.h>
65 #include <linux/delay.h>
66 #include <linux/module.h>
67 #include <linux/mutex.h>
68 #include <linux/slab.h>
70 MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
71 MODULE_LICENSE("GPL");
72 MODULE_DESCRIPTION("tas codec driver for snd-aoa");
75 #include "tas-gain-table.h"
76 #include "tas-basstreble.h"
78 #include "../soundbus/soundbus.h"
80 #define PFX "snd-aoa-codec-tas: "
84 struct aoa_codec codec
;
85 struct i2c_client
*i2c
;
86 u32 mute_l
:1, mute_r
:1 ,
90 u8 cached_volume_l
, cached_volume_r
;
91 u8 mixer_l
[3], mixer_r
[3];
95 /* protects hardware access against concurrency from
96 * userspace when hitting controls and during
97 * codec init/suspend/resume */
101 static int tas_reset_init(struct tas
*tas
);
103 static struct tas
*codec_to_tas(struct aoa_codec
*codec
)
105 return container_of(codec
, struct tas
, codec
);
108 static inline int tas_write_reg(struct tas
*tas
, u8 reg
, u8 len
, u8
*data
)
111 return i2c_smbus_write_byte_data(tas
->i2c
, reg
, *data
);
113 return i2c_smbus_write_i2c_block_data(tas
->i2c
, reg
, len
, data
);
116 static void tas3004_set_drc(struct tas
*tas
)
118 unsigned char val
[6];
120 if (tas
->drc_enabled
)
121 val
[0] = 0x50; /* 3:1 above threshold */
123 val
[0] = 0x51; /* disabled */
124 val
[1] = 0x02; /* 1:1 below threshold */
125 if (tas
->drc_range
> 0xef)
127 else if (tas
->drc_range
< 0)
130 val
[2] = tas
->drc_range
;
135 tas_write_reg(tas
, TAS_REG_DRC
, 6, val
);
138 static void tas_set_treble(struct tas
*tas
)
142 tmp
= tas3004_treble(tas
->treble
);
143 tas_write_reg(tas
, TAS_REG_TREBLE
, 1, &tmp
);
146 static void tas_set_bass(struct tas
*tas
)
150 tmp
= tas3004_bass(tas
->bass
);
151 tas_write_reg(tas
, TAS_REG_BASS
, 1, &tmp
);
154 static void tas_set_volume(struct tas
*tas
)
160 left
= tas
->cached_volume_l
;
161 right
= tas
->cached_volume_r
;
163 if (left
> 177) left
= 177;
164 if (right
> 177) right
= 177;
166 if (tas
->mute_l
) left
= 0;
167 if (tas
->mute_r
) right
= 0;
169 /* analysing the volume and mixer tables shows
170 * that they are similar enough when we shift
171 * the mixer table down by 4 bits. The error
172 * is miniscule, in just one item the error
173 * is 1, at a value of 0x07f17b (mixer table
174 * value is 0x07f17a) */
175 tmp
= tas_gaintable
[left
];
179 tmp
= tas_gaintable
[right
];
183 tas_write_reg(tas
, TAS_REG_VOL
, 6, block
);
186 static void tas_set_mixer(struct tas
*tas
)
193 val
= tas
->mixer_l
[i
];
194 if (val
> 177) val
= 177;
195 tmp
= tas_gaintable
[val
];
196 block
[3*i
+0] = tmp
>>16;
197 block
[3*i
+1] = tmp
>>8;
200 tas_write_reg(tas
, TAS_REG_LMIX
, 9, block
);
203 val
= tas
->mixer_r
[i
];
204 if (val
> 177) val
= 177;
205 tmp
= tas_gaintable
[val
];
206 block
[3*i
+0] = tmp
>>16;
207 block
[3*i
+1] = tmp
>>8;
210 tas_write_reg(tas
, TAS_REG_RMIX
, 9, block
);
215 static int tas_dev_register(struct snd_device
*dev
)
220 static const struct snd_device_ops ops
= {
221 .dev_register
= tas_dev_register
,
224 static int tas_snd_vol_info(struct snd_kcontrol
*kcontrol
,
225 struct snd_ctl_elem_info
*uinfo
)
227 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
229 uinfo
->value
.integer
.min
= 0;
230 uinfo
->value
.integer
.max
= 177;
234 static int tas_snd_vol_get(struct snd_kcontrol
*kcontrol
,
235 struct snd_ctl_elem_value
*ucontrol
)
237 struct tas
*tas
= snd_kcontrol_chip(kcontrol
);
239 mutex_lock(&tas
->mtx
);
240 ucontrol
->value
.integer
.value
[0] = tas
->cached_volume_l
;
241 ucontrol
->value
.integer
.value
[1] = tas
->cached_volume_r
;
242 mutex_unlock(&tas
->mtx
);
246 static int tas_snd_vol_put(struct snd_kcontrol
*kcontrol
,
247 struct snd_ctl_elem_value
*ucontrol
)
249 struct tas
*tas
= snd_kcontrol_chip(kcontrol
);
251 if (ucontrol
->value
.integer
.value
[0] < 0 ||
252 ucontrol
->value
.integer
.value
[0] > 177)
254 if (ucontrol
->value
.integer
.value
[1] < 0 ||
255 ucontrol
->value
.integer
.value
[1] > 177)
258 mutex_lock(&tas
->mtx
);
259 if (tas
->cached_volume_l
== ucontrol
->value
.integer
.value
[0]
260 && tas
->cached_volume_r
== ucontrol
->value
.integer
.value
[1]) {
261 mutex_unlock(&tas
->mtx
);
265 tas
->cached_volume_l
= ucontrol
->value
.integer
.value
[0];
266 tas
->cached_volume_r
= ucontrol
->value
.integer
.value
[1];
269 mutex_unlock(&tas
->mtx
);
273 static const struct snd_kcontrol_new volume_control
= {
274 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
275 .name
= "Master Playback Volume",
276 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
277 .info
= tas_snd_vol_info
,
278 .get
= tas_snd_vol_get
,
279 .put
= tas_snd_vol_put
,
282 #define tas_snd_mute_info snd_ctl_boolean_stereo_info
284 static int tas_snd_mute_get(struct snd_kcontrol
*kcontrol
,
285 struct snd_ctl_elem_value
*ucontrol
)
287 struct tas
*tas
= snd_kcontrol_chip(kcontrol
);
289 mutex_lock(&tas
->mtx
);
290 ucontrol
->value
.integer
.value
[0] = !tas
->mute_l
;
291 ucontrol
->value
.integer
.value
[1] = !tas
->mute_r
;
292 mutex_unlock(&tas
->mtx
);
296 static int tas_snd_mute_put(struct snd_kcontrol
*kcontrol
,
297 struct snd_ctl_elem_value
*ucontrol
)
299 struct tas
*tas
= snd_kcontrol_chip(kcontrol
);
301 mutex_lock(&tas
->mtx
);
302 if (tas
->mute_l
== !ucontrol
->value
.integer
.value
[0]
303 && tas
->mute_r
== !ucontrol
->value
.integer
.value
[1]) {
304 mutex_unlock(&tas
->mtx
);
308 tas
->mute_l
= !ucontrol
->value
.integer
.value
[0];
309 tas
->mute_r
= !ucontrol
->value
.integer
.value
[1];
312 mutex_unlock(&tas
->mtx
);
316 static const struct snd_kcontrol_new mute_control
= {
317 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
318 .name
= "Master Playback Switch",
319 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
320 .info
= tas_snd_mute_info
,
321 .get
= tas_snd_mute_get
,
322 .put
= tas_snd_mute_put
,
325 static int tas_snd_mixer_info(struct snd_kcontrol
*kcontrol
,
326 struct snd_ctl_elem_info
*uinfo
)
328 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
330 uinfo
->value
.integer
.min
= 0;
331 uinfo
->value
.integer
.max
= 177;
335 static int tas_snd_mixer_get(struct snd_kcontrol
*kcontrol
,
336 struct snd_ctl_elem_value
*ucontrol
)
338 struct tas
*tas
= snd_kcontrol_chip(kcontrol
);
339 int idx
= kcontrol
->private_value
;
341 mutex_lock(&tas
->mtx
);
342 ucontrol
->value
.integer
.value
[0] = tas
->mixer_l
[idx
];
343 ucontrol
->value
.integer
.value
[1] = tas
->mixer_r
[idx
];
344 mutex_unlock(&tas
->mtx
);
349 static int tas_snd_mixer_put(struct snd_kcontrol
*kcontrol
,
350 struct snd_ctl_elem_value
*ucontrol
)
352 struct tas
*tas
= snd_kcontrol_chip(kcontrol
);
353 int idx
= kcontrol
->private_value
;
355 mutex_lock(&tas
->mtx
);
356 if (tas
->mixer_l
[idx
] == ucontrol
->value
.integer
.value
[0]
357 && tas
->mixer_r
[idx
] == ucontrol
->value
.integer
.value
[1]) {
358 mutex_unlock(&tas
->mtx
);
362 tas
->mixer_l
[idx
] = ucontrol
->value
.integer
.value
[0];
363 tas
->mixer_r
[idx
] = ucontrol
->value
.integer
.value
[1];
367 mutex_unlock(&tas
->mtx
);
371 #define MIXER_CONTROL(n,descr,idx) \
372 static const struct snd_kcontrol_new n##_control = { \
373 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
374 .name = descr " Playback Volume", \
375 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
376 .info = tas_snd_mixer_info, \
377 .get = tas_snd_mixer_get, \
378 .put = tas_snd_mixer_put, \
379 .private_value = idx, \
382 MIXER_CONTROL(pcm1
, "PCM", 0);
383 MIXER_CONTROL(monitor
, "Monitor", 2);
385 static int tas_snd_drc_range_info(struct snd_kcontrol
*kcontrol
,
386 struct snd_ctl_elem_info
*uinfo
)
388 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
390 uinfo
->value
.integer
.min
= 0;
391 uinfo
->value
.integer
.max
= TAS3004_DRC_MAX
;
395 static int tas_snd_drc_range_get(struct snd_kcontrol
*kcontrol
,
396 struct snd_ctl_elem_value
*ucontrol
)
398 struct tas
*tas
= snd_kcontrol_chip(kcontrol
);
400 mutex_lock(&tas
->mtx
);
401 ucontrol
->value
.integer
.value
[0] = tas
->drc_range
;
402 mutex_unlock(&tas
->mtx
);
406 static int tas_snd_drc_range_put(struct snd_kcontrol
*kcontrol
,
407 struct snd_ctl_elem_value
*ucontrol
)
409 struct tas
*tas
= snd_kcontrol_chip(kcontrol
);
411 if (ucontrol
->value
.integer
.value
[0] < 0 ||
412 ucontrol
->value
.integer
.value
[0] > TAS3004_DRC_MAX
)
415 mutex_lock(&tas
->mtx
);
416 if (tas
->drc_range
== ucontrol
->value
.integer
.value
[0]) {
417 mutex_unlock(&tas
->mtx
);
421 tas
->drc_range
= ucontrol
->value
.integer
.value
[0];
423 tas3004_set_drc(tas
);
424 mutex_unlock(&tas
->mtx
);
428 static const struct snd_kcontrol_new drc_range_control
= {
429 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
431 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
432 .info
= tas_snd_drc_range_info
,
433 .get
= tas_snd_drc_range_get
,
434 .put
= tas_snd_drc_range_put
,
437 #define tas_snd_drc_switch_info snd_ctl_boolean_mono_info
439 static int tas_snd_drc_switch_get(struct snd_kcontrol
*kcontrol
,
440 struct snd_ctl_elem_value
*ucontrol
)
442 struct tas
*tas
= snd_kcontrol_chip(kcontrol
);
444 mutex_lock(&tas
->mtx
);
445 ucontrol
->value
.integer
.value
[0] = tas
->drc_enabled
;
446 mutex_unlock(&tas
->mtx
);
450 static int tas_snd_drc_switch_put(struct snd_kcontrol
*kcontrol
,
451 struct snd_ctl_elem_value
*ucontrol
)
453 struct tas
*tas
= snd_kcontrol_chip(kcontrol
);
455 mutex_lock(&tas
->mtx
);
456 if (tas
->drc_enabled
== ucontrol
->value
.integer
.value
[0]) {
457 mutex_unlock(&tas
->mtx
);
461 tas
->drc_enabled
= !!ucontrol
->value
.integer
.value
[0];
463 tas3004_set_drc(tas
);
464 mutex_unlock(&tas
->mtx
);
468 static const struct snd_kcontrol_new drc_switch_control
= {
469 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
470 .name
= "DRC Range Switch",
471 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
472 .info
= tas_snd_drc_switch_info
,
473 .get
= tas_snd_drc_switch_get
,
474 .put
= tas_snd_drc_switch_put
,
477 static int tas_snd_capture_source_info(struct snd_kcontrol
*kcontrol
,
478 struct snd_ctl_elem_info
*uinfo
)
480 static const char * const texts
[] = { "Line-In", "Microphone" };
482 return snd_ctl_enum_info(uinfo
, 1, 2, texts
);
485 static int tas_snd_capture_source_get(struct snd_kcontrol
*kcontrol
,
486 struct snd_ctl_elem_value
*ucontrol
)
488 struct tas
*tas
= snd_kcontrol_chip(kcontrol
);
490 mutex_lock(&tas
->mtx
);
491 ucontrol
->value
.enumerated
.item
[0] = !!(tas
->acr
& TAS_ACR_INPUT_B
);
492 mutex_unlock(&tas
->mtx
);
496 static int tas_snd_capture_source_put(struct snd_kcontrol
*kcontrol
,
497 struct snd_ctl_elem_value
*ucontrol
)
499 struct tas
*tas
= snd_kcontrol_chip(kcontrol
);
502 if (ucontrol
->value
.enumerated
.item
[0] > 1)
504 mutex_lock(&tas
->mtx
);
508 * Despite what the data sheet says in one place, the
509 * TAS_ACR_B_MONAUREAL bit forces mono output even when
510 * input A (line in) is selected.
512 tas
->acr
&= ~(TAS_ACR_INPUT_B
| TAS_ACR_B_MONAUREAL
);
513 if (ucontrol
->value
.enumerated
.item
[0])
514 tas
->acr
|= TAS_ACR_INPUT_B
| TAS_ACR_B_MONAUREAL
|
515 TAS_ACR_B_MON_SEL_RIGHT
;
516 if (oldacr
== tas
->acr
) {
517 mutex_unlock(&tas
->mtx
);
521 tas_write_reg(tas
, TAS_REG_ACR
, 1, &tas
->acr
);
522 mutex_unlock(&tas
->mtx
);
526 static const struct snd_kcontrol_new capture_source_control
= {
527 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
528 /* If we name this 'Input Source', it properly shows up in
529 * alsamixer as a selection, * but it's shown under the
530 * 'Playback' category.
531 * If I name it 'Capture Source', it shows up in strange
532 * ways (two bools of which one can be selected at a
533 * time) but at least it's shown in the 'Capture'
535 * I was told that this was due to backward compatibility,
536 * but I don't understand then why the mangling is *not*
537 * done when I name it "Input Source".....
539 .name
= "Capture Source",
540 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
541 .info
= tas_snd_capture_source_info
,
542 .get
= tas_snd_capture_source_get
,
543 .put
= tas_snd_capture_source_put
,
546 static int tas_snd_treble_info(struct snd_kcontrol
*kcontrol
,
547 struct snd_ctl_elem_info
*uinfo
)
549 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
551 uinfo
->value
.integer
.min
= TAS3004_TREBLE_MIN
;
552 uinfo
->value
.integer
.max
= TAS3004_TREBLE_MAX
;
556 static int tas_snd_treble_get(struct snd_kcontrol
*kcontrol
,
557 struct snd_ctl_elem_value
*ucontrol
)
559 struct tas
*tas
= snd_kcontrol_chip(kcontrol
);
561 mutex_lock(&tas
->mtx
);
562 ucontrol
->value
.integer
.value
[0] = tas
->treble
;
563 mutex_unlock(&tas
->mtx
);
567 static int tas_snd_treble_put(struct snd_kcontrol
*kcontrol
,
568 struct snd_ctl_elem_value
*ucontrol
)
570 struct tas
*tas
= snd_kcontrol_chip(kcontrol
);
572 if (ucontrol
->value
.integer
.value
[0] < TAS3004_TREBLE_MIN
||
573 ucontrol
->value
.integer
.value
[0] > TAS3004_TREBLE_MAX
)
575 mutex_lock(&tas
->mtx
);
576 if (tas
->treble
== ucontrol
->value
.integer
.value
[0]) {
577 mutex_unlock(&tas
->mtx
);
581 tas
->treble
= ucontrol
->value
.integer
.value
[0];
584 mutex_unlock(&tas
->mtx
);
588 static const struct snd_kcontrol_new treble_control
= {
589 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
591 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
592 .info
= tas_snd_treble_info
,
593 .get
= tas_snd_treble_get
,
594 .put
= tas_snd_treble_put
,
597 static int tas_snd_bass_info(struct snd_kcontrol
*kcontrol
,
598 struct snd_ctl_elem_info
*uinfo
)
600 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
602 uinfo
->value
.integer
.min
= TAS3004_BASS_MIN
;
603 uinfo
->value
.integer
.max
= TAS3004_BASS_MAX
;
607 static int tas_snd_bass_get(struct snd_kcontrol
*kcontrol
,
608 struct snd_ctl_elem_value
*ucontrol
)
610 struct tas
*tas
= snd_kcontrol_chip(kcontrol
);
612 mutex_lock(&tas
->mtx
);
613 ucontrol
->value
.integer
.value
[0] = tas
->bass
;
614 mutex_unlock(&tas
->mtx
);
618 static int tas_snd_bass_put(struct snd_kcontrol
*kcontrol
,
619 struct snd_ctl_elem_value
*ucontrol
)
621 struct tas
*tas
= snd_kcontrol_chip(kcontrol
);
623 if (ucontrol
->value
.integer
.value
[0] < TAS3004_BASS_MIN
||
624 ucontrol
->value
.integer
.value
[0] > TAS3004_BASS_MAX
)
626 mutex_lock(&tas
->mtx
);
627 if (tas
->bass
== ucontrol
->value
.integer
.value
[0]) {
628 mutex_unlock(&tas
->mtx
);
632 tas
->bass
= ucontrol
->value
.integer
.value
[0];
635 mutex_unlock(&tas
->mtx
);
639 static const struct snd_kcontrol_new bass_control
= {
640 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
642 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
643 .info
= tas_snd_bass_info
,
644 .get
= tas_snd_bass_get
,
645 .put
= tas_snd_bass_put
,
648 static struct transfer_info tas_transfers
[] = {
651 .formats
= SNDRV_PCM_FMTBIT_S16_BE
| SNDRV_PCM_FMTBIT_S24_BE
,
652 .rates
= SNDRV_PCM_RATE_32000
| SNDRV_PCM_RATE_44100
| SNDRV_PCM_RATE_48000
,
657 .formats
= SNDRV_PCM_FMTBIT_S16_BE
| SNDRV_PCM_FMTBIT_S24_BE
,
658 .rates
= SNDRV_PCM_RATE_32000
| SNDRV_PCM_RATE_44100
| SNDRV_PCM_RATE_48000
,
664 static int tas_usable(struct codec_info_item
*cii
,
665 struct transfer_info
*ti
,
666 struct transfer_info
*out
)
671 static int tas_reset_init(struct tas
*tas
)
675 tas
->codec
.gpio
->methods
->all_amps_off(tas
->codec
.gpio
);
677 tas
->codec
.gpio
->methods
->set_hw_reset(tas
->codec
.gpio
, 0);
679 tas
->codec
.gpio
->methods
->set_hw_reset(tas
->codec
.gpio
, 1);
681 tas
->codec
.gpio
->methods
->set_hw_reset(tas
->codec
.gpio
, 0);
683 tas
->codec
.gpio
->methods
->all_amps_restore(tas
->codec
.gpio
);
685 tmp
= TAS_MCS_SCLK64
| TAS_MCS_SPORT_MODE_I2S
| TAS_MCS_SPORT_WL_24BIT
;
686 if (tas_write_reg(tas
, TAS_REG_MCS
, 1, &tmp
))
689 tas
->acr
|= TAS_ACR_ANALOG_PDOWN
;
690 if (tas_write_reg(tas
, TAS_REG_ACR
, 1, &tas
->acr
))
694 if (tas_write_reg(tas
, TAS_REG_MCS2
, 1, &tmp
))
697 tas3004_set_drc(tas
);
699 /* Set treble & bass to 0dB */
700 tas
->treble
= TAS3004_TREBLE_ZERO
;
701 tas
->bass
= TAS3004_BASS_ZERO
;
705 tas
->acr
&= ~TAS_ACR_ANALOG_PDOWN
;
706 if (tas_write_reg(tas
, TAS_REG_ACR
, 1, &tas
->acr
))
714 static int tas_switch_clock(struct codec_info_item
*cii
, enum clock_switch clock
)
716 struct tas
*tas
= cii
->codec_data
;
719 case CLOCK_SWITCH_PREPARE_SLAVE
:
720 /* Clocks are going away, mute mute mute */
721 tas
->codec
.gpio
->methods
->all_amps_off(tas
->codec
.gpio
);
724 case CLOCK_SWITCH_SLAVE
:
725 /* Clocks are back, re-init the codec */
726 mutex_lock(&tas
->mtx
);
731 tas
->codec
.gpio
->methods
->all_amps_restore(tas
->codec
.gpio
);
732 mutex_unlock(&tas
->mtx
);
735 /* doesn't happen as of now */
742 /* we are controlled via i2c and assume that is always up
743 * If that wasn't the case, we'd have to suspend once
744 * our i2c device is suspended, and then take note of that! */
745 static int tas_suspend(struct tas
*tas
)
747 mutex_lock(&tas
->mtx
);
749 tas
->acr
|= TAS_ACR_ANALOG_PDOWN
;
750 tas_write_reg(tas
, TAS_REG_ACR
, 1, &tas
->acr
);
751 mutex_unlock(&tas
->mtx
);
755 static int tas_resume(struct tas
*tas
)
758 mutex_lock(&tas
->mtx
);
763 mutex_unlock(&tas
->mtx
);
767 static int _tas_suspend(struct codec_info_item
*cii
, pm_message_t state
)
769 return tas_suspend(cii
->codec_data
);
772 static int _tas_resume(struct codec_info_item
*cii
)
774 return tas_resume(cii
->codec_data
);
776 #else /* CONFIG_PM */
777 #define _tas_suspend NULL
778 #define _tas_resume NULL
779 #endif /* CONFIG_PM */
781 static struct codec_info tas_codec_info
= {
782 .transfers
= tas_transfers
,
783 /* in theory, we can drive it at 512 too...
784 * but so far the framework doesn't allow
785 * for that and I don't see much point in it. */
786 .sysclock_factor
= 256,
787 /* same here, could be 32 for just one 16 bit format */
789 .owner
= THIS_MODULE
,
790 .usable
= tas_usable
,
791 .switch_clock
= tas_switch_clock
,
792 .suspend
= _tas_suspend
,
793 .resume
= _tas_resume
,
796 static int tas_init_codec(struct aoa_codec
*codec
)
798 struct tas
*tas
= codec_to_tas(codec
);
801 if (!tas
->codec
.gpio
|| !tas
->codec
.gpio
->methods
) {
802 printk(KERN_ERR PFX
"gpios not assigned!!\n");
806 mutex_lock(&tas
->mtx
);
807 if (tas_reset_init(tas
)) {
808 printk(KERN_ERR PFX
"tas failed to initialise\n");
809 mutex_unlock(&tas
->mtx
);
813 mutex_unlock(&tas
->mtx
);
815 if (tas
->codec
.soundbus_dev
->attach_codec(tas
->codec
.soundbus_dev
,
817 &tas_codec_info
, tas
)) {
818 printk(KERN_ERR PFX
"error attaching tas to soundbus\n");
822 if (aoa_snd_device_new(SNDRV_DEV_CODEC
, tas
, &ops
)) {
823 printk(KERN_ERR PFX
"failed to create tas snd device!\n");
826 err
= aoa_snd_ctl_add(snd_ctl_new1(&volume_control
, tas
));
830 err
= aoa_snd_ctl_add(snd_ctl_new1(&mute_control
, tas
));
834 err
= aoa_snd_ctl_add(snd_ctl_new1(&pcm1_control
, tas
));
838 err
= aoa_snd_ctl_add(snd_ctl_new1(&monitor_control
, tas
));
842 err
= aoa_snd_ctl_add(snd_ctl_new1(&capture_source_control
, tas
));
846 err
= aoa_snd_ctl_add(snd_ctl_new1(&drc_range_control
, tas
));
850 err
= aoa_snd_ctl_add(snd_ctl_new1(&drc_switch_control
, tas
));
854 err
= aoa_snd_ctl_add(snd_ctl_new1(&treble_control
, tas
));
858 err
= aoa_snd_ctl_add(snd_ctl_new1(&bass_control
, tas
));
864 tas
->codec
.soundbus_dev
->detach_codec(tas
->codec
.soundbus_dev
, tas
);
865 snd_device_free(aoa_get_card(), tas
);
869 static void tas_exit_codec(struct aoa_codec
*codec
)
871 struct tas
*tas
= codec_to_tas(codec
);
873 if (!tas
->codec
.soundbus_dev
)
875 tas
->codec
.soundbus_dev
->detach_codec(tas
->codec
.soundbus_dev
, tas
);
879 static int tas_i2c_probe(struct i2c_client
*client
,
880 const struct i2c_device_id
*id
)
882 struct device_node
*node
= client
->dev
.of_node
;
885 tas
= kzalloc(sizeof(struct tas
), GFP_KERNEL
);
890 mutex_init(&tas
->mtx
);
892 i2c_set_clientdata(client
, tas
);
894 /* seems that half is a saner default */
895 tas
->drc_range
= TAS3004_DRC_MAX
/ 2;
897 strlcpy(tas
->codec
.name
, "tas", MAX_CODEC_NAME_LEN
);
898 tas
->codec
.owner
= THIS_MODULE
;
899 tas
->codec
.init
= tas_init_codec
;
900 tas
->codec
.exit
= tas_exit_codec
;
901 tas
->codec
.node
= of_node_get(node
);
903 if (aoa_codec_register(&tas
->codec
)) {
907 "snd-aoa-codec-tas: tas found, addr 0x%02x on %pOF\n",
908 (unsigned int)client
->addr
, node
);
911 mutex_destroy(&tas
->mtx
);
916 static int tas_i2c_remove(struct i2c_client
*client
)
918 struct tas
*tas
= i2c_get_clientdata(client
);
919 u8 tmp
= TAS_ACR_ANALOG_PDOWN
;
921 aoa_codec_unregister(&tas
->codec
);
922 of_node_put(tas
->codec
.node
);
924 /* power down codec chip */
925 tas_write_reg(tas
, TAS_REG_ACR
, 1, &tmp
);
927 mutex_destroy(&tas
->mtx
);
932 static const struct i2c_device_id tas_i2c_id
[] = {
933 { "MAC,tas3004", 0 },
936 MODULE_DEVICE_TABLE(i2c
,tas_i2c_id
);
938 static struct i2c_driver tas_driver
= {
940 .name
= "aoa_codec_tas",
942 .probe
= tas_i2c_probe
,
943 .remove
= tas_i2c_remove
,
944 .id_table
= tas_i2c_id
,
947 module_i2c_driver(tas_driver
);