/*
* linux/drivers/char/gpio_led/gpio_led.c
*
* gpio_led driver for the TI DAVINCI
*
* Copyright (c) 2006 Texas Instruments.
*
*/
#include <linux/module.h>
#include <linux/config.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/miscdevice.h>
#include <linux/smp_lock.h>
#include <linux/init.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <asm/bitops.h>
#include <linux/moduleparam.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/err.h>
#include <linux/bitops.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <asm/hardware/clock.h>
#include <asm/arch/irqs.h>
#include <asm/arch/hardware.h>
#include <asm/arch/gpio.h>
#include <asm/arch/cpu.h>
#include <asm/mach/irq.h>
//10,130 = /dev/watchdog
//10,131 = /dev/temperature
//10,135 = /dev/rtc
//10,151 = /dev/led
#define GPIO_LED_MAJOR 10 //主设备号
#define GPIO_LED_MINOR 151 //次设备号
char led_data[10];
//static int timer_margin = TIMER_MARGIN_CFG_VAL; /* in seconds */
static int gpio_led_users;
static struct miscdevice gpio_led_miscdev; /* Forward declaration */
/*
* Allow only one person to hold it open
*/
static int gpio_led_open(struct inode *inode, struct file *file)
{
if(gpio_direction_output(0,0))
return -1;
if(gpio_direction_output(1,0))
return -1;
return 0;
}
static int gpio_led_release(struct inode *inode, struct file *file)
{
return 0;
}
static loff_t gpio_led_read(struct file *file, char *buf, size_t count, loff_t *offset)
{
return count; /* Not seekable */
}
static ssize_t
gpio_led_write(struct file *file, const char *data, size_t len,
loff_t * ppos)
{
char val0,val1;
copy_from_user(led_data,data,len);
if((*led_data)>2)
{
printk("input value must less than 3\n");
return -1;
}
val0 = (*led_data) & 0x01;
val1 = ((*led_data) & 0x02)>>1;
gpio_set_value(0,val0);
gpio_set_value(1,val1);
return 0;
}
static int
gpio_led_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
return 0;
}
static struct file_operations gpio_led_fops = {
.owner = THIS_MODULE,
.read = gpio_led_read,
.write = gpio_led_write,
.ioctl = gpio_led_ioctl,
.open = gpio_led_open,
.release = gpio_led_release,
};
static struct miscdevice gpio_led_miscdev = {
.minor = GPIO_LED_MINOR,
.name = "gpio_led",
.fops = &gpio_led_fops
};
static int __init gpio_led_init(void)
{
int ret;
if(gpio_request(0, NULL))//申请资源
{
printk("request gpio 0 failed\n");
return -1;
}
if(gpio_request(1, NULL))
{
printk("request gpio 1 failed\n");
gpio_free(0);
return -1;
}
ret = misc_register(&gpio_led_miscdev);
if (ret)
return ret;
return 0;
}
static void __exit gpio_led_exit(void)
{
gpio_free(0);
gpio_free(1);
misc_deregister(&gpio_led_miscdev);
}
module_init(gpio_led_init);
module_exit(gpio_led_exit);
MODULE_AUTHOR("Texas Instruments");
MODULE_LICENSE("GPL");
//module_param(timer_margin, int, 0);
gpio.rar_GPIO driver DAVINCI_GPIO 驱动_dm6467_dm6467 gpio_dm6467
版权申诉
28 浏览量
2022-09-21
07:06:08
上传
评论
收藏 15KB RAR 举报
朱moyimi
- 粉丝: 62
- 资源: 1万+
最新资源
- Screenshot_20240509_034911_com.tencent.mtt.jpg
- 基于python实现的医学影像(MIR, CT )图像分割源码+文档说明(高分课程设计)
- 基于python+JavaScript实现的医学影像分割+源代码+文档说明+截图演示+数据(高分毕业设计)
- 基于U-net+pytorch实现的医学影像分割python源码+文档说明+数据+界面截图+博客介绍
- 课程设计-基于Pytorch实现MNIST数据集的手写数字识别源码+数据(Gui界面)+文档说明+模型
- 软件开发国家标准.xls
- pytorch-CNN-SBATM-ubuntudemo
- matplotlibdemo
- pytorch-CNN-dht11温湿度传感器笔记
- 软件研发管理体系文件清单(推荐文档).xls
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈