DirkS
Posts: 9902
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: I2C mulitplexer support

Sun Apr 10, 2016 6:48 pm

Massi wrote:so i tried looking for the overlay files and it seems to be present in both firmwares

Code: Select all

pi@baguette:/dev $ sudo find / -name "*i2c-mux*"
/lib/modules/4.1.19-v7+/kernel/drivers/i2c/i2c-mux.ko
/lib/modules/4.1.21-v7+/kernel/drivers/i2c/i2c-mux.ko
Those are the drivers, not the overlays.
The overlays are only available in the 'next' branch:
master: https://github.com/raspberrypi/firmware ... t/overlays
next: https://github.com/raspberrypi/firmware ... t/overlays

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7143
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: I2C mulitplexer support

Sun Apr 10, 2016 7:26 pm

Massi wrote:that said, why isn't it working? :) is it available in my firmware or still not?
To be pedantic, this is a function of the kernel not the firmware.
DirkS has already pointed out to you that it is on the "next" branch, so "sudo BRANCH=next rpi-update" if you want it. I haven't worked through where Pi Towers want new work, but I've shifted on to kernel 4.4 and haven't hit any issues. Some stuff I expect they'll back port to 4.1 when they get a chance, but that requires effort.
Massi wrote:and, finally, i haven't understood if using the multiplexer on i2c-0 on a pi3 is safe or not (safe: does not kill any other function)
Simple answer there - it is NOT safe under any circumstances to enable i2c-0 on a Pi3. Whether it is to attach a mux or anything else is irrelevant, it's almost guaranteed to result in failure.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: I2C mulitplexer support

Sun Apr 10, 2016 8:54 pm

thanks both of you.
but now i can get only one mux working
on address 0x70 or 0x74, depending which one i call last.
what am i loosing?
thanks again

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7143
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: I2C mulitplexer support

Mon Apr 11, 2016 8:40 am

Massi wrote:thanks both of you.
but now i can get only one mux working
on address 0x70 or 0x74, depending which one i call last.
what am i loosing?
thanks again
dtoverlay just adds a single section to the overall device-tree (named i2cmux). By including it twice, you're just overwriting the settings applied with the first line.

If you really want two muxes, then you need to build your own dt overlay. There would be too many combinations of potential connections to make it worthwhile trying to describe, and I even said as much in viewtopic.php?f=44&t=140054#p932034

- Take https://raw.githubusercontent.com/raspb ... verlay.dts
- Add in

Code: Select all

		i2cmux2: mux@71 {
				compatible = "nxp,pca9548";
				reg = <0x71>;
				#address-cells = <1>;
				#size-cells = <0>;

				i2c@0 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <0>;
				};
				i2c@1 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <1>;
				};
				i2c@2 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <2>;
				};
				i2c@3 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <3>;
				};
				i2c@4 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <4>;
				};
				i2c@5 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <5>;
				};
				i2c@6 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <6>;
				};
				i2c@7 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <7>;
				};
			};
- Also amend the overrides section:

Code: Select all

	__overrides__ {
		addr = <&i2cmux2>,"reg:0";
	};
- Recompile the overlay

Code: Select all

dtc -@ -I dts -O dtb -o i2c-mux-pca9548a-overlay.dtb i2c-mux-pca9548a-overlay.dts
I had found a way to be able to number the devices in a controlled way, but I haven't found a way to make that controllable from an overlay. I may make a second PR later to add in that option.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: I2C mulitplexer support

Mon Apr 11, 2016 10:07 am

Thanks, i'll give this a try.

what do you mean with this?
I had found a way to be able to number the devices in a controlled way, but I haven't found a way to make that controllable from an overlay. I may make a second PR later to add in that option.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7143
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: I2C mulitplexer support

Mon Apr 11, 2016 12:35 pm

Massi wrote:what do you mean with this?
I had found a way to be able to number the devices in a controlled way, but I haven't found a way to make that controllable from an overlay. I may make a second PR later to add in that option.
Currently the devices will adopt the next available /dev/i2cN number. You can tell the kernel to always allocate them as /dev/i2c11 to 18, or other more memorable numbers. That is what I have a potential followup to do.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: I2C mulitplexer support

Mon Apr 11, 2016 6:53 pm

6by9 wrote: - Take https://raw.githubusercontent.com/raspb ... verlay.dts
- Add in

Code: Select all

		i2cmux2: mux@71 {
				compatible = "nxp,pca9548";
				reg = <0x71>;
				#address-cells = <1>;
				#size-cells = <0>;

				i2c@0 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <0>;
				};
				i2c@1 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <1>;
				};
				i2c@2 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <2>;
				};
				i2c@3 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <3>;
				};
				i2c@4 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <4>;
				};
				i2c@5 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <5>;
				};
				i2c@6 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <6>;
				};
				i2c@7 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <7>;
				};
			};
ok, i'm having fun with this but sadly i need some help..

I took the starting dts file and added this part on the same indentation level of i2cmux (i hope that's right..)
- Also amend the overrides section:

Code: Select all

	__overrides__ {
		addr = <&i2cmux2>,"reg:0";
	};
I did this adding a new param (add2 for i2cmux2, leaving addr for i2cmux), but since i could not have it loaded, i tried also with a new overrides section (as you posted)
- Recompile the overlay

Code: Select all

dtc -@ -I dts -O dtb -o i2c-mux-pca9548a-overlay.dtb i2c-mux-pca9548a-overlay.dts
first i installed the device-tree-compiler, than i compiled the amended dts file (no output from the compiler at all, only che dtb file)

Then i copied the newly created i2c-mux-pca9548a-double-overlay.dtb to /boot/overlays and added a line to config.txt:

Code: Select all

dtoverlay=i2c-mux-pca9548a-double,addr=0x70,addr2=0x74
dtdebug=1
Result? a simple "Failed to load overlay 'i2c-mux-pca9548a-double'"

Where am i wrong? the man page says that
"dtoverlay=acme-board [...] will cause the loader to look for overlays/acme-board-overlay.dtb"
so i think i used the correct name, but i can't understand the problem :(

thanks

Here is my (your :)) code:

Code: Select all

// Definitions for NXP PCA9548A I2C mux on ARM I2C bus. Two muxes supported
/dts-v1/;
/plugin/;

/{
	compatible = "brcm,bcm2708";

	fragment@0 {
		target = <&i2c_arm>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			status = "okay";

			i2cmux: mux@70 {
				compatible = "nxp,pca9548";
				reg = <0x70>;
				#address-cells = <1>;
				#size-cells = <0>;

				i2c@0 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <0>;
				};
				i2c@1 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <1>;
				};
				i2c@2 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <2>;
				};
				i2c@3 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <3>;
				};
				i2c@4 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <4>;
				};
				i2c@5 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <5>;
				};
				i2c@6 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <6>;
				};
				i2c@7 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <7>;
				};
			};
			i2cmux2: mux@71 {
				compatible = "nxp,pca9548";
				reg = <0x71>;
				#address-cells = <1>;
				#size-cells = <0>;

				i2c@0 {
				   #address-cells = <1>;
				   #size-cells = <0>;
				   reg = <0>;
				};
				i2c@1 {
				   #address-cells = <1>;
				   #size-cells = <0>;
				   reg = <1>;
				};
				i2c@2 {
				   #address-cells = <1>;
				   #size-cells = <0>;
				   reg = <2>;
				};
				i2c@3 {
				   #address-cells = <1>;
				   #size-cells = <0>;
				   reg = <3>;
				};
				i2c@4 {
				   #address-cells = <1>;
				   #size-cells = <0>;
				   reg = <4>;
				};
				i2c@5 {
				   #address-cells = <1>;
				   #size-cells = <0>;
				   reg = <5>;
				};
				i2c@6 {
				   #address-cells = <1>;
				   #size-cells = <0>;
				   reg = <6>;
				};
				i2c@7 {
				   #address-cells = <1>;
				   #size-cells = <0>;
				   reg = <7>;
				};
			};
		};
	};
	__overrides__ {
		addr = <&i2cmux>,"reg:0";
		addr2 = <&i2cmux2>,"reg:0";
	};
};

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: I2C mulitplexer support

Mon Apr 11, 2016 7:04 pm

ok the code is correct, but you have to build a dtbo file
ref: viewtopic.php?f=28&t=140835#p933631

now with the double param i'm full of i2c buses :lol:

Code: Select all

pi@baguette:/dev $ ls i2c-*
i2c-1  i2c-10  i2c-11  i2c-12  i2c-13  i2c-14  i2c-15  i2c-16  i2c-17  i2c-18  i2c-3  i2c-4  i2c-5  i2c-6  i2c-7  i2c-8  i2c-9
stupid question: since driver files are present, can't i build an overlay for muxes for 4.1 kernel?

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: I2C mulitplexer support

Mon Apr 11, 2016 8:09 pm

well, there's something "strange" in how channels are managed.

I've done some testing connecting devices to i2c-1, one of channels of the first mux and one of the second mux.

Accessing i2c-1 i expected to see UU on reserved addresses (0x70 and 0x74) and the device attached to i2c-1
and that's ok, if i detect devices first than muxes.

But if i access the device on one mux and THEN on i2c-1, i still can access the device on the mux.

This means, in my opinion, that when accessing i2c-1 the mux is not "turned off" writing 0x00 on the control register. The last selected address remains active (so accessing i2c-1 after having accessed a muxed channel is the same of accessing the muxed channel again)

This is a "conceptual" problem, but the "real" problem comes when using two (or more) muxes. In this case the last channel of each mux remains selected, so there's a true risk of having the same address used on both muxes and get an address conflict when accessing one mux, the other, or i2c-1

i strongly doubt this can be managed at "overlay" level.
probably leaving i2c-1 without overhead is a good choice for performance (every call to muxed channels requires an i2c write call), but with multiple muxes it's a mess..
ideas?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7143
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: I2C mulitplexer support

Mon Apr 11, 2016 8:42 pm

In the docs - https://github.com/raspberrypi/linux/bl ... ca954x.txt
Optional Properties:

- reset-gpios: Reference to the GPIO connected to the reset input.
- i2c-mux-idle-disconnect: Boolean; if defined, forces mux to disconnect all
children in idle state. This is necessary for example, if there are several
multiplexers on the bus and the devices behind them use same I2C addresses.
So add "i2c-mux-idle-disconnect;" to your amended overlay and you should be good.

It's not really applicable for the base overlay with a single mux, and that saves a two byte I2C transaction at each end of every transfer.

In theory you can build for 4.1 kernels, although I hadn't realised they were built by default - I added them to the config for the 4.4 tree.
I don't see i2c-mux-pca954x.ko in the 4.1 build, so you're not going to be able to control these particular muxes - i2c-mux.ko is just the mux framework.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7143
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: I2C mulitplexer support

Mon Apr 11, 2016 8:54 pm

BTW The default kernel obtained via rpi-update has just been bumped to 4.4, so 4.1 is now less relevant.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: I2C mulitplexer support

Tue Apr 12, 2016 5:42 am

perfect, i'll give this a try this evening.
Thanks a lot 6by9

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: I2C mulitplexer support

Tue Apr 12, 2016 5:45 pm

good fun with overlays :)
this version manages 2 muxes and accepts specific i2c address for both of them
it also accepts the boolean "idle disconnect" param for both of them

Thanks 6by9, really interesting.
I'm gonna do some performance testing..

Code: Select all

// Definitions for NXP PCA9548A I2C mux on ARM I2C bus. Two muxes supported
/dts-v1/;
/plugin/;

/{
	compatible = "brcm,bcm2708";

	fragment@0 {
		target = <&i2c_arm>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			status = "okay";

			i2cmux: mux@70 {
				compatible = "nxp,pca9548";
				reg = <0x70>;
				#address-cells = <1>;
				#size-cells = <0>;

				i2c@0 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <0>;
				};
				i2c@1 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <1>;
				};
				i2c@2 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <2>;
				};
				i2c@3 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <3>;
				};
				i2c@4 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <4>;
				};
				i2c@5 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <5>;
				};
				i2c@6 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <6>;
				};
				i2c@7 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <7>;
				};
			};
			i2cmux2: mux@71 {
				compatible = "nxp,pca9548";
				reg = <0x71>;
				#address-cells = <1>;
				#size-cells = <0>;

				i2c@0 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <0>;
				};
				i2c@1 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <1>;
				};
				i2c@2 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <2>;
				};
				i2c@3 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <3>;
				};
				i2c@4 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <4>;
				};
				i2c@5 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <5>;
				};
				i2c@6 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <6>;
				};
				i2c@7 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <7>;
				};
			};
		};
	};
	__overrides__ {
		addr = <&i2cmux>,"reg:0";
		addr2 = <&i2cmux2>,"reg:0";
		idle-disconnect = <&i2cmux>,"i2c-mux-idle-disconnect?";
		idle-disconnect2 = <&i2cmux2>,"i2c-mux-idle-disconnect?";
	};
};

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7143
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: I2C mulitplexer support

Tue Apr 12, 2016 8:21 pm

Possibly better to make a second overlay rather than cram everything into one. It also means that the overrides can keep the same names.

There's a bit of a learning curve to these overlays, but actually not as tricky as they at first appear.

If you wanted to play with being able to specify the /dev/i2cN node number, then my amended overlay is:

Code: Select all

// Definitions for NXP PCA9548A I2C mux on ARM I2C bus.
/dts-v1/;
/plugin/;

/{
	compatible = "brcm,bcm2708";

	fragment@0 {
		target = <&i2c_arm>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			status = "okay";

			i2cmux: mux@70 {
				compatible = "nxp,pca9548";
				reg = <0x70>;
				#address-cells = <1>;
				#size-cells = <0>;

				i2cm0: i2c@0 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <0>;
				};
				i2cm1: i2c@1 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <1>;
				};
				i2cm2: i2c@2 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <2>;
				};
				i2cm3: i2c@3 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <3>;
				};
				i2cm4: i2c@4 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <4>;
				};
				i2cm5: i2c@5 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <5>;
				};
				i2cm6: i2c@6 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <6>;
				};
				i2cm7: i2c@7 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <7>;
				};
			};
		};
	};
	fragment@1 {
		target-path = "/";
		__overlay__ {
			aliases {
				i2c5 = &i2cm0;
				i2c7 = &i2cm1;
				i2c9 = &i2cm2;
				i2c11 = &i2cm3;
				i2c13 = &i2cm4;
				i2c15 = &i2cm5;
				i2c17 = &i2cm6;
				i2c19 = &i2cm7;
			};
		};
	};
	__overrides__ {
		addr = <&i2cmux>,"reg:0";
	};
};
Would enumerate the devices as i2c5, 7, 9, 11, 13, 15, 17, and 19. Alter those aliases to control the device names (always has to be i2c<number> I think).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Adco
Posts: 42
Joined: Fri Mar 11, 2016 3:01 pm

Re: I2C mulitplexer support

Thu Apr 21, 2016 2:05 pm

brekee12 wrote:Thank you for the idea of jumperable address space and SCL SDA. I will take it into consideration.
Some people complaining they want long lines (10m) to their sensor. It would solved their needs. (Most cases temperature sensor outside.) As the board is not assembled or if someone ask me I partially assemble to decrease costs, it is not required to use driver, even the two connection point can be shorted and it is like nothing but not a driver there.

What I would like to ask you to see everything from the driver point of view. I am not a professional, especially not from software point of view. My original idea was not to check my schematic, but I would like to design something which works with your driver.
I am working towards a system that can communicate over very long distances. I will use a P82B96 chip. It is an I2C extender. No EN line needed. I need to talk to 100 remote I2C devices located all over a building and this seems to be the best way to do it.

Here is a great App note. http://www.nxp.com/documents/application_note/AN255.pdf

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: I2C mulitplexer support

Thu Apr 21, 2016 2:15 pm

Adco wrote:I am working towards a system that can communicate over very long distances. I will use a P82B96 chip. It is an I2C extender. No EN line needed. I need to talk to 100 remote I2C devices located all over a building and this seems to be the best way to do it.

Here is a great App note. http://www.nxp.com/documents/application_note/AN255.pdf
i have a couple of P82B715 boards in my setup ( http://sandboxelectronics.com/?product= ... 715-module ) and i have to say they work quite good.
Your PB82B96 should be even better so it should help you, but if devices are "located all over the building" you could need a extender chip for every device

PS: what do you mean with "very long distance"? :)

Adco
Posts: 42
Joined: Fri Mar 11, 2016 3:01 pm

Re: I2C mulitplexer support

Thu Apr 21, 2016 7:31 pm

Sure, each node would require an extender chip. They are not expensive.

Long distance to me is more than 100m. The mentioned app says 1km is possible.

camrex
Posts: 4
Joined: Fri Apr 22, 2016 3:10 pm

Re: I2C mulitplexer support

Fri Apr 22, 2016 3:13 pm

Would this be compatible with the TCA9545, which is a 4-channel multiplexer, or would changes need to be made?

Thanks.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7143
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: I2C mulitplexer support

Fri Apr 22, 2016 5:03 pm

camrex wrote:Would this be compatible with the TCA9545, which is a 4-channel multiplexer, or would changes need to be made?
The kernel driver supports the TCA9545 (and PCA9540, PCA9542, PCA9543, PCA9544, PCA9546, PCA9547, and PCA9548), but the overlay specifically specifies the PCA9548.

Creating a new overlay for PCA/TCA 9545 shouldn't be difficult.
- Take the 9548 overlay at https://github.com/raspberrypi/linux/bl ... verlay.dts and rename it.
- Amend line 16 from compatible = "nxp,pca9548" to compatible = "nxp,pca9545"
- Remove lines 41-60 as you only have 4 slave nodes.
- Compile the overlay (see docs at https://www.raspberrypi.org/documentati ... ce-tree.md)
- Push to /boot/overlays on your device.
- Add appropriate dtoverlay=new_overlay line to /boot/config.txt
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

camrex
Posts: 4
Joined: Fri Apr 22, 2016 3:10 pm

Re: I2C mulitplexer support

Fri Apr 22, 2016 5:37 pm

That is great news. Would it be worth making the built in overlay compatible with all of those chips. I have made some edits to the current overlay to add support for 2,4 and 8 channel mulitplexers in the PCA954x family. I currently have them called by (i2cmux2, i2cmux4, and i2cmux8). Here is the code I've come up with for the overlay. I was a little unsure about what would need to be changed in the overrides (so did not make a change.)

Code: Select all

// Definitions for several NXP PCA954x based I2C mux on ARM I2C bus.
/dts-v1/;
/plugin/;

/{
	compatible = "brcm,bcm2708";

	fragment@0 {
		target = <&i2c_arm>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			status = "okay";

			// 2-channel mux (pca9540, pca9542, pca9543)
			i2cmux2: i2cmux2@70 {
				compatible = "nxp,pca9542";
				reg = <0x70>;
				#address-cells = <1>;
				#size-cells = <0>;

				i2c@0 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <0>;
				};
				i2c@1 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <1>;
				};
			};
			// 4-channel mux (pca9544, pca9545, pca9546)
			i2cmux4: i2cmux4@70 {
				compatible = "nxp,pca9545";
				reg = <0x70>;
				#address-cells = <1>;
				#size-cells = <0>;

				i2c@0 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <0>;
				};
				i2c@1 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <1>;
				};
				i2c@2 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <2>;
				};
				i2c@3 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <3>;
				};
			};
			// 8-channel mux (pca9547, pca9548)
			i2cmux8: i2cmux8@70 {
				compatible = "nxp,pca9548";
				reg = <0x70>;
				#address-cells = <1>;
				#size-cells = <0>;

				i2c@0 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <0>;
				};
				i2c@1 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <1>;
				};
				i2c@2 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <2>;
				};
				i2c@3 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <3>;
				};
				i2c@4 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <4>;
				};
				i2c@5 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <5>;
				};
				i2c@6 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <6>;
				};
				i2c@7 {
					#address-cells = <1>;
					#size-cells = <0>;
					reg = <7>;
				};
			};
		};
	};
	__overrides__ {
		addr = <&i2cmux>,"reg:0";
	};
};
I also wasn't sure if comments were allowed within the overlay, but I added them anyways.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7143
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: I2C mulitplexer support

Fri Apr 22, 2016 6:49 pm

These probably don't want to all be in the one overlay but a set, each with suitable names. Otherwise the kernel will try to load them all, and there's no way to identify over i2c which one is actually connected. The user then needs to specify the correct overlay to load based on what they've actually connected.
Note also that you've used the same i2c address for all of these devices - that's going to fail pretty badly.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

camrex
Posts: 4
Joined: Fri Apr 22, 2016 3:10 pm

Re: I2C mulitplexer support

Tue Apr 26, 2016 4:26 pm

So I performed the steps that are outlined below. I compiled the overlay and added it to the /boot/overlays directory. I am on kernel 4.4. I added i2c-mux to /etc/modules. But unfortunately have had no luck getting access to the extra busses from the TCA9545. i2cdetect only shows the i2c bus 1 from the raspberry pi.

Any suggestions, am I missing a step?
The kernel driver supports the TCA9545 (and PCA9540, PCA9542, PCA9543, PCA9544, PCA9546, PCA9547, and PCA9548), but the overlay specifically specifies the PCA9548.

Creating a new overlay for PCA/TCA 9545 shouldn't be difficult.
- Take the 9548 overlay at https://github.com/raspberrypi/linux/bl ... verlay.dts and rename it.
- Amend line 16 from compatible = "nxp,pca9548" to compatible = "nxp,pca9545"
- Remove lines 41-60 as you only have 4 slave nodes.
- Compile the overlay (see docs at https://www.raspberrypi.org/documentati ... ce-tree.md)
- Push to /boot/overlays on your device.
- Add appropriate dtoverlay=new_overlay line to /boot/config.txt

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7143
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: I2C mulitplexer support

Tue Apr 26, 2016 4:39 pm

camrex wrote:So I performed the steps that are outlined below. I compiled the overlay and added it to the /boot/overlays directory. I am on kernel 4.4. I added i2c-mux to /etc/modules. But unfortunately have had no luck getting access to the extra busses from the TCA9545. i2cdetect only shows the i2c bus 1 from the raspberry pi.

Any suggestions, am I missing a step?
i2cdetect should see the address of the TCA9545 and mark it as UU if the kernel driver is loaded and it found a TCA9545 when it tried talking to the configured I2C address.
If you don't see the mux address as having been detected, then you've got a wiring issue to sort first.
There has been a recent change to the kernel tree with regard overlays. Did you compile it to a .dtb or a .dtbo file? Follow whatever the rest of the files in /boot/overlays shows.

You shouldn't need to add anything to /etc/modules - device tree should have done all of that for you. You will need to add i2c-dev to there if you want access from userspace.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

camrex
Posts: 4
Joined: Fri Apr 22, 2016 3:10 pm

Re: I2C mulitplexer support

Tue Apr 26, 2016 4:45 pm

I actually was able to finally figure out the problem. I had named the file i2c-mux-pca9545a-overlay.dtbo and it needed to be i2c-mux-pca9545a.dtbo. Now i2cdetect -l is recognizing all of the busses.

It always seems to be stupid things like this.

Thanks for your help.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7143
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: I2C mulitplexer support

Tue Apr 26, 2016 4:52 pm

Glad you got there.
Feel free to upload your change to github and create a pull request to https://github.com/raspberrypi/linux/ for it to be available for others.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

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