sbharsha1979
Posts: 6
Joined: Wed Jul 05, 2017 4:42 am

How to write device tree for multiple MAX14830 con to SPI

Wed Jul 05, 2017 5:01 am

Dear All,

My one of the requirement is to have 16 UART ports communication using raspbery pi3, So i have choosen the MAX14830 SPI to quad UART port chip to get the 16 UART ports. I am using 4 MAX14380 Chips to achive this.

For this to get it working on the raspberry pi3 i tried googling around for configuring the multiple MAX14380 device tree, but was not able to get any hints on this.

Let me add clear picture of the hardware what i have to configure.

1. I have 4 - MAX14830 Chips connected to the SPI0 of Raspberry pi3 (GPIO 9,10,11)
2. I have 74HC138D (Demuxer) Which is 3 to 8 Mux lines. The output of this Chip(74HC138D) is connected to all the 4 -
MAX14380 Chip select lines. Input to this is GPIO 23, 7 and 12.

Now using this hardware setup, am not getting how i can add the gpiomux plugin to the device tree. Output of this Mux should be configured as chipselect lines for the MAX14380.

It would be great help if i get some help or pointers on this configuration of multiple MAX14380 in the device tree with Chipselect using the dmux output.

Regards,
Harsha S

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

Re: How to write device tree for multiple MAX14830 con to SP

Wed Jul 05, 2017 1:02 pm

The SPI subsystem allows you to configure any spare GPIO as an extra software chip select, so an easy way forward might be to use GPIOs 8, 7, 12 and 23 as CS/CE0-3. Starting with the spi0-cs overlay (https://github.com/raspberrypi/linux/bl ... verlay.dts) you should just be able to extend the cs-gpios property to contain 4 entries instead of 2:

Code: Select all

cs-gpios = <&gpio 8 1>, <&gpio 7 1>, <&gpio 12 1>, <&gpio 23 1>;
It should then be fairly clear how to declare the additional UARTs in DT (assuming you know how to declare one).

sbharsha1979
Posts: 6
Joined: Wed Jul 05, 2017 4:42 am

Re: How to write device tree for multiple MAX14830 con to SP

Mon Jul 10, 2017 10:37 am

Dear Phil,

To explain bit more, I am using the MAX14830 SPI Device which is connected to the SPI0 of Raspberry PI3. For the Chipselect am using the GPIO pins GPIO12,GPIO13,GPIO23. AS CS0-SC2.

The default overlay for the SPI0-cs-overlay, Modified with
brcm,pins = <8 7>; reaplced with brcm,pins = <12 13 23>;
and
cs-gpios = <&gpio 8 1>, <&gpio 7 1>; replaced with cs-gpios = <&gpio 12 1>, <&gpio 13 1>, <&gpio 23 1>;

Apart from this Have added one more overlay for the MAX14380 to populate the ttyMAX0-3 Device of UART in /dev

Code: Select all

/dts-v1/;
/plugin/;

/ {
        compatible = "brcm,bcm2708";

        [email protected] {
                target = <&spi0>;
                __overlay__ {
                        /* needed to avoid dtc warning */
                        #address-cells = <1>;
                        #size-cells = <0>;
                        status = "okay";
                        max14830: [email protected] {
                                compatible = "maxim,max14830";
                                reg = <0>; /* CE0 */
                                clocks = <0x41>;
                                clock-names = "osc";
                                spi-max-frequency = <12000000>;
                                status = "okay";
                        };
                };
        };

        [email protected] {
                target = <&gpio>;
                __overlay__ {
                        max14830_pins: max_14830_pins {
                                brcm,pins = <4>;
                                brcm,function = <0>; /* in */
                                brcm,pull = <0>; /* none */
                        };
                };
        };

        __overrides__ {
                int_pin = <&max14830>, "interrupts:0",
                          <&max14830_pins>, "brcm,pins:0";
                speed   = <&max14830>, "spi-max-frequency:0";
        };
};
After booting the raspberry PI, I am trying to load the Overlay method MAX14830. But am unable to get the ttyMAX0-3 dev interfaces.

When i load the overlay device tree am getting nothing in dmesg. When i load one more time am getting
"
[ 283.221234] device-tree: Duplicate name in [email protected], renamed to "[email protected]#1"
[ 283.221424] spi-bcm2835 3f204000.spi: chipselect 0 already in use
[ 283.221431] spi_master spi0: spi_device register error /soc/[email protected]/[email protected]
[ 283.221439] of_spi_notify: failed to create for '/soc/[email protected]/[email protected]'
[ 283.221444] __of_changeset_entry_notify: notifier error @/soc/[email protected]/[email protected]
"

It would be great if some one can help me in getting the correct device tree for putting MAX14830 over SPI.

My hardware setup :
SPI0 connected to the MAX14830
Chipselect : GPIO12,GPIO13,GPIO23 (Using it as Cs0-CS2, For multiple Device selection)
IRQ line to MAX14830 : GPIO5

Please can suggest a what wrong i am doing in adding the overlay method for MAX14830. It would be great if i get some template for adding the MAX14830 Device on SPI0. that would really help me to resolve first issue.

Harsha S

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

Re: How to write device tree for multiple MAX14830 con to SP

Mon Jul 10, 2017 10:55 am

Loading an overlay multiple times will cause name collisions and the error messages you saw.

Your overlay doesn't include a fragment to disable the [email protected] node, like this:

Code: Select all

	[email protected] {
		target = <&spidev0>;
		__overlay__ {
			status = "disabled";
		};
	};
Without this the spidev driver will claim CS0 of SPI0.

You also need to ensure that the driver module exists. Support for the MAX14830 is provided by the MAX310X driver, which is only built when CONFIG_SERIAL_MAX310X is set to "y" or "m". Neither bcmrpi_defconfig nor bcm2710_defconfig set this option, so the driver is not included in standard Pi kernel packages.

sbharsha1979
Posts: 6
Joined: Wed Jul 05, 2017 4:42 am

Re: How to write device tree for multiple MAX14830 con to SP

Wed Jul 12, 2017 5:00 am

Dear PhileE,

Thank you for the support.

Yes, Some steps i have missed it during the last post. Corrected all below steps. Still facing the issue with MAX14830. Getting this message when i load the overlay. with this command > sudo /opt/vc/bin/dtoverlay max14830
"[ 47.181182] max310x spi0.0: MAX14830 ID 0x00 does not match"

Now to make it work with simple connections, i have updated my hardware as below

I have connected the single -- MAX14830 to SPI0
Connected the CS0 (GPIO8) to CS0 of MAX14830.(Using the default CS0 of SPI0 to MAX14830).
I have built the max310x driver and included in the kernel.

I have added 3 dts overlay files to enable the MAX14830 over SPI. Please see if i am doing any mistake or mishandled any settings.

Code: Select all

/* spidevoff.dts -- Turning of SPI0 and SPI1 dev entries*/
/dts-v1/;
/plugin/;
/{
        compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
        [email protected] {
                target = <&spidev0>;
                __overlay__{
                        status = "disabled";
                };
        };
        [email protected] {
                target = <&spidev1>;
                __overlay__ {
                        status = "disabled";
                };
        };
};

Code: Select all

/*MAX Clock settings : max14830-clock.dts*/
/dts-v1/;
/plugin/;

/{
        compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
        [email protected] {
                target = <&clocks>;
                __overlay__{
                        #address-cells = <1>;
                        #size-cells = <0>;
                        xtal:[email protected] {
                                reg = <0x7>;
                                #clock-cells = <0>;
                                compatible = "fixed-clock";
                                clock-frequency = <3686400>;
                                clock-output-names = "xtal";
                        };
                };
        };
};

Code: Select all

/* MAx14830.dts to load the MAX14830 driver as spi0*/
/dts-v1/;
/plugin/;
/{
        compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
        [email protected] {
                target = <&spi0>;
                __overlay__{
                        /* Needed to avoid dtc warning */
                        #address-cells = <1>;
                        #size-cells = <0>;
                        status = "okay";

                        max14830_1: [email protected] {
                                compatible = "maxim,max14830";
                                reg = <0>;
                                mode = <0>;
                                clocks = <0x4b>;
                                clock-names = "xtal";
                                spi-max-frequency =  <12000000>;
                                interrupt-parent = <&gpio>;
                                interrupts = <0x5 0x2>; /*GPIO5 IRQ from MAX14830*/
                                status = "okay";
                                gpio-controller;
                                #gpio-cells = <2>;
                        };
                };
        };
        [email protected]{
                target = <&gpio>;
                __overlay__{
                        max14830_pins: max_14830_pins{
                                brcm,pins = <4>;
                                brcm,function = <0>; /*in*/
                                brcm,pull = <0>; /*none */
                        };
                };
        };

        __overrides__{
                int_pin = <&max14830_1>,"interrupts:0",
                        <&max14830_pins>, "brcm,pins:0";
                speed = <&max14830_1>, "spi-max-frequency:0";
        };
};
Not sure what am still missing from this. Please can suggest if i am missing anything in this.

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

Re: How to write device tree for multiple MAX14830 con to SP

Wed Jul 12, 2017 8:41 am

Having tried myself with your overlays I think you must already be loading the clock overlay from config.txt, otherwise you would be getting a different error. Since I don't have the MAX14830 hardware I tried with nothing attached and got exactly the same error as you - without a real device attached any read returns zeroes, and there is no way for the driver to tell the difference - so I suspect your wiring is wrong in some way. With another SPI device attached (an RFID reader) I see a different (but still wrong) ID value - not surprising, since the register map is different.

sbharsha1979
Posts: 6
Joined: Wed Jul 05, 2017 4:42 am

Re: How to write device tree for multiple MAX14830 con to SP

Thu Jul 13, 2017 5:05 am

Dear PhilE,

Thats correct, I am loading the max clock dtbo in config.txt.

checked my hardware connections. All seems to be fine. Now i have just connected 1 MAX14830 to SPI0. When i try yo load the overlay method It says different a bit. ID shown as 0x0F Rather than earlier 0x00.

[ 27.866623] max310x spi0.0: MAX14830 ID 0x0f does not match

Just wanted to check one more thing on this. The MAX14830 has fallowing pins.
MISO -- SPI0 MISO
MOSI -- SPI0 MOSI
MSCK -- SPI0 CLK
CS0 -- CS0 (GPIO 8)
IRQ -- GPIO 5
RST. -- Switch.

Now in this I have configured the interrupts as 0x05 0x02 Does this make any issues here ?
Default SPI0 has 2 Chipselect CS0 and CS1, Since i am using only CS0, should we disable the CS1 ? If so how can we do it.

Harsha S

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

Re: How to write device tree for multiple MAX14830 con to SP

Thu Jul 13, 2017 10:26 am

Unused chip selects are harmless - they are just output signals.

I'm still suspicious about the electrical integrity of your hardware and the wiring. I've seen so many people struggle to get an MFRC522 RFID reader to work that I wrote a simple app that just reads all the registers - you can download it here: https://gist.github.com/pelwell/e667bc7 ... 91f6411db9

There are a few things to note:
1. It will try to drive GPIO 22 as a reset signal - you can change that to suit, or comment out all lines containing NRSTPD.
2. It uses /dev/spidev0, so don't load any of your overlays.

Thinking about the reset line, are you sure you are driving the MAX14830's reset correctly? The device will need a clear reset after the power supply has stabilised - don't rely on it having a good power-on reset circuit.

sbharsha1979
Posts: 6
Joined: Wed Jul 05, 2017 4:42 am

Re: How to write device tree for multiple MAX14830 con to SP

Mon Jul 17, 2017 11:09 am

Hi PhilE,

I tried to isolate the hardware and connected only 1 MAX14830 to the SPI-0. Since the MAX is REVID is 0xB4, Changed the driver accordingly, as earlier driver supported till RevID of 0xB1 and 0xB2. So Now the Device is getting detected. Facing some issue with respect to IRQ.

[ 44.214640] spi0.0: ttyMAX0 at I/O 0x0 (irq = 0, base_baud = 230400) is a MAX14830
[ 44.214904] spi0.0: ttyMAX1 at I/O 0x20 (irq = 0, base_baud = 230400) is a MAX14830
[ 44.215098] spi0.0: ttyMAX2 at I/O 0x40 (irq = 0, base_baud = 230400) is a MAX14830
[ 44.215330] spi0.0: ttyMAX3 at I/O 0x60 (irq = 0, base_baud = 230400) is a MAX14830
[ 44.215544] max310x spi0.0: Unable to reguest IRQ 0
[ 44.216388] max310x: probe of spi0.0 failed with error -22

Am using the IRQ line as GPIO 4.
Any suggestion why this error would occur ?

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

Re: How to write device tree for multiple MAX14830 con to SP

Mon Jul 17, 2017 12:50 pm

I can't see why that isn't working for you. By analogy to the sc16is7xx driver (derived from the max310x driver) and its overlay you seem to be doing the right things. I have just noticed that you have a hard-coded phandle (0x4b) in your overlay instead of using a symbol reference, presumably because you haven't figured out how to export a symbol from an overlay (see the i2c-gpio overlay for an example of how you can do this), but that shouldn't be causing this problem.

What happens if you change the requested IRQ pin from 4 to something else - does it always try to request zero?

sbharsha1979
Posts: 6
Joined: Wed Jul 05, 2017 4:42 am

Re: How to write device tree for multiple MAX14830 con to SP

Mon Jul 17, 2017 2:18 pm

Hi PhilE,

I tried Changing the IRQ Pins( 5 or 21 etc) , but the result is same. Will try out some other GPIO's and see if anything it resolves.
As per my uderstaning, the MAX driver will pick the IRQ line from the device tree, is it correct ?

I wanted to try out one more thing is to hard code the interrupt line in the MAX driver and try out, Which am yet to try out.

Harsha S

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

Re: How to write device tree for multiple MAX14830 con to SP

Mon Jul 17, 2017 2:21 pm

As per my uderstaning, the MAX driver will pick the IRQ line from the device tree, is it correct ?
Almost - the SPI framework is supposed to read the "interrupts" property and make it available as the "irq" field of the spi_device structure passed to the probe function.

mdharris
Posts: 2
Joined: Sat May 13, 2017 6:25 am

Re: How to write device tree for multiple MAX14830 con to SPI

Fri Jan 11, 2019 1:55 pm

Hi PhilE,
I am trying to load the max310x.ko, in "dmesg I am getting " max310x: loading out-of-tree module taints kernel." ERROR. Then When I give the following command /opt/vc/bin/dtoverlay max14830, the output in dmesg is

OF: /soc/[email protected]/[email protected]: could not get #clock-cells for /soc/[email protected]/spi2_gpio40
ERROR: could not get clock /soc/[email protected]/[email protected]:xtal(0)
max310x spi0.0: Cannot get clock
max310x: probe of spi0.0 failed with error -22

I am using the same device-tree file which it is given above.What is going wrong,please help.
Also in the config.txt what I should write?.
Hardware "Raspberry pi 2(BCM2709)"
Software "2018-06-27-raspbian-stretch-lite.img"
Kernel "4.14.79-v7+"

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

Re: How to write device tree for multiple MAX14830 con to SPI

Fri Jan 11, 2019 2:39 pm

Please upload (to pastebin, etc.) your config.txt and the source of the overlay you are using.


Return to “Device Tree”