1. Driver part (图方便,随便在一个文件中申请了一个杂项设备,有时候想,为什么不是字符设备,查阅相关信息,得知杂项设备驱动是一种特殊的字符设备驱动,节省了主设备号,使用简单。)
#include <linux/miscdevice.h>
#include <linux/uaccess.h>
#define MISC_NAME "led"
#define MISC_IOC_MAGIC 'L'
#define RK_FBIOSET_SET_LOGO _IOW(MISC_IOC_MAGIC, 0x00, int)
int sys_indicator_gpio;
static long logo_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
void __user *argp = (void __user *)arg;
int on;
pr_info("%s cmd:%d arg:%d", __FUNCTION__, cmd, arg);
switch (cmd) {
case RK_FBIOSET_SET_LOGO:
if (argp == NULL) {
pr_info("invalid argument.\n");
return -EINVAL;
}
if (copy_from_user(&on, argp, sizeof(on)))
return -EFAULT;
if (on == 0) {
gpio_direction_output(sys_indicator_gpio, 0);
} else {
gpio_d