Apalis TK1 - Unable to read GPIO pins via K20

Hi @avionics,

Thanks for the testing. So we now know that updating the bin is not enough, the .ko should be updated as well.

Ok, I will test if I can update the kernel modules alongside the binary, I’ll reply to you when I have something. About the LVDS though, I made a quick search and it appears that it’s possible to make it work on the downstream kernel, not the upstream. You will only need to activate the LVDS on your device tree.

Have you already tried that?

There is a reference on our website: Display Output, Resolution and Timings (Linux)

I’ve also find some tickets about this topic:

Best Regards,

Hello Hiago,

Thank you for the information.
I have some misunderstanding here, please correct me.
The following steps were performed:

  1. Installed on to TK1 module Linux version 5.7.0 build .20 (2022-07-25) Multimedia Image
    which is DOWNSTREAM version, means with support of the device tree

  2. From this website attempting to prepare compilation environment for device tree compilation.
    Reference website page: Build U-Boot and Linux Kernel from Source Code | Toradex Developer Center

I did that already in the past so have understanding of this process.
I have a problem while attempting to download an actual Kernel source for DOWNSTREAM version BSP 5.
From what I see for downstream kernel versions at Toradex github there is only toradex_tk1_l4t_r21.7 which is highest available.
So in my case

git clone -b toradex_tk1_l4t_r21.7 git://git.toradex.com/linux-toradex.git

Question: will that be suitable for device tree compilation of newer BSP 5 which I installed on to my TK1 board ?

If so I guess I just need to download it, modify required dtsi file for display and compile new tegra124-apalis-eval.dtb

Please confirm which branch should I download from toradex github to properly compile BSP 5 device tree.
In the image below you can see that there is no BSP 5 branch available for cloning for TK1 board thus how can I compile device tree ?

Quick update here:
Attempted to compile device tree file from toradex_tk1_l4t_r21.7-next branch, copied it over to TK1 in /boot folder. Board never started again, means compiled file is not correct for BSP5 so this is expected.
I need to get BSP5 for TK1 cloned form git.toradex.com. How can I do that ?
More specifically I want (Linux version 5.7.0 build .20 (2022-07-25) Multimedia Image) source please.
This is downstream version.

Thank you,

Hi @avionics,

One good reference is our release matrix. So if you check the release matrix of Apalis TK1, you will see that the downstream kernel is only available until BSP 3, BSP 5 uses only the mainline kernel (which from the tickets that I shared I can see that it doesn’t support LVDS).

Therefore, the latest BSP for the Nvidia kernel (downstream) is 3.0. You can try to compile a device tree using this version to test if that will work or not for your board. I downloaded the Yocto recipe for BSP 3 and checked the recipe for the linux kernel:

SUMMARY = "Linux Kernel for Toradex Tegra124 based modules"
SECTION = "kernel"

LIC_FILES_CHKSUM = "file://COPYING;md5=d7810fab7487fb0aad327b76f1be7cd7"

inherit kernel siteinfo

LINUX_VERSION ?= "3.10.40"


SRCREV = "063d16eceb570adeb1ae753d73d13f299cefe876"
SRCREV_use-head-next = "${AUTOREV}"

S = "${WORKDIR}/git"
SRCBRANCH = "toradex_tk1_l4t_r21.7"
SRCBRANCH_use-head-next = "toradex_tk1_l4t_r21.7-next"
SRC_URI = "git://git.toradex.com/linux-toradex.git;protocol=git;branch=${SRCBRANCH}"


The branch you tried is correct, but it’s for BSP 3, it won’t work on BSP 5. That’s why your module didn’t boot anymore.

Therefore, to use LVDS, BSP 3 or 2.8 should be used. We only need to make sure that the k20 firmware is working for GPIO as it works for BSP 5. Can you please try to enable the device tree on the LVDS of the BSP 3/2.8 downstream kernel? Also, we can test the k20 firmware to check if it’s working for BSP 3 as well.

Let me know if you need any help with the LVDS device-tree.

Best Regards,

Hello Hiago,

Thank you for the detailed explanations. Yes I now understand more about the branches and releases of different BSPs vs board models and compatibility.

Alright so what I did and what I found so far:

  1. I looked in to BSP3.0 Linux images available and unfortunately both versions offered in Easy Installer (Mainline and Downstream) of BSP3 are command prompt images only, with no graphical interface. This is a problem since we use OpenGL and we absolutely require full graphical support and it is requires GUI interface present in image.

  2. I looked in to legacy image Linux LXDE Image BSP 2.8.7 from 2020-06-10.
    This one is downstream version and also includes GUI interface.
    I choose to install it on one of out TK1 boards. Upon installation it started to work with LVDS by default. This is a very good sign!
    But unfortunately it does not work with GPIO in K20.

What I have in this image is:

dmesg | grep k20

[ 11.925532] apalis-tk1-k20 spi1.1: Apalis TK1 K20 MFD driver. Firmware version 1.4.

So we again have here version 1.4 of K20 firmware which is identical to the one we have in Ubuntu BSP 2.8.
Again no luck here. We now know that both BSP2.8 Linux LXDE image and Ubuntu image support LVDS correctly., However both images includes version 1.4 of K20 firmware and both images does not work with GPIO properly. So it looks like internal additional drivers modification in image is required.

To conclude:
For TK1 board only available BSPs are BSP2.8 LXDE image, BSP2.8 with Ubuntu image and BSP3.0 console only image.
We can utilize only images with GUI due to our requirements of OpenGL.
Can I please ask you to modify image lets say BSP2.8 LXDE and incorporate there proper drivers to support 1.5 version of K20 firmware ? Alternatively Ubuntu BSP2.8 can get same modifications in image.
This will let us use older BSP2.8 with proper LVDS support and also will allow ver1.5 of K20 firmware use.
Please let me know.
Thank you!

Hi @avionics,

After some tests and by reading the source code of the kernel module for the k20, I was able to flash the 1.5 binary and fix the GPIO issue on BSP 2.8 downstream kernel toradex_tk1_l4t_r21.7.

Here is the step-by-step guide:

root@apalis-tk1:~# dmesg | grep k20
[   12.388235] apalis-tk1-k20 spi1.1: Apalis TK1 K20 MFD driver. Firmware version 1.4.
[   12.416345] apalis-tk1-k20-can apalis-tk1-k20-can.0: probed 0
[   12.429787] input: apalis-tk1-k20-ts as /devices/platform/spi-tegra114.1/spi_master/spi1/spi1.1/apalis-tk1-k20-ts/input/input1
[   12.442199] apalis-tk1-k20-can apalis-tk1-k20-can.1: probed 1
  • Copy the 1.5 binary to your module and place it inside /lib/firmware/ (I copied from a USB stick).
root@apalis-tk1:~# cp /media/sda1/apalis-tk1-k20.bin /lib/firmware/
  • Remove the kernel modules responsible for the K20. We’ll need to reload them.
root@apalis-tk1:~# rmmod apalis_tk1_k20_adc apalis_tk1_k20_can apalis_tk1_k20_ts gpio_apalis_tk1_k20
root@apalis-tk1:~# rmmod apalis_tk1_k20
  • Now here is the important part, by checking the source code, I was able to find these two parameters:
static unsigned int fw_ignore = 0;
module_param(fw_ignore , uint, 0);
MODULE_PARM_DESC(fw_ignore, "Assume that K20 is running valid fw version. "
		 "Don't verify, don't erase, don't update");

static unsigned int force_fw_reload = 0;
module_param(force_fw_reload , uint, 0);
MODULE_PARM_DESC(force_fw_reload, "Update K20 fw even when the same version"
		" is already flashed.");

So we can make the driver ignore the firmware we’re loading and also force the firmware update. From my tests, you can’t pass both arguments at the same time. Instead, now run the following command:

root@apalis-tk1:~# modprobe apalis_tk1_k20 force_fw_reload=1
[   94.566330] apalis-tk1-k20 spi1.1: Unsupported firmware version 1.5.
[   94.576066] apalis-tk1-k20: probe of spi1.1 failed with error -524

This will force the reload of the new firmware.

  • Now remove the driver module again and pass the ignore parameter to launch the new firmware. This will force the driver to ignore we’re loading a different version:
root@apalis-tk1:~# rmmod apalis_tk1_k20_adc apalis_tk1_k20_can apalis_tk1_k20_ts gpio_apalis_tk1_k20
root@apalis-tk1:~# rmmod apalis_tk1_k20
root@apalis-tk1:~# modprobe apalis_tk1_k20 fw_ignore=1
[  127.660098] apalis-tk1-k20 spi1.1: fw_ignore == 1. Detected firmware 1.5. Driver expected 1.4
[  127.672542] gpio wake34 for gpio=82
[  127.684604] apalis-tk1-k20 spi1.1: Apalis TK1 K20 MFD driver. Firmware version 1.4.
[  127.753484] input: apalis-tk1-k20-ts as /devices/platform/spi-tegra114.1/spi_master/spi1/spi1.1/apalis-tk1-k20-ts/input/input2
[  127.776547] apalis-tk1-k20-can apalis-tk1-k20-can.0: probed 0
[  127.797811] gpiochip_add: registered GPIOs 856 to 1015 on device: generic
[  127.811795] apalis-tk1-k20-can apalis-tk1-k20-can.1: probed 1

You can see from this line

[  127.660098] apalis-tk1-k20 spi1.1: fw_ignore == 1. Detected firmware 1.5. Driver expected 1.4

that we’re able to launch the new firmware.

Now you should be able to export the GPIO and it should work.

A couple of very important things to mention:

  • If you reboot, it won’t work because you still need to pass the ignore flag. Otherwise it will detect this is a different firmware version and it won’t launch. So in order to add the flag automatically on boot, please create the following file with the option inside:
root@apalis-tk1:~# cat /etc/modprobe.d/apalis-tk1-k20.conf 
options apalis-tk1-k20 fw_ignore=1

Now if you reboot the module, it will load the kernel module with the correct flag.

  • Second and the most important part is that I only tested the GPIO. Please note that we are doing something that is not expected, so please, test everything carefully and make sure everything works. Who made this driver in the past added a bunch of verifications (as we can see) to check the firmware version, so it must be something important. By bypassing them, there is no guarantee that everything will work.

Finally, about your request to fix the BSP 2.8 which is on our feed, I will ask the development team internally. Be aware that this can be rejected by them, because this is an very old image (it uses kernel 3.10, now we are using 6.2) which is an EOL module and is not supported anymore. So I don’t expect any fixes right now, unfortunately. Anyways, I will let you know of any changes.

Hope this helps for now. Let me know if you have any questions and if that works on your side as well, I’ll be happy to help.

Best Regards,

Hi @avionics,

Do you have any updates on this topic?

Let me know if you need anything.

Best Regards,

Hello Hiago,

Sorry for the delay with updates, I am traveling to EU for business at the moment.
I will update once back to my team in Canada.
Thank you for your continuing support on this!

1 Like