myled.c
#include //add tsuibin #include #include #include #define MYLED_COUNT 1 // S3C2410_GPIO_OUTPUT static unsigned long led_table[] = { ssize_t ssize_t unsigned int pin; pin = led_table[pin]; base = S3C24XX_GPIO_BASE (pin); dat = __raw_readl (base + 0x04); local_irq_restore (flags); int return 0; int int struct file_operations myled_fops = { static int __init /* config gpbcon */ myled_class = class_create (THIS_MODULE, MYLED_NAME); for (i = 0; i < 4; i++) } return ret; static void __exit dev_t dev; dev = myled_cdev.dev; device_destroy (myled_class, dev); return; module_init (myled_init);
#include
#include
#include
#include
#include
#include
#include
#include
/*#include 'gpio-nrs.h'*/
#include
#include
#include
#include
#include
#define MYLED_NAME 'myled'
#define S3C2410_GPB5 S3C2410_GPB(5)
#define S3C2410_GPB6 S3C2410_GPB(6)
#define S3C2410_GPB7 S3C2410_GPB(7)
#define S3C2410_GPB8 S3C2410_GPB(8)
static struct cdev myled_cdev;
static struct class *myled_class;
static struct device *myled_device;
S3C2410_GPB (5),
S3C2410_GPB (6),
S3C2410_GPB (7),
S3C2410_GPB (8),
};
myled_read (struct file *filp, char __user * buf, size_t count,
loff_t * f_pos)
{
return 0;
}
myled_write (struct file * filp, const char __user * buf, size_t count,
loff_t * f_pos)
{
unsigned int led_off = 0;
unsigned long offs;
unsigned long flags;
unsigned long dat;
void *base;
pin = buf[0] - '0';
if (buf[1] == '0')
{
led_off = 1;
}
if (pin >= 4 || pin < 0)
return -1;
offs = S3C2410_GPIO_OFFSET (pin);
local_irq_save (flags);
dat &= ~(1 << offs);
dat |= led_off << offs;
__raw_writel (dat, base + 0x04);
return count;
}
myled_ioctl (struct inode *inode, struct file *filp, unsigned int cmd,
unsigned long arg)
{
}
myled_open (struct inode *inode, struct file *filp)
{
return 0;
}
myled_release (struct inode *inode, struct file *filp)
{
return 0;
}
.owner = THIS_MODULE,
.read = myled_read,
.write = myled_write,
.ioctl = myled_ioctl,
.open = myled_open,
.release = myled_release,
};
myled_init (void)
{
int ret;
dev_t dev;
/* S3C2410_GPIO_BANKB */
/* S3C2410_GPIO_OUTPUT */
void *base;
int i;
unsigned int pin;
unsigned int function;
unsigned long mask;
unsigned long con;
unsigned long flags;
ret = alloc_chrdev_region (&dev, 0, MYLED_COUNT, MYLED_NAME);
if (ret < 0)
{
printk ('get dev error!n');
return -1;
}
cdev_init (&myled_cdev, &myled_fops);
cdev_add (&myled_cdev, dev, 1);
myled_device = device_create (myled_class, NULL, dev, NULL, MYLED_NAME);
{
pin = led_table[i];
function = S3C2410_GPIO_OUTPUT;
base = S3C24XX_GPIO_BASE (pin);
mask = 3 << S3C2410_GPIO_OFFSET (pin) * 2;
function &= 3;
function <<= S3C2410_GPIO_OFFSET (pin) * 2;
local_irq_save (flags);
con = __raw_readl (base + 0x00);
con &= ~mask;
con |= function;
__raw_writel (con, base + 0x00);
local_irq_restore (flags);
printk ('module initn');
}
myled_exit (void)
{
printk ('module exitn');
cdev_del (&myled_cdev);
unregister_chrdev_region (dev, 1);
class_destroy (myled_class);
}
module_exit (myled_exit);
MODULE_LICENSE ('Dual BSD/GPL');
MODULE_AUTHOR('Tsuibin');
上一篇:Linux LCD驱动分析
下一篇:mini2440 madplay移植出现问题解决
推荐阅读最新更新时间:2024-11-05 13:31
设计资源 培训 开发板 精华推荐
- 单色 0.91" 128x32 I2C OLED 图形显示器 | 326
- HasuUSB2USB
- ATX电源计划
- DC2073A-C,基于 LTC6900 的演示板,5kHz 至 10MHz 硅振荡器
- LTC2156-12 演示板,12 位,210Msps,1.8V 双路 ADC,DDR LVDS 输出,5-140MHz
- AD8615AUJZ-R2单电源降噪运算放大器典型应用电路
- 具有检测功能的 RT9073、1-Micro A IQ、250mA 低压降线性稳压器的典型应用
- [测试通过] PAM8403 D类功放板
- 使用 Analog Devices 的 LT1120ACN8 的参考设计
- AKD4702,带 AV SCART 开关的 AK4702 2CH DAC 评估板