Hi
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");
}
module_init(data_driver_init);
module_exit(data_driver_exit);
MODULE_LICENSE("GPL");
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
Jamie