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

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

Hello again @frank-w, I could not achieve building the kernel 4.14 with Ubuntu. Hence, XPT2046 screen is not working, the system does not read config.txt for SPI connection. However, I used your GPIO codes from your wiki for blinking leds using java code to integrate our project. Very good information. Moreover, Debian build for Banana-Pi R2 is without interface and it also does not contain config.txt in /boot. Therefore, SPI is not enabled. Also, we can’t try XPT2046 screen in Debian as Debian build starts with terminal. I need to use that touch screen with Banana-Pi. Could you recommend further details about that issue?

Config.txt is raspbian-specific…what do you want to try here? You need to build kernel with changed dta matching the driver for tft. Also my debian/ubuntu are basic images…you have to install xserver + displaymanager by your own. Most users don’t want xserver on router.

I need working SPI connection for using XPT2046 screen. Do you recommend anything else? Could you compile the kernel again and make SPI working in Ubuntu?

as i said multiple times, i cannot build a kernel for a specific spi-device and i cannot test spi except looking if spidev-device comes up because of missing device

add driver-section to dts, add your driver in menuconfig and compile kernel

i take a dts for a display with same driver from beagleboard and modified some positions:

/dts-v1/;
/plugin/;

/ {
	"bananapi,bpi-r2", "mediatek,mt7623";

	/* identification */
	part-number = "BB-ADS7846";
	version = "00A0";

        /* state the resources this cape uses */
        exclusive-use =
                /* the pin header uses */
                "P9.17",        /* SPI0_CS0 */
                "P9.18",        /* SPI0_D1 */
                "P9.21",        /* SPI0_D0 */
                "P9.22",        /* SPI0_SCLK */
                "P9.23";       /* pendown */

	fragment@0 {
		target = <&pio>;
		__overlay__ {
		 ads7846_pins:pinmux_spi0_pins {
				pinctrl-single,pins = <
        	0x150 0x30 /* spi0_sclk, INPUT_PULLUP | MODE0 */
        	0x154 0x10 /* spi0_d0, OUTPUT_PULLUP | MODE0 */
        	0x158 0x30 /* spi0_d1, INPUT_PULLUP | MODE0 */
        	/* For ADS7846 */
	        0x15c 0x10 /* spi0_cs0, OUTPUT_PULLUP | MODE0 */
				>;
			};
		};
};

	fragment@1 {
		target = <&spi0>;
		__overlay__ {
			#address-cells = <0x1>;
	     	        #size-cells = <0>;
			status = "okay";
			pinctrl-names = "default";
			pinctrl-0 = <&ads7846_pins>;/*maybe use spi0_pins_a here and remove fragment@0*/
			ti,pindir-d0-out-d1-in = <1>;
 		    ads7846@0 {
				compatible = "ti,ads7846";
				spi-max-frequency = <100000>;   /* Higher frequency causes more jitter */
				interrupts = <17 0>;             /* pin number 17 and falling edge interrupt */
				interrupt-parent = <&gpio1>;
				pendown-gpio = <&gpio1 17 0>;        /* This corresponds to pin no 23 = GPIO1[17]*/
				reg = <0>;     /* We are using chip select 0, so we enter 0 here */
                #addr-size = <2>;
                #page-size = <32>;

                /* driver defaults */
                ti,x-min = /bits/ 16 <0xB0>;
                ti,y-min = /bits/ 16 <0x231>;
                ti,x-max = /bits/ 16 <0xF49>;
                ti,y-max = /bits/ 16 <0xF6B>;
                ti,pressure-min = /bits/ 16 <0>;
                ti,pressure-max = /bits/ 16 <0xFF>;
                ti,x-plate-ohms = /bits/ 16 <0x96>;
                ti,swap_xy = /bits/ 16 <0>;
                ti,keep_vref_on = /bits/ 16 <0>;
                ti,cs = /bits/ 16 <1>;
    		    linux,wakeup;
	        };
        };
    };
};

here you can try skip the fragment@0 where i don’t know the pin-configuration, but spi0 has already a pin-definition (maybe not there on beagleboard), which is defined this way:

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;
	};
};

i don’t know how to configure gpio inside the spi-driver-part.

and don’t forget driver in menuconfig (ads7846)

@frank-w, thank you again for your detailed information. I finally compiled Ubuntu 4.14 bpi-r2 kernel in Banana Pi R2 with Ubuntu 16.04 system with adding your dts code. Later, I updated grub and grub2. However, the system is still in kernel 4.4.70. I think it’s because of the architecture difference. The architecture is ARMv7, not x86 or x64. How can I boot the system with the new kernel?

One more question, I found out that you compiled Raspbian for Banana-Pi. Your link. XPT2046 touch screen works in Raspbian system in Raspberry. Are SPI and GPIO working in Banana-Pi with your built Raspbian system? Could the screen work in Raspbian in Banana-Pi?

raspian ist not from me…only debian stretch and ubuntu 18.4 from my gdrive

there is no grub…only uboot

after copy kernel+modules to your card you have to say uboot that you warnt to boot this file by changing the kernel-variable in uEnv.txt

Hello @frank-w, I successfully compiled 4.14.108-bpi-r2 kernel using your /dts-v1/ file and I checked monitor settings in menuconfig before compiling in Ubuntu and it works. I reinstalled the driver from link. However, touch still does not working. Moreover, I did not understand where should I insert the code spi0_pins_a: spi@0

banana-kernel

1 Like

You have changed bpi-r2.dts or using my overlay? If using overlay how do you load it? Have you verified dts from linux (sysfs devicetree)?

How do you define the gpio-properties?

@Ryder.Lee can you guide @sanalcem to get spi working?