Skip to main content
Explorer
December 16, 2024
Solved

Use of gpiod_ in ecosystem V6

  • December 16, 2024
  • 1 reply
  • 673 views

Hi STM Community !!
We use the STM32MP1 on our board.

We use the gpio feature for an IRQ in our system.
We use it in a kernel module.

With the Ecosystem v5, it worked perfectly, but we used

#define PIN_FPGA_INTA (16 + 10)

static struct gpio gpio_irq_pps = {PIN_FPGA_INTA, GPIOF_IN, "IRQ PPS FPGA"};

...
if (gpio_request_one(gpio_irq_pps.gpio, gpio_irq_pps.flags, gpio_irq_pps.label)) {
printk("Fail of gpio_request for PPS_INT(B10 pin) :( \n");
}

irq_num_pps = gpio_to_irq(gpio_irq_pps.gpio);
if (irq_num_pps < 0) {
printk("Fail to use GPIO B10 as PPS Interrupt :( \n");
gpio_free(PIN_FPGA_INTA);
}

// set interrupt for PPS
ret = request_irq(irq_num_pps, pps_irq_handler, IRQF_TRIGGER_FALLING, "pnt_fpga_int_a", NULL);
if (ret != 0) {
printk("Interrupt Request Failed for INT_PPS: %d\n", ret);
gpio_free(PIN_FPGA_INTA);
} else
printk("Interrupt PPS OK\n");
...

Now, in the Ecosystem v6, we need to move to new gpiod kernel functions, because gpio_* functions are deprecated.
So, in the DTS In the DTS we have :

/ {
...
my_gpio {
fpga_inta-gpios = <&gpiob 10 GPIO_PULL_UP>;
fpga_intb-gpios = <&gpiob 11 GPIO_PULL_UP>;
}
...
};

We tried to use :

struct gpio_desc *gpio_pps;

gpio_pps = gpio_to_desc(PIN_FPGA_INTA);
or
gpio_pps = gpiod_get(NULL, "PB10", GPIOD_IN);

but each time these functions return no gpio.

 

Have you an idea ?
thanks for your help.

    This topic has been closed for replies.
    Best answer by hechelard

    I reply to myself with a solution .. if it can help anyone with the same question

    Firstovall, be sure you declared your gpio in your DTS, in root for example:

    pnt_gpio: board_gpio {
    yourgpio-gpios = <&gpiok 0 GPIO_ACTIVE_HIGH>;
    };
    

    In your kernel module, use the of_find_node_by_path() to retrieve your declaration

    static struct gpio_desc *your_gpio;
    struct device_node *np = of_find_node_by_path("/board_gpio");
    your_gpio = fwnode_gpiod_get_index(&np->fwnode, "yourgpio", 0, GPIOD_IN, "yourgpio");

    After that ... you can use the descriptor for all gpiod_ functions you need (gpiod_direction_input(), etc ....)

    1 reply

    hechelardAuthorAnswer
    Explorer
    January 1, 2025

    I reply to myself with a solution .. if it can help anyone with the same question

    Firstovall, be sure you declared your gpio in your DTS, in root for example:

    pnt_gpio: board_gpio {
    yourgpio-gpios = <&gpiok 0 GPIO_ACTIVE_HIGH>;
    };
    

    In your kernel module, use the of_find_node_by_path() to retrieve your declaration

    static struct gpio_desc *your_gpio;
    struct device_node *np = of_find_node_by_path("/board_gpio");
    your_gpio = fwnode_gpiod_get_index(&np->fwnode, "yourgpio", 0, GPIOD_IN, "yourgpio");

    After that ... you can use the descriptor for all gpiod_ functions you need (gpiod_direction_input(), etc ....)