ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Thu Mar 05, 2015 1:43 am

I'm using an add-on board with the Pi2B which has an IR receiver which is directly routed to GPIO 18 (GPIO_GEN18). When I enable I2S with dtparam=i2s=on, this happens:

Code: Select all

[   16.593124] pinctrl-bcm2835 3f200000.gpio: pin gpio18 already requested by lirc_rpi; cannot claim for 3f203000.i2s
[   16.593131] pinctrl-bcm2835 3f200000.gpio: pin-18 (3f203000.i2s) status -22
[   16.593139] pinctrl-bcm2835 3f200000.gpio: could not request pin 18 (gpio18) from group gpio18  on device pinctrl-bcm2835
[   16.593145] bcm2708-i2s 3f203000.i2s: Error applying setting, reverse things back
Is there an easy way to override the default I2S pins (brcm,pins = <18 19 20 21>;) from within /boot/configt.txt to instead be something like 16 19 20 21? I was not able to find any examples of overriding the default I2S pins. I suppose I could create a modified bcm2709-rpi-2-b.dtb.

EDIT: Thank you, PhilE. That is not the answer I was hoping for, but a great answer anyway. And thanks for the PDF link. I'm sure it will be useful for me.
Last edited by ktb on Thu Mar 05, 2015 9:32 am, edited 2 times in total.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Thu Mar 05, 2015 8:54 am

I'm sorry, but that isn't possible. If you download the BCM2835 ARM Peripherals documentation from here and turn to pages 102-103 you will see a map of the alternate functions available on each GPIO pin. The I2S functions are labelled as PCM, and appear in two groups - 18-21 and 28-31. Later Models A and B use 28-31 brought out onto a separate header (P5), but the Pluses and Pi 2 use 18-21 for I2S, the other group being used for I2C and as GPIOs to control on-board devices.

So the declarations of pin usage in Device Tree has prevented you from making a configuration error. By not enabling I2S you would be able to use GPIO18, and vice-versa, but you can't have both. (I realise you may know this, but not all readers will.)

fogwizard2
Posts: 6
Joined: Sun Mar 15, 2015 4:51 am

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun Mar 15, 2015 5:02 am

I got a problem about devicetree.I have turn on the bcm2708 devicetree.And I have fix the config.txt to use devicetree.But the device in dts file is not to be register.And the node is visual in /proc/devicetree/ . What I should do?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun Mar 15, 2015 1:21 pm

If this is an i2c device and you are looking for /dev/i2c* then you will need to modprobe i2c-dev.

If it isn't that, give everyone a chance of helping you by providing some concrete information.

fogwizard2
Posts: 6
Joined: Sun Mar 15, 2015 4:51 am

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun Mar 15, 2015 8:26 pm

It is a i2c device.
Here is my dts file about the device.

Code: Select all

		[email protected] {
			compatible = "brcm,bcm2708-i2c";
			reg = <0x7e804000 0x1000>;
			interrupts = <0x2 0x15>;
			clocks = <0x5>;
			#address-cells = <0x1>;
			#size-cells = <0x0>;
			pinctrl-names = "default";
			pinctrl-0 = <0x7>;
			clock-frequency = <0x186a0>;
			linux,phandle = <0xc>;
			phandle = <0xc>;
			[email protected] {
				compatible = "synaptics,dsx-i2c";
				reg = <0x20>;
			};
		};
I got the node [email protected] in /proc/device-tree/soc/ .
The problem is that the probe function in my i2c driver should be call but actually not.
As we know if device name attach driver's compatible,the probe function will be call .And the driver I use work well on my phone(base on qcomm cpu).So the driver code should be OK. Is there anything I do wrong?
Last edited by ShiftPlusOne on Sun Mar 15, 2015 8:40 pm, edited 1 time in total.
Reason: Added code tags

fogwizard2
Posts: 6
Joined: Sun Mar 15, 2015 4:51 am

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun Mar 15, 2015 8:32 pm

The kernel I use is rasp-3.18-y.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun Mar 15, 2015 9:08 pm

1) Where is the source for this driver? I don't recognise it - I think it must be an out-of-tree driver.
2) Search the source for your compatible string - "synaptics,dsx-i2c" - and show what you find.
3)

Code: Select all

grep "synaptics,dsx-i2c" /lib/modules/`uname -r`/modules.alias
Again, show what you find.
4) If you get no hits for 3) try relaxing the search string to just "synaptics".

fogwizard2
Posts: 6
Joined: Sun Mar 15, 2015 4:51 am

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Mon Mar 16, 2015 5:30 pm

1.The driver is in the input subsystem in driver/input/touchscreen/synaptics_dsx
2.The output is:
[email protected]:~/raspberry/linux$ grep -nr "synaptics,dsx-i2c" .
Binary file ./.tmp_vmlinux1 matches
Binary file ./.tmp_vmlinux2 matches
Binary file ./drivers/built-in.o matches
Binary file ./drivers/input/built-in.o matches
Binary file ./drivers/input/touchscreen/built-in.o matches
Binary file ./drivers/input/touchscreen/synaptics_dsx/built-in.o matches
./drivers/input/touchscreen/synaptics_dsx/synaptics_dsx_i2c.c:546: .compatible = "synaptics,dsx-i2c",
Binary file ./drivers/input/touchscreen/synaptics_dsx/synaptics_dsx_i2c.o matches
3. "grep "synaptics,dsx-i2c" /lib/modules/`uname -r`/modules.alias" : Run this command didn't hit anything. Is that a problem? I build the synaptics driver in kernel(not a module).
4.Thanks.

fogwizard2
Posts: 6
Joined: Sun Mar 15, 2015 4:51 am

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Mon Mar 16, 2015 5:49 pm

I have a try to use mainline linux on kernel.org.And I found it run.But I still not found the real reason.Here is my log use mainline kernel(3.19.1). I found network is not working use mainline kernel.I am try to get it work now.Thanks.
4.178915] mousedev: PS/2 mouse device common for all mice
[ 4.185211] ====synaptics_rmi4_init
[ 4.188928] i2c /dev entries driver
[ 4.194012] ====synaptics_rmi4_i2c_probe
[ 4.198275] ====synaptics_rmi4_probe

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Tue Mar 17, 2015 9:28 am

That path ("driver/input/touchscreen/synaptics_dsx") does not exist in any kernel I can find (even after correcting it to "drivers/") - not in the upstream kernel.org sources and not in the raspberrypi/linux branches. I think you must have applied a patch, or cloned some other tree. Unless you can be straight with me and tell me where you got the source, I can't help you.

fogwizard2
Posts: 6
Joined: Sun Mar 15, 2015 4:51 am

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Tue Mar 17, 2015 5:13 pm

1.I am sorry about the source code is belong to company and I don't know whether I can set free it in law.
2.Many Thanks.

ZivS
Posts: 6
Joined: Sun May 03, 2015 10:25 am

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun May 03, 2015 11:07 am

Hi,

I've been struggling with the I2C activation for a few days on Pi 2 :/
I am trying to activate it for the use of an RTC board (DS3231).

sudo i2cdetect -y 1 (or 0...) is resulting with the below:
"Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory"

I own 2 Pi, Model B+ , and Rev 2 B Pi.

On the B+ i have the 3.12 kernel , I've added i2c-dev and i2c-BCM2708 to etc/modules & installed python-smbus and all is good, the i2cdetect is working with no issues.

On the Pi 2 B on the other hand... can't get the i2cdetect to work, the kernel is 3.18.6

I've added dtparam=i2c_arm=on to boot/config.txt , no good.
Tried to add dtparam=i2c1=on , no good.
Tried both..no good.

Tried "device_tree=" to disable the device tree , no good...

Also tried to downgrade the kernel with rpi-update + hash of 3.15.35 , it went through fine but after reboot the uname -a still shows 3.18.6... weird?

Any idea on why my i2cdetect isn't working on the Pi 2 ? and how can it fixed ?
Appreciate your thoughts.
Ziv

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun May 03, 2015 3:27 pm

In order for the user-space interfaces (/dev/i2c*) to exist, you need to load module i2c-dev. Put i2c-dev into /etc/modules and reboot (or modprobe i2c-dev to avoid the need to reboot).

ZivS
Posts: 6
Joined: Sun May 03, 2015 10:25 am

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun May 03, 2015 3:36 pm

Hi Phil,

Thank you for the reply.

In the B+ i wrote - "I've added i2c-dev and i2c-BCM2708 to etc/modules".
I also did it in the Pi 2, it is loading, i can see it when the Pi 2 loads.
If i am checking " lsmod | grep i2c* " , i can see both "i2c-dev" and "i2c-BCM2708" are running but still i get the error when running i2cdetect.

Maybe i have an HW problem with my Pi 2 ?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun May 03, 2015 3:41 pm

What does

Code: Select all

dmesg | grep -i i2c
show?

ZivS
Posts: 6
Joined: Sun May 03, 2015 10:25 am

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun May 03, 2015 3:43 pm

"dmesg | grep -i i2c" shows:

[ 17.400745] i2c /dev entries driver

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun May 03, 2015 3:51 pm

That's far too short - it should look more like this (from a Pi 1, but you get the idea):

Code: Select all

[    5.503791] bcm2708_i2c_init_pinmode(0,0)
[    5.666925] bcm2708_i2c_init_pinmode(0,1)
[    5.674016] bcm2708_i2c 20205000.i2c: BSC0 Controller at 0x20205000 (irq 79) (baudrate 100000)
[    5.991503] bcm2708_i2c_init_pinmode(1,2)
[    6.206989] bcm2708_i2c_init_pinmode(1,3)
[    6.213990] bcm2708_i2c 20804000.i2c: BSC1 Controller at 0x20804000 (irq 79) (baudrate 100000)
Try setting "dtdebug=1" in your config.txt, rebooting, and then running

Code: Select all

sudo vcdbg log msg
. You can ignore the lines about HDMI.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun May 03, 2015 7:45 pm

After an exchange of private messages, ZivS and I discovered that the problem was because /boot/config.txt wasn't the file we thought it was. His system is running a Berryboot installation, and for some reason the VFAT boot partition required for the firmware to boot was not mounted in his main OS image. Instead the main filing system contained a copy of the original, so you can edit /boot/config.txt as much as you like but it won't change real config.txt in the boot partition.

The solution was to edit /etc/fstab and uncomment the following line:

Code: Select all

#/dev/mmcblk0p1  /boot           vfat    defaults          0       2
and to do the following:

Code: Select all

sudo mv /boot /boot.old
sudo mkdir /boot
Rebooting will then make the real config.txt editable from within the OS. All that was then required was to add:

Code: Select all

dtparam=i2c_arm=on
If you'd rather not make a permanent change to the installation, you could temporarily mount /dev/mmcblk0p1 somewhere else and edit the file that way:

Code: Select all

sudo mkdir /realboot
sudo mount -t vfat /dev/mmcblk0p1 /realboot
At this point you can edit /realboot/config.txt. Alternatively, you could also make this change from your PC using a card reader.

ZivS
Posts: 6
Joined: Sun May 03, 2015 10:25 am

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun May 03, 2015 8:26 pm

Thanks for the great help Phil :)

One more thing i might add, after doing the permanent change Phil came up with (which i validated on a fresh install with berryboot-20150401-pi2-only) , the /boot/config.txt file will have to be edited to this content:
* (it had [pi 1] options that needed to be removed)

Code: Select all

disable_overscan=1
start_x=1
gpu_mem=128

dtparam=i2c_arm=on

# Berryboot settings, do not change
kernel=kernel_rpi2_aufs.img
initramfs berryboot.img


rgrubb
Posts: 2
Joined: Wed May 06, 2015 5:42 pm

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Mon May 11, 2015 7:26 pm

I am looking at using the Pi 2 for an audio application that requires I2S. I can see how to enable the firmware module load in the config file. The BCM2835 ARM Peripherals document shows me how to access the interface for the earlier board. Is the BM 2836 identical in this respect ? Thanks.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Mon May 11, 2015 7:57 pm

Yes it is. You will find that all of the audio boards compatible with the B+ work with the Pi 2 Model B without modification.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sat May 30, 2015 7:29 pm

There is a new Forum section dedicated to Device Tree topics. You can find it here.

javierfeto
Posts: 2
Joined: Thu Jul 30, 2015 11:58 pm

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sat Sep 26, 2015 10:26 pm

Hi, I have a problem usin RFID card reader (RC522) through SPI.
I need to manage 4 Card reader but the raspberry pi 2 onlyhave 2 CE pins, so it only allow to manage 2 card reader.
How can i fix this problem?? is there any card expansion??

Thanks and sorry my english

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Mon Sep 28, 2015 2:35 pm

You are in luck. The current RPi SPI driver, spi-bcm2835, support GPIO chip-selects. This means that any free GPIO line can be used as another chip select. In fact, as a result of some driver performance optimisations causing the hardware ("native") chip-selects to glitch, the driver will automatically convert native CS's to GPIO CS's.

The use of GPIO CS's (apart from the automatic native->GPIO coercion performed by the spi-bcm2835 driver) is controlled by the cs-gpio Device Tree property; the basic concepts and Device-tree usage are described here. The GPIO syntax is very briefly touched on here, but what you need to know is that after the reference to the GPIO controller ("&gpio") comes the pin number followed by a boolean indicating if the sense of the GPIO is normal (0) or inverted (1), e.g. "<&gpio 27 1>".

To request two extra CS-GPIOs, you would add this property to the node with the "spi0" label:

Code: Select all

    cs-gpios = <0>, <0>, <&gpio 20 1>, <&gpio 21 1>;
The first two <0>s request that native CS's 0 and 1 are used (even though the driver will convert them to GPIO CS's), and that GPIO's 20 and 21 are used as active-low chip selects 2 and 3.

It is probably also wise (perhaps even necessary) to reserve the extra GPIO pins to ensure that no other drivers can claim them, and to mark them as outputs. You can do this by adding this to the node labelled "gpio":

Code: Select all

	spi0_cs_pins: spio_cs_pins {
		brcm,pins = <20 21>;
		brcm,function = <1>; /* out */
	};
and changing the spi0 node to say:

Code: Select all

	pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
You can do all of this with a Device Tree overlay that looks like this:

Code: Select all

/dts-v1/;
/plugin/;

/ {
	compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";

	[email protected] {
		target = <&spi0>;
		frag0: __overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
			status = "okay";
			cs-gpios = <0>, <0>, <&gpio 20 1>, <&gpio 21 1>;

			[email protected]{
				compatible = "spidev";
				reg = <2>;	/* CE2 */
				#address-cells = <1>;
				#size-cells = <0>;
				spi-max-frequency = <500000>;
			};

			[email protected]{
				compatible = "spidev";
				reg = <3>;	/* CE3 */
				#address-cells = <1>;
				#size-cells = <0>;
				spi-max-frequency = <500000>;
			};
		};
	};

	[email protected] {
		target = <&gpio>;
		__overlay__ {
			spi0_cs_pins: spi0_cs_pins {
				brcm,pins = <20 21>;
				brcm,function = <1>; /* out */
			};
		};
	};

	__overrides__ {
		cs2_pin = <&frag0>,"cs-gpios:12", <&spi0_cs_pins>,"brcm,pins:0";
		cs3_pin = <&frag0>,"cs-gpios:24", <&spi0_cs_pins>,"brcm,pins:4";
	};
};
The "__overrides__" block defines two Device Tree parameters, allowing you to change the pins that are used. Save the above as spi-gpio-cs-overlay.dts, and compile it into an overlay using:

Code: Select all

sudo apt-get install device-tree-compiler
# dtc [email protected] -I dts -O dtb -o spi-gpio-cs-overlay.dtb spi-gpio-cs-overlay.dts  # Old version for 4.1 and earlier
# sudo cp spi-gpio-cs-overlay.dtb /boot/overlays
dtc [email protected] -I dts -O dtb -o spi-gpio-cs.dtbo spi-gpio-cs-overlay.dts           # New version for 4.4 and later
sudo cp spi-gpio-cs.dtbo /boot/overlays
then use it by adding this to your config.txt:

Code: Select all

dtoverlay=spi-gpio-cs,cs2_pin=5,cs3_pin=6
An explanation of Device Tree and how to use it on Raspberry Pi's is here.

User avatar
bonzadog
Posts: 215
Joined: Wed Apr 25, 2012 9:40 am
Location: Rietberg/Germany

I2C Enbaled s

Sun Oct 04, 2015 6:47 pm

I have just installed Openelectrons Pan - Tilt software.
The Pan / Tilt tests work. So I want to use the Web Cam interface to show the video AND manual set the pan/tilt angles.

On boot a python programs fails Problem and shows that
smbus.SMBus(1) causes a "no such file" condition
I2Ctools and smbus are installed, I2C enabled.

/boot/config.txt contains
.....
start_x=1
gpu_mem=128
dtparam=i2c_arm=on


sudo i2cdetect -y 0 shows the following
Error: Could not open file `/dev/i2c-0' or `/dev/i2c/0': No such file or directory

A small python programme shows this

Type "help", "copyright", "credits" or "license" for more information.
>>> import smbus
>>> bus = smbus.SMBus(1)

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory
>>> bus = smbus.SMBus(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory

I have the impression that I am doing something wrong, and would like the forums assistance.
.

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