#include <linux/init.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/io.h>

#define GPIO5_BASE_ADDR 0x201B0000 #define GPIO5_REG_DIR_OFFSET 0x400 #define GPIO5_REG_DAT_OFFSET 0x404

static void __iomem *gpio5_base;

static int gpio_init(void) { int ret = 0;

// 映射 GPIO5 的寄存器
gpio5_base = ioremap(GPIO5_BASE_ADDR, SZ_4K);
if (!gpio5_base) {
    printk(KERN_ERR 'Failed to map GPIO5 registers\n');
    return -ENOMEM;
}

// 配置 GPIO5_0 和 GPIO5_1 为输出
writel(0x00000003, gpio5_base + GPIO5_REG_DIR_OFFSET);

// 设置 GPIO5_1 拉低电平 100ms
writel(0x00000000, gpio5_base + GPIO5_REG_DAT_OFFSET);
msleep(100);

// 设置 GPIO5_1 拉高电平 100ms
writel(0x00000002, gpio5_base + GPIO5_REG_DAT_OFFSET);
msleep(100);

printk(KERN_INFO 'GPIO driver initialized\n');

return ret;

}

static void gpio_exit(void) { // 取消映射 GPIO5 的寄存器 iounmap(gpio5_base);

printk(KERN_INFO 'GPIO driver exited\n');

}

module_init(gpio_init); module_exit(gpio_exit);

MODULE_LICENSE('GPL'); MODULE_AUTHOR('Your Name'); MODULE_DESCRIPTION('GPIO driver for Hi3521DV100');

Hi3521DV100 GPIO 驱动程序示例:配置 GPIO5_0 和 GPIO5_1 为输出

原文地址: https://www.cveoy.top/t/topic/nKpb 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录