SPI touchscreen ads7846 (xpt2046) on UBUNTU images (BPI-R2)

Hello all,

For the life of me, I cannot find a single tutorial that would show how to set up an ads7846/xpt2046 touchscreen (over spi) while using an ubuntu system image.

There are plenty of tutorials that show how to enable various touchscreen variants that use the ads7846 drivers, both on rpi and bpi:

https://www.raspberrypi.org/forums/viewtopic.php?t=175616#p1120534 https://www.raspberrypi.org/forums/viewtopic.php?t=178443

however, all of them are geared towards raspbian. They show necessary editing of /boot/config.txt but there is no such file in the ubuntu images (or using raspi-config which is also unavailable on ubuntu) .

NOTE: i just need to enable the resistive touchscreen over spi, the screen itself is connected over hdmi. For reference, I am interested in connecting this screen: https://www.raspberrypi.org/forums/viewtopic.php?t=175616

I would be extremely grateful if anyone could provide me a proper tutorial on enabling an spi touchscreen on BPI-R2 with ubuntu.

As said here

You need to build kernel with spi-module and activate spi-node in dts-file except you have to use 4.4 because hdmi is not working in 4.14 yet

Thanks for the info. Is there per chance a more in depth explanation on how to achieve what i’m looking for? I managed to compile and run the bpi-r2-bsp source (kernel 4.4) on ubuntu 16.04.

i managed to find the dts file (this is from the kernel 4.4 source) ./linux-mt/arch/arm/boot/dts/mt7623n-bpi-r2.dts what am i supposed to edit over here? Surely I can’t just take the one linked in the other post, that one is for kernel version 4.14?

Sorry, this is my first time dealing with changing something in the kernel source.

you have a mt7623.dtsi (basic declarations) and then a dts (you’ve found the right for your kernel :wink: it’s only different name)

first the node itself must exist in the dtsi, if it isn’t there you can copy declaration from 4.14 for the spi to 4.4…then enable it in dts-file and compile. if there any references (&xx) the corresponding node must also exist (spi0_pins_a inside of &pio in dts)

Sorry, this really doesn’t clear any confusion for me :smiley: Where can i find some info about actually using and modifying these dts files?

Also, i am unable to compile the 4.4 kernel from your git:

make[1]: Entering directory ‘/home/toby/Documents/LIME/BPI-R2-4.4/linux-mt’ drivers/net/wireless/mediatek/Kconfig:10: can’t open file “drivers/net/wireless/mediatek/mt76/Kconfig”

this is from the main branch.

trying to paste the bananapi-bpi-r2.dts from 4.14 to 4.4 (from the BSP git) also does not work, make just gives a parsing error for the dts file while building

using the pre-built 4.14.14 from the google drive link results in pi not booting

here spi0 exists:

spi0: spi@1100a000 {
        compatible = "mediatek,mt7623-spi",
                     "mediatek,mt2701-spi";
        #address-cells = <1>;
        #size-cells = <0>;
        reg = <0 0x1100a000 0 0x100>;
        interrupts = <GIC_SPI 78 IRQ_TYPE_LEVEL_LOW>;
        clocks = <&topckgen CLK_TOP_SYSPLL3_D2>,
                 <&topckgen CLK_TOP_SPI0_SEL>,
                 <&pericfg CLK_PERI_SPI0>;
        clock-names = "parent-clk", "sel-clk", "spi-clk";
        status = "disabled"; //<<<<<<<<<<<<<<<<< status disabled
};

here you can try to enable the spi using:

&spi0 {
	//pinctrl-names = "default";
	//pinctrl-0 = <&spi0_pins_a>;
	status = "okay";
};

but maybe you need also the pinctrl (i currently commented out with // ), then you search for the &pio-block and add this

spi0_pins_a: spi@0 {
	pins_spi {
		pinmux = <MT7623_PIN_53_SPI0_CSN_FUNC_SPI0_CS>,
			<MT7623_PIN_54_SPI0_CK_FUNC_SPI0_CK>,
			<MT7623_PIN_55_SPI0_MI_FUNC_SPI0_MI>,
			<MT7623_PIN_56_SPI0_MO_FUNC_SPI0_MO>;
		bias-disable;
	};
};

like it’s done here:

hope now it’s clear enough

the error came from git submodule which seems not to be updated in your clone…as you don’t need that module, you can disable it in your config ./build.sh and choosing 4 for menuconfig and disabkle it

  │ Symbol: MT76 [=m]                                                       │  
  │ Type  : tristate                                                        │  
  │ Prompt: MediaTek MT76x2 802.11ac chips support                          │  
  │   Location:                                                             │  
  │     -> Device Drivers                                                   │  
  │       -> Network device support (NETDEVICES [=y])                       │  
  │         -> Wireless LAN (WLAN [=y])                                     │  
  │ (1)       -> Mediatek Wireless LAN support (WL_MEDIATEK [=y])  

or commenting out “CONFIG_MT76=m” (with #) in linux-mt/arch/arm/configs/mt7623n_evb_bpi_defconfig

I have now removed submodule and added files direct to repo to avoid such problems, git pull to update

tried to find spi-dev in 4.14:

root@bpi-r2:~# find /sys/ -iname '*spi*'                                        
/sys/kernel/debug/clk/spi0_sel                                                  
/sys/kernel/debug/clk/pmicspi_sel                                               
/sys/kernel/debug/clk/spi2_sel                                                  
/sys/kernel/debug/clk/spi1_sel                                                  
/sys/kernel/debug/clk/pmicspi_ck                                                
/sys/kernel/debug/clk/spi0_ck                                                   
/sys/kernel/debug/clk/spi2_ck                                                   
/sys/kernel/debug/clk/spi1_ck                                                   
/sys/kernel/debug/clk/host89_spi_ck                                             
/sys/kernel/debug/tracing/events/spi                                            
/sys/kernel/debug/tracing/events/spi/spi_controller_idle                        
/sys/kernel/debug/tracing/events/spi/spi_controller_busy                        
/sys/kernel/debug/tracing/events/spi/spi_message_submit                         
/sys/kernel/debug/tracing/events/spi/spi_message_start                          
/sys/kernel/debug/tracing/events/spi/spi_message_done                           
/sys/kernel/debug/tracing/events/spi/spi_transfer_start                         
/sys/kernel/debug/tracing/events/spi/spi_transfer_stop                          
/sys/devices/platform/1100a000.spi                                              
/sys/class/spi_master                                                           
/sys/firmware/devicetree/base/spi@1100a000                                      
/sys/firmware/devicetree/base/spi@11017000                                      
/sys/firmware/devicetree/base/spi@11016000                                      
/sys/firmware/devicetree/base/pinctrl@10005000/spi@0                            
/sys/firmware/devicetree/base/pinctrl@10005000/spi@0/pins_spi                   
/sys/bus/platform/devices/1100a000.spi                                          
/sys/bus/spi                           

currently i don’t know which is the right device…found nothing in /dev, but maybe its different to 4.4

maybe CONFIG_SPI_SPIDEV must be set in Kernel…

1 Like

Well, i sort of understand what has to be done. I’m not sure if i can make it work, but i will keep you posted. Thanks again for your help :)))

I have made steps which you wrote and build kernel again. The sys outputs are following;

  sudo find /sys/ -iname '*spi*' 
    [sudo] password for pi: 
    /sys/bus/spi
    /sys/bus/spi/drivers/spidev
    /sys/bus/platform/devices/1100a000.spi
    /sys/bus/platform/drivers/spi_gpio
    /sys/bus/platform/drivers/mtk-spi
    /sys/bus/platform/drivers/mtk-spi/1100a000.spi
    /sys/devices/platform/1100a000.spi
    /sys/devices/platform/1100a000.spi/spi_master
    /sys/devices/platform/1100a000.spi/spi_master/spi32766
    /sys/devices/platform/1100a000.spi/spi_master/spi32766/statistics/spi_sync_immediate
    /sys/devices/platform/1100a000.spi/spi_master/spi32766/statistics/spi_sync
    /sys/devices/platform/1100a000.spi/spi_master/spi32766/statistics/spi_async
    /sys/class/spi_master
    /sys/class/spi_master/spi32766
    /sys/class/spidev
    /sys/firmware/devicetree/base/spi@1100a000
    /sys/firmware/devicetree/base/pinctrl@10005000/spi@0
    /sys/firmware/devicetree/base/pinctrl@10005000/spi@0/pins_spi
    /sys/kernel/debug/clk/spi0_sel
    /sys/kernel/debug/clk/pmicspi_sel
    /sys/kernel/debug/clk/spi2_sel
    /sys/kernel/debug/clk/spi1_sel
    /sys/kernel/debug/clk/pmicspi_ck
    /sys/kernel/debug/clk/spi0_ck
    /sys/kernel/debug/clk/spi2_ck
    /sys/kernel/debug/clk/spi1_ck
    /sys/kernel/debug/clk/host89_spi_ck
    /sys/kernel/debug/tracing/events/spi
    /sys/kernel/debug/tracing/events/spi/spi_master_idle
    /sys/kernel/debug/tracing/events/spi/spi_master_busy
    /sys/kernel/debug/tracing/events/spi/spi_message_submit
    /sys/kernel/debug/tracing/events/spi/spi_message_start
    /sys/kernel/debug/tracing/events/spi/spi_message_done
    /sys/kernel/debug/tracing/events/spi/spi_transfer_start
    /sys/kernel/debug/tracing/events/spi/spi_transfer_stop
    /sys/module/spidev

But, I still don’t see /dev/spidev0.0. Have you an idea?

CONFIG_SPI_SPIDEV set in kernel-config? And loaded if build as module?

I have activated from ./build.sh menuconfig Device Driver -> SPI Support -> User Mode SPI device driver support and all of the spı controller supports… You mean these supports. Right?

Right, user mode driver should be spidev…have you buildtin (*) or module (m)?

Maybe there is a lack of driver-support…nearly the half of bpi-r2 is currently supported. For some features are patches for 4.15,but i did not seen anything for spi yet…but also not focused on it

Maybe gary or someone from bpi-team can say whats missing

I have builtin spidev with (*) not (M)…

Thanks for infos Frank.

@Toby SPI-device is working see here BPI-R2 SPI Communication maybe now you have more luck to get your touchscreen working

Please see below for details:

@frank-w; we bought XPT2046 5" TFT screen and I tried to build your kernel on your GitHub repository, but I could not succeed. We have Banana-Pi R2 for sure. It says that I should not use administrator account. After the kernel configuration and while the kernel is building, it gives errors. Do you have a precompiled Ubuntu image for Banana-Pi R2 with SPI working? Moreover, I found out that your kernel includes working SPI configuration. Is that right? Furthermore, could I use XPT2046 via only SPI (via GPIO)? The screen has HDMI and micro usb inputs. Couldn’t we pass data via usb? Or could we use only SPI (via GPIO)?

I cannot test spi because i have no spi-device. Imho you nedd to define driver in dts so you have to do it for yourself.

Please make crosscompile and not on r2 directly. I have accepted a patch for direct compile but i don’t use it and don’t want to give support for this.

You can try hdmi…imho usb should be only for touch-function

I have one more question @frank-w, are you working on building Bananian Linux for Banana R2? Moreover, I have a question for BPI company, when companies sell computers, they build a good OS for that computer. Won’t you build a stable OS for Banana-Pi R2? I need answers.

Bananian was a special debian…i have a basic debian-image for r2 on my gdrive…only kernel-updates can’t be installed via apt

Bananian itself is dead because there is a official armhf port of debian.

Did you build SPI interface and XPT2046 screen drivers in your Debian build?

As i said before display has to be defined in dts (maybe dto,needs no kernel-rebuild but difficulter to setup). System is a basic system without any special configuration except network. You can install which is available on official debian repo. For Kernel download my repo and activate drivers you need

Try to get it working with modified dts and then i make a dto and add driver-module