User avatar
PeterO
Posts: 4216
Joined: Sun Jul 22, 2012 4:14 pm

I2S Success (at last) !

Sun Nov 09, 2014 6:37 pm

I've written up my success with getting a PCM1803A ADC to work on a B+.

http://www.peteronion.org.uk/I2S/

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

carla_sch
Posts: 17
Joined: Wed Mar 18, 2015 5:23 pm

Re: I2S Success (at last) !

Wed Mar 18, 2015 5:33 pm

I was now able to compile and load the Module my_loader.ko under linux 3.18.9-2
but it says bcm2708-i2s.0 not registered
Driver asoc-simple-card requests probe deferral .
What can I do ?

IBM Portable PC
Posts: 46
Joined: Sun Apr 26, 2015 10:18 am
Location: Melbourne, Australia

Re: I2S Success (at last) !

Fri May 01, 2015 5:58 am

carla_sch wrote:I was now able to compile and load the Module my_loader.ko under linux 3.18.9-2
but it says bcm2708-i2s.0 not registered
Driver asoc-simple-card requests probe deferral .
What can I do ?
After a lot of effort, I'm at the same point:

[ 128.353009] asoc-simple-card asoc-simple-card.0: ASoC: CPU DAI bcm2708-i2s.0 not registered
[ 128.353142] platform asoc-simple-card.0: Driver asoc-simple-card requests probe deferral

carla_sch
Posts: 17
Joined: Wed Mar 18, 2015 5:23 pm

Re: I2S Success (at last) !

Thu May 14, 2015 6:12 pm

Here is a modified my_loader.c file that creates a sound device .
(arecord -l ) but I was
not able to record - maybe a hardware problem with the codec board.
Only some names were changed I found them in /sys/kernel/debug/asoc/


#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/kmod.h>
#include <linux/platform_device.h>
#include <sound/simple_card.h>

void device_release_callback(struct device *dev) { /* do nothing */ };

static struct asoc_simple_card_info snd_rpi_simple_card_info = {
.card = "snd_rpi_simple_card", // -> snd_soc_card.name
.name = "simple-card_codec_link", // -> snd_soc_dai_link.name
.codec = "snd-soc-dummy", // "dmic-codec", // -> snd_soc_dai_link.codec_name
// .platform = "bcm2708-i2s.0", // -> snd_soc_dai_link.platform_name
.platform = "20203000.i2s",
.daifmt = 0,
.cpu_dai = {
// .name = "bcm2708-i2s.0", // -> snd_soc_dai_link.cpu_dai_name
.name = "20203000.i2s", // -> snd_soc_dai_link.cpu_dai_name
.fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
|SND_SOC_DAIFMT_CBM_CFM,
.sysclk = 0 },
.codec_dai = {
.name = "snd-soc-dummy-dai", //"dmic-codec", // -> snd_soc_dai_link.codec_dai_name
.fmt = 0,
.sysclk = 0 },
};
static struct platform_device snd_rpi_simple_card_device = {
.name = "asoc-simple-card", //module alias
.id = 0,
.num_resources = 0,
.dev = { .release = &device_release_callback,
.platform_data = &snd_rpi_simple_card_info, // *HACK ALERT*
},
};
static struct platform_device snd_rpi_codec_device = {
.name = "snd-soc-dammy", // "dmic-codec", //module alias
.id = -1,
.num_resources = 0,
.dev = { .release = &device_release_callback,
},
};

int hello_init(void)
{
const char *dmaengine = "bcm2708-dmaengine"; //module name
int ret;

ret = request_module(dmaengine);
pr_alert("request module load '%s': %d\n",dmaengine, ret);

// ret = platform_device_register(&snd_rpi_codec_device);
// pr_alert("register platform device '%s': %d\n",snd_rpi_codec_device.name, ret);

ret = platform_device_register(&snd_rpi_simple_card_device);
pr_alert("register platform device '%s': %d\n",snd_rpi_simple_card_device.name, ret);

pr_alert("Hello World :)\n");
return 0;
}
void hello_exit(void)
{// you'll have to sudo modprobe -r the card & codec drivers manually (first?)
platform_device_unregister(&snd_rpi_simple_card_device);
platform_device_unregister(&snd_rpi_codec_device);
pr_alert("Goodbye World!\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_DESCRIPTION("ASoC simple-card I2S setup");
MODULE_AUTHOR("Plugh Plover");
MODULE_LICENSE("GPL v2");

carla_sch
Posts: 17
Joined: Wed Mar 18, 2015 5:23 pm

Re: I2S Success (at last) !

Fri May 15, 2015 3:04 pm

Recording works now - the powerdown pin of the pcm1803a
has to be high, although there is still noise and distortion,
maybe it needs a power supply separate from the raspberry.


The line
platform_device_unregister(&snd_rpi_codec_device);

has to be removed because it crashes when unloading the module.
It is not possible to unregister something that was not registered.
Note that I am using Arch-Linux and linux-headers for compiling
the kernel-module.

LisaJK
Posts: 14
Joined: Sat Jul 11, 2015 6:21 am

Re: I2S Success (at last) !

Sat Jul 11, 2015 6:52 am

I'm also at the point getting:

[ 95.409720] asoc-simple-card asoc-simple-card.0: ASoC: CPU DAI bcm2708-i2s.0 not registered
[ 95.409845] platform asoc-simple-card.0: Driver asoc-simple-card requests probe deferral

I tried carla's code printed above, but although I don't get the not registered messages, it doesn't seem to work.

What it the step between my error and it working? Many people seem to have got it working, but I haven't found how they did yet, unless I am missing something!

carla_sch
Posts: 17
Joined: Wed Mar 18, 2015 5:23 pm

Re: I2S Success (at last) !

Tue Jul 14, 2015 5:52 pm

bcm2708-i2s.0 does not work , registering the codec_device also does not work.
But using the obviously already registered
20203000.i2s and snd-soc-dummy-dai did work.
My code also expects that the PCM1803A is in master mode, I used it with 96000Hz
sample rate in i2s mode. Check if the PCM1803A is outputting some signal.
I read the Sparkfun PCM1803A Board is no longer available, so what
should we use instead ?

mchamster
Posts: 1
Joined: Sun Jul 26, 2015 4:54 pm

Re: I2S Success (at last) !

Sun Jul 26, 2015 5:07 pm

carla_sch wrote:bcm2708-i2s.0 does not work , registering the codec_device also does not work.
But using the obviously already registered
20203000.i2s and snd-soc-dummy-dai did work.
My code also expects that the PCM1803A is in master mode, I used it with 96000Hz
sample rate in i2s mode. Check if the PCM1803A is outputting some signal.
I read the Sparkfun PCM1803A Board is no longer available, so what
should we use instead ?
I've spun up the sparkfun pcm1803a on oshpark with a few improvements:

- Removed the 3.3v regulator.
- Replaced all caps with 0603 ceramic. May be some additional noise, but it's what i have in my parts bin.
- Star topography for system ground, analog ground and digital ground. Much better noise suppression. The sparkfun layout induced digital ground currents within the analog domain. There's a ground pin at the bottom of the pcb. Use that to connect to the PI header.
- Exposed pad AGND so analog powerline noise measurements can be performed.
- Slightly smaller footprint to make it fit better on protoboard/breadboard.

To order: https://oshpark.com/shared_projects/HOqnPukE (3pcs, ~$5 shipped)

The crystal is the same used by sparkfun, but sourced on digikey: 631-1186-1-ND ... mpn : FXO-HC736R-24.576

I'll be following in everyone's footsteps here shortly to implement this on the rpi (currently finishing another project). If anyone would like assembled boards for the purpose of getting this to work with the pi, I may be able to assist. Eagle SCH/BRD files available per request. Just PM me.

LisaJK
Posts: 14
Joined: Sat Jul 11, 2015 6:21 am

Re: I2S Success (at last) !

Sat Aug 08, 2015 10:51 am

Hi Carly_sch,

thanks for your reply. I have tried your code and the driver registers, and I can see a recording device.

However, when I try to record, I see no BCLK or LRCLK. After a few seconds I get an error:

arecord: pcm_read:1801: read error: Input/output error

When I do a dmesg after a few attempts, I see:

[ 517.169878] request module load 'bcm2708-dmaengine': 0
[ 517.182694] register platform device 'asoc-simple-card': 0
[ 517.189882] Hello World :)
[ 517.232018] asoc-simple-card asoc-simple-card.0: snd-soc-dummy-dai <-> 20203000.i2s mapping ok
[ 661.117490] bcm2708-i2s 20203000.i2s: I2S SYNC error!
[ 671.123889] bcm2708-dmaengine bcm2708-dmaengine: DMA transfer could not be terminated
[ 767.279680] bcm2708-i2s 20203000.i2s: I2S SYNC error!
[ 777.284463] bcm2708-dmaengine bcm2708-dmaengine: DMA transfer could not be terminated
[10040.560910] bcm2708-i2s 20203000.i2s: I2S SYNC error!
[10050.565581] bcm2708-dmaengine bcm2708-dmaengine: DMA transfer could not be terminated
[10374.363007] bcm2708-i2s 20203000.i2s: I2S SYNC error!
[10384.368636] bcm2708-dmaengine bcm2708-dmaengine: DMA transfer could not be terminated
[10464.713298] bcm2708-i2s 20203000.i2s: I2S SYNC error!
[10474.719540] bcm2708-dmaengine bcm2708-dmaengine: DMA transfer could not be terminated
[10694.703794] bcm2708-i2s 20203000.i2s: I2S SYNC error!
[10704.711660] bcm2708-dmaengine bcm2708-dmaengine: DMA transfer could not be terminated

LisaJK
Posts: 14
Joined: Sat Jul 11, 2015 6:21 am

Re: I2S Success (at last) !

Sat Aug 08, 2015 10:54 am

BTW, I have a Knowles I2S microphone. This can't be the problem as I get this whether it is connected or not.

As the driver is for master mode, I should see clocks whatever.

LisaJK
Posts: 14
Joined: Sat Jul 11, 2015 6:21 am

Re: I2S Success (at last) !

Sun Aug 09, 2015 5:38 am

Just to be clear, I am looking for BCLK and LRCLK with a scope on pins 12 and 35 respectively and see nothing. I have the latest RPi 2.

I am not expecting that anything needs to be plugged into the Pi to see these clocks.

The Knowles I2S microphone obviously requires these clocks to do anything, so until I see them I don't see any reason to try connecting it.

Any help would be gratefully received!

carla_sch
Posts: 17
Joined: Wed Mar 18, 2015 5:23 pm

Re: I2S Success (at last) !

Mon Aug 10, 2015 12:38 pm

The driver is for master mode of the pcm1803a board, so the
this board has to supply the clocks not the raspberry pi.
"Master" refers to the i2s board not the raspberry pi.

To use the pcm1803a board as slave is not a good idea because
the clocks supplied by the computer have to be synchronized to
the system clock of the i2s board and that is not possible here,
so there will be loss of data repeatedly.
But you can change the mode of the driver to slave if your i2s device
only supports slave mode and wants clock signals from the raspberry pi.
Change SND_SOC_DAIFMT_CBM_CFM to SND_SOC_DAIFMT_CBS_CFS

LisaJK
Posts: 14
Joined: Sat Jul 11, 2015 6:21 am

Re: I2S Success (at last) !

Mon Aug 10, 2015 10:25 pm

Hi Carla,

fantastic, it worked, many thanks.

I had begun to think I'd be looking at real debugging, but it was such a simple thing.

BTW, I am not using that CODEC, I'm using a Knowles I2S mic and it works great now. It's tiny and has extremely good signal to noise and PSRR.

Many thanks again!

BTW, one of the applications I have requires using the Pi as a slave. If the master device is not running when arecord is run, I assume I'll get the I2S error as before. Any idea whether the error will cause subsequent attempts to record to fail?

LisaJK
Posts: 14
Joined: Sat Jul 11, 2015 6:21 am

Re: I2S Success (at last) !

Thu Aug 13, 2015 7:20 pm

Well, the driver is working great on Raspbian, but I'm having great fun on Arch Linux.

First we had a version problem when trying just insmod, updated everything to the latest kernels and headers and now I find that simple_card has changed in the latest 4.1.4 and 4.1.5 kernels.

fmt has been removed.

http://lists.infradead.org/pipermail/li ... 17560.html

Again, I could delve into the actual code, but having spent time just getting the driver going, I'm reluctant.

Anyone got any good suggestions?

carla_sch
Posts: 17
Joined: Wed Mar 18, 2015 5:23 pm

Re: I2S Success (at last) !

Sat Aug 15, 2015 6:19 pm

It compiles and recording works - but I did not yet check the result
Don't forget to change master to slave for your knowles mic :

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/kmod.h>
#include <linux/platform_device.h>
#include <sound/simple_card.h>
#include <linux/delay.h>
/*
modified for linux 4.1.5
inspired by https://github.com/msperl/spi-config
with thanks for https://github.com/notro/rpi-source/wiki
as well as Florian Meier for the rpi i2s and dma drivers

to use a differant (simple-card compatible) codec
change the codec name string in two places and the
codec_dai name string. (see codec's source file)

fmt flags are set for vanilla i2s with rpi as clock slave

N.B. playback vs capture is determined by the codec choice
*/

void device_release_callback(struct device *dev) { /* do nothing */ };

static struct asoc_simple_card_info snd_rpi_simple_card_info = {
.card = "snd_rpi_simple_card", // -> snd_soc_card.name
.name = "simple-card_codec_link", // -> snd_soc_dai_link.name
.codec = "snd-soc-dummy", // "dmic-codec", // -> snd_soc_dai_link.codec_name
.platform = "20203000.i2s",
.daifmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM,
.cpu_dai = {
.name = "20203000.i2s", // -> snd_soc_dai_link.cpu_dai_name
.sysclk = 0 },
.codec_dai = {
.name = "snd-soc-dummy-dai", //"dmic-codec", // -> snd_soc_dai_link.codec_dai_name
.sysclk = 0 },
};
static struct platform_device snd_rpi_simple_card_device = {
.name = "asoc-simple-card", //module alias
.id = 0,
.num_resources = 0,
.dev = { .release = &device_release_callback,
.platform_data = &snd_rpi_simple_card_info, // *HACK ALERT*
},
};


int hello_init(void)
{
const char *dmaengine = "bcm2708-dmaengine"; //module name
int ret;

ret = request_module(dmaengine);
pr_alert("request module load '%s': %d\n",dmaengine, ret);
ret = platform_device_register(&snd_rpi_simple_card_device);
pr_alert("register platform device '%s': %d\n",snd_rpi_simple_card_device.name, ret);

pr_alert("Hello World :)\n");
return 0;
}
void hello_exit(void)
{// you'll have to sudo modprobe -r the card & codec drivers manually (first?)
platform_device_unregister(&snd_rpi_simple_card_device);
pr_alert("Goodbye World!\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_DESCRIPTION("ASoC simple-card I2S setup");
MODULE_AUTHOR("Plugh Plover");
MODULE_LICENSE("GPL v2");

LisaJK
Posts: 14
Joined: Sat Jul 11, 2015 6:21 am

Re: I2S Success (at last) !

Sat Aug 22, 2015 12:00 am

Fantastic, I'll try it today!!!

LisaJK
Posts: 14
Joined: Sat Jul 11, 2015 6:21 am

Re: I2S Success (at last) !

Sun Aug 23, 2015 4:17 am

Doh!

Now I get:

[ 72.372642] request module load 'bcm2708-dmaengine': 0
[ 72.373036] register platform device 'asoc-simple-card': 0
[ 72.373162] Hello World :)
[ 72.381936] asoc-simple-card asoc-simple-card.0: ASoC: CPU DAI 20203000.i2s not registered
[ 72.382227] platform asoc-simple-card.0: Driver asoc-simple-card requests probe deferral
[ 117.175197] w1_master_driver w1_bus_master1: Family 0 for 00.400000000000.46 is not registered.
[ 117.175619] asoc-simple-card asoc-simple-card.0: ASoC: CPU DAI 20203000.i2s not registered
[ 117.175847] platform asoc-simple-card.0: Driver asoc-simple-card requests probe deferral

Contents of /etc/modules-load.d/raspberrypi.conf are:

bcm2708-rng
#snd-bcm2835
#i2c-dev
w1-gpio pullup=1
w1-therm

snd_soc_bcm2708
snd_soc_bcm2708_i2s
bcm2708_dmaengine

:(

carla_sch
Posts: 17
Joined: Wed Mar 18, 2015 5:23 pm

Re: I2S Success (at last) !

Wed Sep 02, 2015 9:58 pm

I upgraded arch-linux today (now 4.1.6 kernel) and the module
still works (even the one compiled for the 4.1.5 kernel loads).
My /etc/modules-load.d/raspberrypi.conf
is :
bcm2708-rng
snd-bcm2835
#snd_soc_pcm512x
i2c-dev

My archlinux is an older version that was upgraded via pacman -Syu ,
i did not try a fresh installation.

alvinAvR
Posts: 5
Joined: Tue Jan 22, 2013 7:47 pm

Re: I2S Success (at last) !

Thu Sep 03, 2015 5:42 am

Hi Carla,

Good news that it is working for you.

Could you post your /boot/config.txt please, I still have problems.

Thanks

alvinAvR
Posts: 5
Joined: Tue Jan 22, 2013 7:47 pm

Re: I2S Success (at last) !

Thu Sep 03, 2015 5:52 am

Also /boot/cmdline.txt

Mine is

Code: Select all

root=/dev/mmcblk0p2 rw rootwait console=ttyAMA0,115200 console=tty1 selinux=0 plymouth.enable=0 smsc95xx.turbo_mode=N dwc_otg.lpm_enable=0 kgdboc=ttyAMA0,115200 elevator=noop
Thanks

carla_sch
Posts: 17
Joined: Wed Mar 18, 2015 5:23 pm

Re: I2S Success (at last) !

Thu Sep 03, 2015 7:18 am

This is my cmdline.txt:

root=/dev/mmcblk0p5 rw rootwait console=ttyAMA0,115200 console=tty1 selinux=0 plymouth.enable=0 smsc95xx.turbo_mode=N dwc_otg.lpm_enable=0 kgdboc=ttyAMA0,115200 elevator=noop


In /boot/config.txt i2s is enabled:

device_tree_param=i2s=on

This is the output of lsmod:
Module Size Used by
snd_soc_simple_card 6405 0
my_loader 1580 0
evdev 10105 0
snd_soc_bcm2708_i2s 6899 2
regmap_mmio 3266 1 snd_soc_bcm2708_i2s
snd_soc_core 156250 3 snd_soc_simple_card,snd_soc_bcm2708_i2s
snd_compress 8074 1 snd_soc_core
snd_pcm_dmaengine 5356 1 snd_soc_core
i2c_bcm2708 5668 0
bcm2835_gpiomem 3343 0
uio_pdrv_genirq 3273 0
uio 8949 1 uio_pdrv_genirq
sch_fq_codel 7582 2
i2c_dev 6089 0
snd_bcm2835 20636 0
snd_pcm 86077 3 snd_bcm2835,snd_soc_core,snd_pcm_dmaengine
snd_timer 21100 1 snd_pcm
snd 62620 5 snd_bcm2835,snd_soc_core,snd_timer,snd_pcm,snd_compress
bcm2708_rng 1068 0
rng_core 7821 1 bcm2708_rng
ip_tables 11769 0
x_tables 16585 1 ip_tables
ipv6 333610 12

LisaJK
Posts: 14
Joined: Sat Jul 11, 2015 6:21 am

Re: I2S Success (at last) !

Thu Sep 03, 2015 3:56 pm

Hi Carla sch,

many thanks, still having problems with 20203000.i2s.

My cmdline.txt is identical to yours.

I also have I2S enabled in config.txt.

My lsmod are as follows, before and after insmod my_loader_ljk.ko

Code: Select all

[[email protected] loader2]# lsmod
Module                  Size  Used by
sch_fq_codel            7252  1
snd_soc_bcm2708_i2s     7027  0
regmap_mmio             3157  1 snd_soc_bcm2708_i2s
snd_soc_core          163859  1 snd_soc_bcm2708_i2s
snd_compress            8186  1 snd_soc_core
snd_pcm_dmaengine       5351  1 snd_soc_core
snd_pcm                84615  2 snd_soc_core,snd_pcm_dmaengine
snd_seq                56695  0
snd_seq_device          6535  1 snd_seq
snd_timer              19608  2 snd_pcm,snd_seq
snd                    60092  6 snd_soc_core,snd_timer,snd_pcm,snd_seq,snd_seq_device,snd_compress
evdev                   9464  0
joydev                  8515  0
w1_gpio                 4226  0
wire                   28558  1 w1_gpio
i2c_bcm2708             5646  0
cn                      5097  1 wire
uio_pdrv_genirq         3281  0
uio                     8710  1 uio_pdrv_genirq
bcm2708_rng             1143  0
rng_core                5666  1 bcm2708_rng
ipv6                  343408  24
[[email protected] loader2]# insmod my_loader_ljk.ko
[[email protected] loader2]# lsmod
Module                  Size  Used by
snd_soc_simple_card     6698  0
my_loader               1987  0
sch_fq_codel            7252  1
snd_soc_bcm2708_i2s     7027  0
regmap_mmio             3157  1 snd_soc_bcm2708_i2s
snd_soc_core          163859  2 snd_soc_simple_card,snd_soc_bcm2708_i2s
snd_compress            8186  1 snd_soc_core
snd_pcm_dmaengine       5351  1 snd_soc_core
snd_pcm                84615  2 snd_soc_core,snd_pcm_dmaengine
snd_seq                56695  0
snd_seq_device          6535  1 snd_seq
snd_timer              19608  2 snd_pcm,snd_seq
snd                    60092  6 snd_soc_core,snd_timer,snd_pcm,snd_seq,snd_seq_device,snd_compress
evdev                   9464  0
joydev                  8515  0
w1_gpio                 4226  0
wire                   28558  1 w1_gpio
i2c_bcm2708             5646  0
cn                      5097  1 wire
uio_pdrv_genirq         3281  0
uio                     8710  1 uio_pdrv_genirq
bcm2708_rng             1143  0
rng_core                5666  1 bcm2708_rng
ipv6                  343408  24
[[email protected] loader2]#
Last lines of dmesg are:

Code: Select all

[  860.250244] request module load 'bcm2708-dmaengine': 0
[  860.268578] register platform device 'asoc-simple-card': 0
[  860.277096] asoc-simple-card asoc-simple-card.0: ASoC: CPU DAI 20203000.i2s not registered
[  860.277191] platform asoc-simple-card.0: Driver asoc-simple-card requests probe deferral
[  860.358684] Hello World :)
Any ideas how come DAI 20203000.i2s is not registered???

carla_sch
Posts: 17
Joined: Wed Mar 18, 2015 5:23 pm

Re: I2S Success (at last) !

Thu Sep 03, 2015 7:04 pm

Find out your Linux version with uname -r , mine is now 4.1.6
But the sizes of the modules are different from yours, so
your version is different.

Find out what is in:
cat /sys/kernel/debug/platforms

That is how I found the name 20203000.i2s
Debugfs has to be mounted.

LisaJK
Posts: 14
Joined: Sat Jul 11, 2015 6:21 am

Re: I2S Success (at last) !

Fri Sep 04, 2015 12:21 am

Hi Carla,

I found a file called platforms in /sys/kernel/debug/asoc

This contained a different name for i2s, 3f203000.i2s. After using this in my loader, it loads!

Fantastic, many thanks!!!

Now I need to see if it works.

LisaJK
Posts: 14
Joined: Sat Jul 11, 2015 6:21 am

Re: I2S Success (at last) !

Fri Sep 04, 2015 4:00 pm

It works!

I've tried it on all the versions of Arch Linux I am using and the same fix works for them all. I just needed the correct name for that I2S file.

Thanks again!

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 10 guests