[alsa-devel] ASoC: Hooking a TI CODEC to a i.MX27 MCU

Stuart Longland redhatter at gentoo.org
Tue Jun 1 13:32:38 CEST 2010

For the benefit of those working with the TLV320AIC3204 CODEC, I release
this *very experimental* and incomplete driver to hopefully encourage
further work.  I haven't made it available as a patch; rather just
attached the driver and its header file, since the driver is far from
complete.  These files go in sound/soc/codecs, with appropriate entries
into Kconfig and Makefile.

Presently, I'm working on defining all the registers, and considering
methods for allowing their configuration via the APIs available.

The TLV320AIC3204 CODEC exposes its registers in individual "pages"; the
first register (reg 0) is the page select register, the remaining
registers change in meaning depending on what page is selected.  In the
CODEC driver, I therefore use a 16-bit addressing scheme, whereby the
upper 8-bits indicates the page number, and the lower 8-bits is the
actual register address used.  Page select is *always* at register
0x0000 in cache.  When a register on a different page is accessed, the
page is switched first before accessing the register.  I'm not certain
if this is the best approach; but it was the only way that made sense.

The CODEC driver claims total control of the I2C device, and therefore
makes it impossible to alter registers using i2c-tools.  However, as a
work-around; I have provided read/write access to the registers via
sysfs... we use the AIC3204 attached to I2C bus 0; the CODEC therefore
lives under:


There are two files:
	- regsel:	Takes or reports back the 16-bit register
			address in hexadecimal
	- regdata:	Reads or writes the value of the register

`i2cget -y 0 0x18` and `i2cset -y 0 0x18` can be replaced by the
following shell functions:

acget () {
	printf "0x%02x%02x\n" $1 > /sys/bus/i2c/devices/0-0018/regsel
	cat /sys/bus/i2c/devices/0-0018/regdata

acset () {
	printf "0x%02x%02x\n" $1 > /sys/bus/i2c/devices/0-0018/regsel
	printf "0x%02x\n" $2 > /sys/bus/i2c/devices/0-0018/regdata

At most, to get sound out, you may need to use the above two functions
to set your routing and levels.  Register dumps can also be done using
shell scripting, although it's slower than the i2cdump tool.

Other things that need work;
- PLL support doesn't seem to work ... this will need adjustment
- Sample rates are "off"... 48kHz audio gets played at ~52kHz for
  example (see above comment about PLL)
- Routing is hard-coded at present
- In my testing, sound output is low in amplitude

I hope to address some of these over this week, but in the meantime I'll
provide my work in its current form in the hope that we can build upon
this and improve it for inclusion in the Linux kernel.
Stuart Longland (aka Redhatter, VK4MSL)      .'''.
Gentoo Linux/MIPS Cobalt and Docs Developer  '.'` :
. . . . . . . . . . . . . . . . . . . . . .   .'.'
http://dev.gentoo.org/~redhatter             :.'

I haven't lost my mind...
  ...it's backed up on a tape somewhere.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tlv320aic3204.h
Type: text/x-c
Size: 33866 bytes
Desc: not available
Url : http://mailman.alsa-project.org/pipermail/alsa-devel/attachments/20100601/843f63b1/attachment-0002.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tlv320aic3204.c
Type: text/x-c
Size: 54228 bytes
Desc: not available
Url : http://mailman.alsa-project.org/pipermail/alsa-devel/attachments/20100601/843f63b1/attachment-0003.bin 

More information about the Alsa-devel mailing list