GPIO device tree binding to module/driver not working


I’m writing a module to control Jetson Nano GPIO pins from kernel space and I haven’t been able to get it to work. Here is my source code for both the module and device tree.

Module/driver C code:

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kdev_t.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <linux/gpio/driver.h>
#include <linux/gpio/consumer.h>

struct device *dev;
struct gpio_desc *data_rx, *data_tx;

static int __init data_driver_init(void);
static void __exit data_driver_exit(void);

static const struct of_device_id data_dt_ids[] = {
    { .compatible = "gpio-data", },
    { /* sentinel */ }
MODULE_DEVICE_TABLE(of, data_dt_ids);

** Module Init function
static int __init data_driver_init(void)
    pr_info("Module init.\n");
    data_tx = gpiod_get(dev,"data_tx",GPIOD_OUT_HIGH);
    if ( IS_ERR(data_tx) ) {
        pr_err("Error retrieving GPIO\n");

    return 0;

** Module exit function
static void __exit data_driver_exit(void)
    pr_info("Module exit.\n");


And here’s my device tree entry

data {
		compatible = "gpio-data";
		status = "okay";
        data_rx-gpios = <&gpio TEGRA_GPIO(BB, 0) GPIO_ACTIVE_LOW>; /* rx, gpio216, pin 7 */
        data_tx-gpios = <&gpio TEGRA_GPIO(J, 7) GPIO_ACTIVE_HIGH>; /* tx, gpio79, pin 12 */

Is this the correct way to bind the two files together?

When I insmod and then dmesg, the pr_err message occurs. This happens when it runs the line:

data_tx = gpiod_get(dev,"data_tx",GPIOD_OUT_HIGH);

What could be happening?

Thanks in advance for any help

hello JamieBasil,

here’s Jetson-IO tool to simplify the configuration of the I/Os exposed by the 40‑pin expansion header.
please check developer guide for reference, Configuring the 40-Pin Expansion Header.

Thanks JerryChang

I tried using the Jetson-IO tool but it doesn’t look like it has an option to configure unused pins 7 and 12. How do I do this?

Is it not possible to add a node to tegra-porg-p3448-common.dtsi file like I was trying to do above?

hello JamieBasil,

here’re two pins you would like to control with. GPIO09/ GPIO3_PBB.00 and I2S0_SCLK / GPIO3_PJ.07.
they had configured as GPIO pins by default, but the initial state is different.
you may update the DTB configurations to update the pin settings.