Hi3521DV100 BT1120 驱动程序:配置 GPIO1_7 和 GPIO1_6 为输入
#include <linux/module.h> #include <linux/init.h> #include <linux/platform_device.h> #include <linux/io.h>
#define GPIO1_BASE_ADDR 0x20140000 #define GPIO1_DIR_OFFSET 0x400 #define GPIO1_DATA_OFFSET 0x200
static int hi3521bt1120_probe(struct platform_device *pdev) { void __iomem *gpio1_base; u32 gpio1_dir, gpio1_data;
// Map GPIO1 registers to virtual memory
gpio1_base = ioremap(GPIO1_BASE_ADDR, SZ_4K);
if (!gpio1_base) {
pr_err("Failed to map GPIO1 registers\n");
return -ENOMEM;
}
// Configure GPIO1_7 as input and write data to VI_DATA0
gpio1_dir = readl(gpio1_base + GPIO1_DIR_OFFSET);
gpio1_dir &= ~(1 << 7); // set bit 7 to 0 (input)
writel(gpio1_dir, gpio1_base + GPIO1_DIR_OFFSET);
gpio1_data = readl(gpio1_base + GPIO1_DATA_OFFSET);
gpio1_data |= (1 << 0); // set bit 0 to 1 (VI_DATA0)
writel(gpio1_data, gpio1_base + GPIO1_DATA_OFFSET);
// Configure GPIO1_6 as input and write data to VI_DATA1
gpio1_dir &= ~(1 << 6); // set bit 6 to 0 (input)
writel(gpio1_dir, gpio1_base + GPIO1_DIR_OFFSET);
gpio1_data = readl(gpio1_base + GPIO1_DATA_OFFSET);
gpio1_data |= (1 << 1); // set bit 1 to 1 (VI_DATA1)
writel(gpio1_data, gpio1_base + GPIO1_DATA_OFFSET);
iounmap(gpio1_base);
return 0;
}
static int hi3521bt1120_remove(struct platform_device *pdev) { return 0; }
static struct platform_driver hi3521bt1120_driver = { .driver = { .name = "hi3521bt1120", }, .probe = hi3521bt1120_probe, .remove = hi3521bt1120_remove, };
module_platform_driver(hi3521bt1120_driver);
MODULE_LICENSE("GPL"); MODULE_AUTHOR("Your Name"); MODULE_DESCRIPTION("Hi3521DV100 BT1120 Driver");
原文地址: https://www.cveoy.top/t/topic/nKoV 著作权归作者所有。请勿转载和采集!