Hi3521DV100 GPIO5_1 输出控制驱动程序示例
#include <linux/module.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/platform_device.h> #include <linux/io.h> #include <linux/delay.h>
#define GPIO5_BASE 0x20150000 #define GPIO5_DIR_OFFSET 0x400 #define GPIO5_DAT_OFFSET 0x404 #define GPIO5_1_BIT 1
static void __iomem *gpio5_base;
static int hi3521_gpio_init(void) { gpio5_base = ioremap(GPIO5_BASE, SZ_4K); if (!gpio5_base) { printk(KERN_ERR 'Failed to map GPIO5 registers\n'); return -EINVAL; }
// Set GPIO5_1 as output
writel(readl(gpio5_base + GPIO5_DIR_OFFSET) | (1 << GPIO5_1_BIT),
gpio5_base + GPIO5_DIR_OFFSET);
// Write low level for 100ms
writel(readl(gpio5_base + GPIO5_DAT_OFFSET) & ~(1 << GPIO5_1_BIT),
gpio5_base + GPIO5_DAT_OFFSET);
msleep(100);
// Write high level for 50ms
writel(readl(gpio5_base + GPIO5_DAT_OFFSET) | (1 << GPIO5_1_BIT),
gpio5_base + GPIO5_DAT_OFFSET);
msleep(50);
return 0;
}
static void hi3521_gpio_exit(void) { // Set GPIO5_1 as input writel(readl(gpio5_base + GPIO5_DIR_OFFSET) & ~(1 << GPIO5_1_BIT), gpio5_base + GPIO5_DIR_OFFSET);
iounmap(gpio5_base);
}
static struct platform_driver hi3521_gpio_driver = { .probe = hi3521_gpio_init, .remove = hi3521_gpio_exit, .driver = { .name = 'hi3521_gpio', .owner = THIS_MODULE, }, };
static int __init hi3521_gpio_module_init(void) { return platform_driver_register(&hi3521_gpio_driver); }
static void __exit hi3521_gpio_module_exit(void) { platform_driver_unregister(&hi3521_gpio_driver); }
module_init(hi3521_gpio_module_init); module_exit(hi3521_gpio_module_exit); MODULE_LICENSE('GPL');
原文地址: https://www.cveoy.top/t/topic/nKnS 著作权归作者所有。请勿转载和采集!