linux驱动:[1]LED驱动/dev/led
LED Linux驱动程序
测试平台: Xunlong Orange Pi Zero
代码一览(解析见下方)
驱动程序以及Makefile如下:
- sun8i_opizero_led.c:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <asm/uaccess.h>
#include <asm/io.h>
static struct class *sun8i_opizero_led_class;
//STATUS-LED:PA17
#define PIO_BASE 0x1C20800
volatile unsigned long *pacfg[4] = {NULL};
volatile unsigned long *padat = NULL;
static int sun8i_opizero_led_open(struct inode *inode, struct file *file)
{
//configure pa17 to output mode
*pacfg[2] &= ~(3 << 5);
return 0;
}
static ssize_t sun8i_opizero_led_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
{
int val;
copy_from_user(&val, buf, count);
if (val == 1)
*padat |= (1 <<