给驱动节点更改权限:
在android目录文件里system/core/rootdir/ueventd.rc
添加
niuyi
/dev/gpioctrl 0666 root root
arch/arm/configs/x3288_defconfig
CONFIG_GPIOCTRL=y
drivers/Makefile
obj-$(CONFIG_NOVA) += nova/
drivers/Kconfig
source "drivers/nova/Kconfig"
drivers/nova/Makefile
obj-$(CONFIG_GPIOCTRL) += gpioctrl.o
drivers/nova/Kconfig
config GPIOCTRL
tristate "misc gpio Driver"
default y
help
This is the gpio driver for misc.
kernel/arch/arm/boot/dts/rk3288-pinctrl.dtsi
pinctrl: pinctrl@ff770000 {
// niuyi
gpioctrl{
compatilbe = "rockchip,gpioctrl";
// gpionum = "2";
// gpio1 = <&gpio8 GPIO_A2 GPIO_ACTIVE_LOW>;
// gpio2 = <&gpio8 GPIO_A1 GPIO_ACTIVE_LOW>;
// status = "okay";
};
};
驱动源码:
/*
drivers/nova/gpioctrl.c
./out/target/product/rk3288/obj/EXECUTABLES/misctest_intermediates/misctest
./out/target/product/rk3288/symbol/system/bin/misctest
*/
#include
#include
#include
#include
#include
//#include
//#include //kcalloc,kzalloc等内存分配函数
//---------ioctl------------
#include
//---------misc_register----
#include
//----------cdev--------------
#include
//----------delay-------------
#include
//----------GPIO---------------
//#include
//#include
//#include
#ifdef CONFIG_OF
#include
#include
#endif
#define GPIOCTRL_DEVICE_NAME "gpioctrl"
//static int gpioctrl_gpios[10];
//static int gpionum=0;
static long gpioctrl_ioctl(struct file *filp, unsigned int cmd,unsigned long arg)
{
switch(cmd) {
case 0:
case 1:
printk("NY:gpioctrl_ioctl %d - %ld.\n",cmd,arg);
//gpio_set_value(led_gpios[arg], !cmd);//用户选定的LED并设置值
return 0x33;
break;
default:
return -EINVAL;
}
return 0;
}
static struct file_operations gpioctrl_drv_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = gpioctrl_ioctl,
};
static struct miscdevice gpioctrl_drv = {
.minor = MISC_DYNAMIC_MINOR,
.name = GPIOCTRL_DEVICE_NAME,
.fops = &gpioctrl_drv_fops,
};
static int __init gpioctrl_init(void)
{
printk("NY:gpioctrl_init\n");
return misc_register(&gpioctrl_drv);
}
static void __exit gpioctrl_exit(void)
{
printk("NY:gpioctrl_exit\n");
}
module_init(gpioctrl_init);
module_exit(gpioctrl_exit);
MODULE_AUTHOR("nova_niuyi@126.com>");
MODULE_DESCRIPTION("ROCKCHIP GPIO DEV Driver");
MODULE_LICENSE("GPL");
原作者:niuyimail