0

I want to build a CEC Debugger as described in the Kernel.org documentation with my Pi Zero 2 W, I plan on using something like this:

HDMI Pass Through Breakout Board

I am having trouble with the final instructions listed to enable the cec-gpio device tree overlay. The instructions are as follows:

This kernel patch will hook up the cec-gpio driver correctly to e.g. arch/arm/boot/dts/bcm2837-rpi-3-b-plus.dts:

cec-gpio@7 {
        compatible = "cec-gpio";
        cec-gpios = <&gpio 7 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
        hpd-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;
        v5-gpios = <&gpio 22 GPIO_ACTIVE_HIGH>;
};

cec-gpio@8 {
        compatible = "cec-gpio";
        cec-gpios = <&gpio 8 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
        hpd-gpios = <&gpio 27 GPIO_ACTIVE_HIGH>;
        v5-gpios = <&gpio 24 GPIO_ACTIVE_HIGH>;
};

This dts change will enable two cec GPIO devices: I typically use one to send/receive CEC commands and the other to monitor. If you monitor using an unconfigured CEC adapter then it will use GPIO interrupts which makes monitoring very accurate.

I am unfamiliar with dts files but I have managed to create one, built it and copied it to /boot/overlays:

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>

/ {
        compatible = "brcm,bcm2835";

        fragment@0 {
                target-path = "/";
                __overlay__ {
                        cec-gpio@7 {
                                compatible = "cec-gpio";
                                cec-gpios = <&gpio 7 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
                                hpd-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;
                                v5-gpios = <&gpio 22 GPIO_ACTIVE_HIGH>;
                        };
                };
        };
};

I have updated my /boot/config.txt to include this overlay last and there appear to be no errors. I can see something when I run:

> sudo ls -R /sys | grep cec
cec
/sys/bus/cec:
/sys/bus/cec/devices:
cec0
/sys/bus/cec/drivers:
cec-gpio@7
platform:20200000.gpio--platform:cec-gpio@7
cec-gpio@7
/sys/devices/platform/cec-gpio@7:
/sys/devices/platform/cec-gpio@7/power:
consumer:platform:cec-gpio@7
cec0
/sys/devices/platform/soc/20902000.hdmi/cec0:
/sys/devices/platform/soc/20902000.hdmi/cec0/power:
platform:20200000.gpio--platform:cec-gpio@7
/sys/devices/virtual/devlink/platform:20200000.gpio--platform:cec-gpio@7:
cec-gpio@7
/sys/firmware/devicetree/base/cec-gpio@7:
cec-gpios
cec
/sys/kernel/debug/cec:
cec0
/sys/kernel/debug/cec/cec0:
cec
/sys/module/cec:
/sys/module/cec/holders:
/sys/module/cec/notes:
/sys/module/cec/parameters:
/sys/module/cec/sections:

But from this output and from running ls /dev/cec* I can only see 1 CEC device: the inital HDMI port.

What steps can I take to debug this?

3
  • Ordinarily, dts files are source files that must be compiled before they can be loaded as an overlay and used. What is it that makes you think you can use a dts file directly to accomplish this? A few words about what you're trying to do might help us help you.
    – Seamus
    Jan 16, 2023 at 5:22
  • The reference you've cited from the kernel docs lacks many details - this may be intentional. This document at least gives you a PoC.
    – Seamus
    Jan 16, 2023 at 6:02
  • Hey @Seamus I understand that a dts file must be compiled, I used the command sudo dtc -O dtb -b 0 -o /boot/overlays/cec-spy.dtbo ./cec-spy.dts after installing apt-get install linux-headers and linking them to the include folder. From the presentation you linked, and the waybackmachine, I found a patch file that I might be able to use
    – Meberem
    Jan 16, 2023 at 8:53

2 Answers 2

2

After much debugging and trying to figure this out, I have finally managed to "install" my device. The dts in my question is for all intents and purposes correct! However the default build of the Linux Kernel does not include the supported driver. The steps I used to enable /dev/cec1 are based on the Kernel guide: https://www.raspberrypi.com/documentation/computers/linux_kernel.html and this allowed me to cross compile the kernel needed.

On a linux machine that is not the Rasp

  1. Setup a dev environment
sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev
  1. download the kernel git repo
git clone --depth=1 https://github.com/raspberrypi/linux
  1. apply the default build config
cd linux
KERNEL=kernel
make bcmrpi_defconfig
  1. Configure your version of the kernel
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig

and then hunt through the configuration program to set the following options

  • General Setup > Preemption Model > Choose option "Preemptible Kernel (Low-Latency Desktop)"
  • Exit to top menu
  • Device Drivers > HDMI CEC drivers > Select "Generic GPIO-based CEC driver" and press Y
  • Save and Exit
  1. Build
make -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs
  1. make a staging area for all this
mkdir -p ~/staging/boot/custom-kernel/overlays/
mkdir -p ~/staging/lib
  1. Copy/Build drivers to a staging
sudo env PATH=$PATH make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=~/staging/lib modules_install
  1. Copy device tree and images to a folder
sudo cp ~/linux/arch/arm/boot/zImage ~/staging/boot/custom-kernel/$KERNEL.img
sudo cp ~/linux/arch/arm/boot/dts/*.dtb ~/staging/boot/custom-kernel/
sudo cp ~/linux/arch/arm/boot/dts/overlays/*.dtb* ~/staging/boot/custom-kernel/overlays/
sudo cp ~/linux/arch/arm/boot/dts/overlays/README ~/staging/boot/custom-kernel/overlays/
  1. Copy the two folders in your staging directory to the root of the Raspberry Pi file system. In my case I had /boot mounted as fat32 and I has to mount the other partition / which is ext4 format
PC              SD Card
~/staging
   lib/    ->   /lib/
   boot/   ->   /boot/
  1. Update the config.txt to use your new Kernel by adding this line somewhere:
os_prefix=custom-kernel/
  1. Then I was able to copy my cec-spy.dtbo overlay and test it out using sudo dtoverlay cec-spy and sure enough a new /dev/cec1 device appeared!
0

in above procedure you did build seperately for cec-spy.dtbo?.

following newely created for cec-spy.dts?.

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>

/ {
        compatible = "brcm,bcm2835";

        fragment@0 {
                target-path = "/";
                __overlay__ {
                        cec-gpio@7 {
                                compatible = "cec-gpio";
                                cec-gpios = <&gpio 7 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
                                hpd-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;
                                v5-gpios = <&gpio 22 GPIO_ACTIVE_HIGH>;
                        };
                };
        };
};

I tried to build using this command sudo dtc -O dtb -b 0 -o /boot/overlays/cec-spy.dtbo ./cec-spy.dts but i am facing the error.Can you confirm any steps is missed?.

2
  • how does this answer the question?
    – jsotola
    Sep 20, 2023 at 1:07
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – jsotola
    Sep 20, 2023 at 1:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.