freefish
Posts: 21
Joined: Mon Apr 01, 2013 2:02 am

(need help)stmpe610-i2c over i2c-gpio

Thu Jun 02, 2016 2:16 pm

I want to use stmpe610 on i2c-gpio interface(/dev/i2c-3)

I found a solution in this post
/viewtopic.php?f=107&t=148572&p=978332

Code: Select all

/dts-v1/;
/plugin/;

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

        [email protected] {
                target = <&i2c1>;
                __overlay__ {
                        compatible = "brcm,bcm2708-i2c";
                };
        };

        [email protected] {
                target = <&gpio>;
                __overlay__ {
                        stmpe610_pins: stmpe610_pins {
                                brcm,pins = <23>;
                                brcm,function = <0>; /* in */
                                /*brcm,pull = <2 0>; / * pullup none */
                        };
                };
        };

        [email protected] {
                target = <&i2c1>;
                __overlay__ {
                        /* needed to avoid dtc warning */
                        #address-cells = <1>;
                        #size-cells = <0>;
                        status = "okay";

                        [email protected] {
                                #address-cells = <1>;
                                #size-cells = <0>;
                                compatible = "st,stmpe610";
                                reg = <0x41>;

                                irq-gpio = <&gpio 23 0x2>; /* IRQF_TRIGGER_FALLING */
                                interrupts = <23 0x2>; /* high-to-low edge triggered */
                                interrupt-parent = <&gpio>;
                                interrupt-controller;

                                stmpe_touchscreen {
                                        compatible = "st,stmpe-ts";
                                        st,sample-time = <4>;
                                        st,mod-12b = <1>;
                                        st,ref-sel = <0>;
                                        st,adc-freq = <2>;
                                        st,ave-ctrl = <3>;
                                        st,touch-det-delay = <4>;
                                        st,settling = <2>;
                                        st,fraction-z = <7>;
                                        st,i-drive = <0>;
                                };
                        };
                };
        };
};

Someone help me rewrite this DTS file to use I2C-GPIO(/dev/i2c-3) Interface ?

freefish
Posts: 21
Joined: Mon Apr 01, 2013 2:02 am

Re: (solved)stmpe610-i2c over i2c-gpio

Fri Jun 03, 2016 10:38 am

Code: Select all

/dts-v1/;
/plugin/;

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

        [email protected] {
                target = <&i2c_gpio>;
                __overlay__ {
                        compatible = "i2c-gpio";
                };
        };

        [email protected] {
                target = <&gpio>;
                __overlay__ {
                        stmpe610_pins: stmpe610_pins {
                                brcm,pins = <25>;
                                brcm,function = <0>; /* in */
                                /*brcm,pull = <2 0>; / * pullup none */
                        };
                };
        };

        [email protected] {
                target = <&i2c_gpio>;
                __overlay__ {
                        /* needed to avoid dtc warning */
                        #address-cells = <1>;
                        #size-cells = <0>;
                        status = "okay";

                        [email protected] {
                                #address-cells = <1>;
                                #size-cells = <0>;
                                compatible = "st,stmpe610";
                                reg = <0x41>;

                                irq-gpio = <&gpio 25 0x2>; /* IRQF_TRIGGER_FALLING */
                                interrupts = <25 0x2>; /* high-to-low edge triggered */
                                interrupt-parent = <&gpio>;
                                interrupt-controller;

                                stmpe_touchscreen {
                                        compatible = "st,stmpe-ts";
                                        st,sample-time = <4>;
                                        st,mod-12b = <1>;
                                        st,ref-sel = <0>;
                                        st,adc-freq = <2>;
                                        st,ave-ctrl = <3>;
                                        st,touch-det-delay = <4>;
                                        st,settling = <2>;
                                        st,fraction-z = <7>;
                                        st,i-drive = <0>;
                                };
                        };
                };
        };
};
this is my stmpe610.dts file
I compiled it with
dtc [email protected] -I dts -O dtb -o stmpe610.dtbo stmpe610.dts

Code: Select all

[email protected]:/boot/overlays $ sudo dtc [email protected] -I dts -O dtb -o stmpe610.dtbo stmpe610.dts
Warning (unit_address_vs_reg): Node /[email protected] has a unit name, but no reg property
Warning (unit_address_vs_reg): Node /[email protected] has a unit name, but no reg property
Warning (unit_address_vs_reg): Node /[email protected] has a unit name, but no reg property
[email protected]:/boot/overlays $
sudo dtoverlay stmpe610.dtbo
* Failed to apply overlay '0_stmpe610'

dmesg
[37251.777413] of_resolve_phandles: Could not find symbol 'i2c_gpio'
[37251.777441] create_overlay: Failed to resolve tree
Last edited by freefish on Sun Jun 05, 2016 2:37 am, edited 1 time in total.

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

Re: (need help)stmpe610-i2c over i2c-gpio

Fri Jun 03, 2016 7:19 pm

That overlay is a bit confused - it's presumably trying to create an i2c-gpio node, but it's referring to it as if it is already there. Take a look at the existing i2c-gpio overlay (https://github.com/raspberrypi/linux/bl ... verlay.dts) to see how it should be created.

If you are loading the i2c-gpio and expecting it to be accessible to other overlays then it won't be. You have to go to certain lengths to make that possible.

If I2C were a point-to-point link then I would recommend creating a dedicated instance of i2c-gpio for your touchscreen, but since it is a bus that could have other devices hung off it then I think it would be better to get i2c-gpio to make itself available to other overlays.

You can have a go by patching arch/arm/boot/dts/overlays/i2c-gpio-overlay.dts like this:

Code: Select all

diff --git a/arch/arm/boot/dts/overlays/i2c-gpio-overlay.dts 
index 2a2dc98..b72b32e 100644                                
--- a/arch/arm/boot/dts/overlays/i2c-gpio-overlay.dts        
+++ b/arch/arm/boot/dts/overlays/i2c-gpio-overlay.dts        
@@ -19,6 +19,21 @@                                           
                        };                                   
                };                                           
        };                                                   
+                                                            
+       [email protected] {                                         
+               target-path = "/aliases";                    
+               __overlay__ {                                
+                       i2c_gpio = "/[email protected]";                 
+               };                                           
+       };                                                   
+                                                            
+       [email protected] {                                         
+               target-path = "/__symbols__";                
+               __overlay__ {                                
+                       i2c_gpio = "/[email protected]";                 
+               };                                           
+       };                                                   
+                                                            
        __overrides__ {                                      
                i2c_gpio_sda = <&i2c_gpio>,"gpios:4";        
                i2c_gpio_scl = <&i2c_gpio>,"gpios:16";       
and using this as your stmpe610 overlay:

Code: Select all

/dts-v1/;
/plugin/;

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

        [email protected] {
                target = <&gpio>;
                __overlay__ {
                        stmpe610_pins: stmpe610_pins {
                                brcm,pins = <25>;
                                brcm,function = <0>; /* in */
                                /*brcm,pull = <2 0>; / * pullup none */
                        };
                };
        };

        [email protected] {
                target = <&i2c_gpio>;
                __overlay__ {
                        /* needed to avoid dtc warning */
                        #address-cells = <1>;
                        #size-cells = <0>;
                        status = "okay";

                        stmpe610: [email protected] {
                                #address-cells = <1>;
                                #size-cells = <0>;
                                compatible = "st,stmpe610";
                                reg = <0x41>;

                                irq-gpio = <&gpio 25 0x2>; /* IRQF_TRIGGER_FALLING */
                                interrupts = <23 0x2>; /* high-to-low edge triggered */
                                interrupt-parent = <&gpio>;
                                interrupt-controller;

                                stmpe_touchscreen {
                                        compatible = "st,stmpe-ts";
                                        st,sample-time = <4>;
                                        st,mod-12b = <1>;
                                        st,ref-sel = <0>;
                                        st,adc-freq = <2>;
                                        st,ave-ctrl = <3>;
                                        st,touch-det-delay = <4>;
                                        st,settling = <2>;
                                        st,fraction-z = <7>;
                                        st,i-drive = <0>;
                                };
                        };
                };
        };

        __overrides__ {
                irq_pin = <&stmpe610>, "irq-gpio:4",
                          <&stmpe610_pins>, "brcm,pins:0";
        };
};
I've tested this as far as verifying that it appears to do the right thing using dtmerge, but I haven't tried it on real hardware.

Note that I've moved the default irq_pin to 25 so as not to clash with the default i2c-gpio pins.

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

Re: (need help)stmpe610-i2c over i2c-gpio

Fri Jun 03, 2016 7:20 pm

P.S. If this works for you then I'll patch the standard i2c-gpio overlay in the same way.

freefish
Posts: 21
Joined: Mon Apr 01, 2013 2:02 am

Re: (need help)stmpe610-i2c over i2c-gpio

Sat Jun 04, 2016 2:40 am

Yes! It works! Thank you very much!
[email protected]:~ $ dmesg | grep stmpe
[ 6.566124] stmpe-i2c 3-0041: stmpe610 detected, chip id: 0x811
[ 7.177145] input: stmpe-ts as /devices/platform/[email protected]/i2c-3/3-0041/stmpe-ts/input/input4
[email protected]:~ $ sudo evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0: Logitech USB Receiver
/dev/input/event1: Logitech USB Receiver
/dev/input/event2: gpio_ir_recv
/dev/input/event3: MCE IR Keyboard/Mouse (gpio-rc-recv)
/dev/input/event4: stmpe-ts
Select the device event number [0-4]:

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

Re: (need help)stmpe610-i2c over i2c-gpio

Mon Jun 06, 2016 8:34 am

I've pushed the amended i2c-gpio overlay into the rpi-4.4.y source tree; it will be included in subsequent releases.

Return to “Device Tree”