Remap Pins PWM 2 to GPIO | Mallow Board | Verdin

Hi Toradex team,

This issue is some how related to the one I ask earlier but I think is better to open a new one.
Right now I can’t get my head around this.

I have this overlay:

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/clock/imx8mp-clock.h>
#include <dt-bindings/interrupt-controller/arm-gic.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include "imx8mp-pinfunc.h"

/ {
    compatible = "toradex,verdin-imx8mp";
};


/* Verdin PWM_1 */
&pwm1 {
    status = "disabled";
};

/* Verdin PWM_2 */
&pwm2 {
    status = "disabled";
};

&backlight_mezzanine{
    status = "disabled";
};

&iomuxc {
    /* SODIMM 15 */
    pinctrl_led1_gpio: led1gpiogrp {
        fsl,pins = <MX8MP_IOMUXC_SPDIF_EXT_CLK__GPIO5_IO05 0x146>;
    };

    /* SODIMM 16 */
    /*MX8MP_IOMUXC_GPIO1_IO11__PWM2_OUT*/
    pinctrl_led2_gpio: led2gpiogrp {
        fsl,pins = <MX8MP_IOMUXC_GPIO1_IO11__GPIO1_IO11 0x146>;
    };
};

&{/} {

    led1_gpio: led1-gpio {
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_led1_gpio>;
        status = "okay";
    };

    led2_gpio: led2-gpio {
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_led2_gpio>;
        status = "okay";
    };
};

My problem is has follow. This .dts is correctly configuring the Led 1 (PWM 1 - SODIMM 15), I can change the state and see with the the pin go from 0 to 1.8v but when trying to change the Led 2 (PWM 2 - SODIMM 16) I can’t toggle between on/off I have always 1.8v on the PIN.

Is something related to this:
image

Appreciate any help you can provide.

Thanks in advance,
André Silva

Software summary
------------------------------------------------------------
Bootloader:               U-Boot
Kernel version:           5.15.148-6.8.0+git.8c5c2dcbf6ba #1-TorizonCore SMP PREEMPT Tue Aug 6 10:01:59 UTC 2024
Kernel command line:      root=LABEL=otaroot rootfstype=ext4 quiet logo.nologo vt.global_cursor_default=0 plymouth.ignore-serial-consoles splash fbcon=map:3 ostree=/ostree/boot.0/torizon/4ba8fb87dbcbe4eef169c350696ae1ce34e2585cf534963f9395709a06466082/0
Distro name:              NAME="TorizonCore"
Distro version:           VERSION_ID=6.8.0-build.22
Distro variant:           VARIANT="Docker"
Hostname:                 verdin-imx8mp-15459446
------------------------------------------------------------

Hardware info
------------------------------------------------------------
HW model:                 Toradex Verdin iMX8M Plus on Verdin Development Board
Toradex version:          0063 V1.1B
Serial number:            15459446
Processor arch:           aarch64
------------------------------------------------------------

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello,

When configuring GPIO pins on the Verdin iMX8M Plus, it’s important to ensure proper pin multiplexing and control settings. You can refer to the Verdin iMX8M Plus documentation and the datasheet for detailed guidance. The pin control register allows you to configure several parameters, including:

  • Pull-up/down resistors
  • Drive strength
  • Slew rate
  • Input/output settings

For your specific case with PWM2 (SODIMM 16), consider the following steps:

  1. Check the Pad Control Register Settings: The 0x146 value you’re using might need adjustment. Ensure it aligns with your intended configuration.

  2. Verify Pin Configuration Conflicts: Ensure there are no conflicting configurations. Although you are disabling PWM2 in your device tree, another component might still be controlling the pin.

  3. Set Correct Pin Multiplexing: Make sure the pin is configured specifically for GPIO mode.

You may need to adjust the pad control register settings. The register allows configuration of:

  • PE (bit 8): Pull resistor enable/disable
  • HYS (bit 7): CMOS vs Schmitt trigger input
  • PUE (bit 6): Pull-up vs pull-down selection
  • ODE (bit 5): CMOS vs open-drain output
  • FSE (bits 4-3): Slew rate control
  • DSE (bits 2-0): Drive strength

If the issue persists, check if there are any other nodes in your device tree that might be claiming control of this pin.

I hope this helps you resolve the configuration issue.

Best regards,
Toradex AI Assistant

A bit more information,

I have set the pin with the configuration 0x1E (open drain) since I check this on the circuit schematics:

What i’m missing here?

Thanks in advance.

Hello @af-silva,

Sorry for the delay here.

On your device tree overlay, where you declare the LEDs, you are missing the compatible string, which will tell Linux which driver to use there.
You are also missing the GPIO configuration for these nodes.

Please check the following example: How to Customize Device Trees | Toradex Developer Center

Best Regards,
Bruno

Hi @bruno.tx ,

Do you mean like this:

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/clock/imx8mp-clock.h>
#include <dt-bindings/interrupt-controller/arm-gic.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include "imx8mp-pinfunc.h"

/ {
    compatible = "toradex,verdin-imx8mp";
};


/* Verdin PWM_1 */
&pwm1 {
    status = "disabled";
};

/* Verdin PWM_2 */
&pwm2 {
    status = "disabled";
};

&backlight_mezzanine{
    status = "disabled";
};



&iomuxc {
    pinctrl_leds_gpio: ledgpiogrp {
        fsl,pins = <MX8MP_IOMUXC_SPDIF_EXT_CLK__GPIO5_IO05 0x104>, /* SODIMM 15 | PWM_1 | x10 Pin 18 | pull-down enabled and drive strength X2  */
                   <MX8MP_IOMUXC_GPIO1_IO11__GPIO1_IO11 0x104>;    /* SODIMM 16 | PWM_2 | x10 Pin 19 | pull-down enabled and drive strength X2  */
    };
    
};

&{/} {

    leds {
        compatible = "gpio-leds";

        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_leds_gpio>;

        led1_sodimm_15 {
            label = "LED_1";
            gpios = <&gpio5 5 GPIO_ACTIVE_HIGH>;
            linux,default-trigger = "heartbeat";
            default-state = "on";
        };

        led2_sodimm_16 {
            label = "LED_2";
            gpios = <&gpio1 11 GPIO_ACTIVE_HIGH>;
            linux,default-trigger = "heartbeat";
            default-state = "on";
        };


    };
};

The result is the same, I can toggle on/off the pin 18 (PWM_1) but nothing seems to happen on the pin 19 (PWM_2), it’s is always on.

Thanks for any help you can provide

Hello @af-silva,

Your device tree overlay is correct.
If you connect LEDs to these GPIO pins you should see then blink in a heartbeat cadence.

The reason for this is that the linux,default-trigger property is set to "heartbeat".
You can view the options available in the following documentation: https://www.kernel.org/doc/Documentation/devicetree/bindings/leds/common.yaml

If you want to control the LEDs via the sysfs interface, you can set this property to "none".

Best Regards,
Bruno

Hi @bruno.tx thanks for the feedback,

Note: We are using imx8mp on a mallow board

But that is the thing, I have a digital multimeter connected to the pin heads to test the change of state ok, i don’t have leds connected to the board yet. What I can see is that I can see changes on the pin 18 I can toggle the pin on/off and see 1.8v and 0v respectively. On the other hand on the pin 19 I can’t get the same behavior, the pin is always at 1.8v regardless of what I do.
For context, I’m using the docker container from the Toradex documentation for my testbed, and using the libgpiod to test, and when doing the gpioset gpiochip0 11=1 & and gpioset gpiochip0 11=0 & nothing happens on this pin I can’t any state change (i.e., on/off) but on the pin 18 doing the same test gpioset gpiochip4 5=1 & and gpioset gpiochip4 5=0 & it works as expected.

I’m missing something here ???

Hello @af-silva,

When configuring the GPIOs as LEDs, you need to use the LED sysfs interface, not libgpiod.
This can be done as in the following example (Lines starting with # are my comments):

root@verdin-imx8mp-15247177:/sys/devices/platform/leds/leds/LED_1# echo none > trigger
# Disable trigger heartbeat
root@verdin-imx8mp-15247177:/sys/devices/platform/leds/leds/LED_1# cat brightness 
0 
# LED is OFF
root@verdin-imx8mp-15247177:/sys/devices/platform/leds/leds/LED_1# echo 1 > brightness 
# LED turns ON
root@verdin-imx8mp-15247177:/sys/devices/platform/leds/leds/LED_1# echo 0 > brightness
# LED turns OFF

Best Regards,
Bruno

Hi @bruno.tx,

Again thanks for the quick reply, and I can confirm that using sysfs interface and the last overlay I provided it works as expected.

But I will need to control this from a container and would be easier to use libgpiod to control the leds and also I would like to known how to configure this specific pins as generic GPIO’s and not only as LEDs.

Again thanks for the help.
Best regards,
André Silva

Hello @af-silva,

Noted, then to use libgpiod, you should not configure them as LEDs on the device tree, but as GPIOs.
This means that you can remove the leds node with all its content.
Then, to enable pinctrl_leds_gpio being used as GPIOs, you need to add them to the pinctrl-0 property on the iomuxc node.
For the module you are using, you can add the following under the existing &iomuxc, before pinctrl_leds_gpio:

pinctrl-0 = <&pinctrl_gpio1>, <&pinctrl_gpio2>,
		    <&pinctrl_gpio3>, <&pinctrl_gpio4>,
		    <&pinctrl_gpio7>, <&pinctrl_gpio8>,
		    <&pinctrl_gpio_hog1>, <&pinctrl_gpio_hog2>, <&pinctrl_gpio_hog3>,
		    <&pinctrl_hdmi_hog>, <&pinctrl_leds_gpio>;

Best Regards,
Bruno