资源简介
2440 linux2.6下I2C驱动,编译通过,大家可以参考下进行修改
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define DEVICE “i3c“
#define DATA_LEN 6
int major = 233;
int minor = 0;
void *R_GPECON*R_GPEUP*R_IICCON*R_IICSTAT*R_IICADD*R_IICDS;
int IIC_open(struct inode * struct file *);
int IIC_release(struct inode * struct file *);
ssize_t IIC_read(struct file *file char* buf size_t count loff_t *f_pos);
unsigned int IIC_poll(struct file* file poll_table* wait);
irqreturn_t interrupt_handle( int irq void* dev_id struct pt_regs* regs );
static void address_map(void)
{
#define IIC_base (0x54000000)
#define IIC_GPECON ( IIC_base + 0x40 )
#define IIC_GPEUP ( IIC_base + 0x48 )
#define IIC_CON ( IIC_base + 0x0 )
#define IIC_STAT ( IIC_base + 0x4 )
#define IIC_ADDR ( IIC_base + 0x8 )
#define IIC_DS ( IIC_base + 0xC )
R_GPECON = ioremap(IIC_GPECON4);
R_GPEUP = ioremap(IIC_GPEUP 4);
R_IICCON = ioremap(IIC_CON 4);
R_IICSTAT = ioremap(IIC_STAT 4);
R_IICADD = ioremap(IIC_ADDR 4);
R_IICDS = ioremap(IIC_DS 4);
}
static void address_unmap(void)
{
iounmap( R_GPECON );
iounmap( R_GPEUP );
iounmap( R_IICCON );
iounmap( R_IICSTAT );
iounmap( R_IICADD );
iounmap( R_IICDS );
}
static struct file_operations fops = {
owner : THIS_MODULE
read: IIC_read
open: IIC_open
release: IIC_release
poll: IIC_poll
};
struct IIC_dev{
wait_queue_head_t rq; // 读取等待队列
uint8_t *buffer;
uint32_t size;
uint32_t index;
struct semaphore sem;
struct cdev cdev;
};
struct IIC_dev *my_dev;
static int __init IIC_init(void)
{
// 1. 分配主设备号
dev_t devno = MKDEV( major minor );
int ret = register_chrdev_region( devno 1 DEVICE );
if( ret < 0 )
{
printk(KERN_DEBUG “register major number failed with %d\n“ ret);
return ret;
}
printk(KERN_DEBUG “%s:register major number OK\n“DEVICE);
// 2. 注册设备
my_dev = kmalloc(sizeof(struct IIC_dev) GFP_KERNEL);
memset( my_dev 0 sizeof(struct IIC_dev) );
cdev_init( &my_dev->cdev &fops );
my_dev->cdev.ops = &fops;
my_dev->cdev.owner = THIS_MODULE;
ret = cdev_add( &my_dev->cdev devno 1 );
if( ret < 0 )
{
printk(KERN_DEBUG “register device failed with %d\n“ ret);
return ret;
}
printk(KERN_DEBUG “%s:register device OK\n“DEVICE);
// 3. 分配本驱动要使用的内存
my_dev->index = 0;
my
- 上一篇:淘淘商城参考资料
- 下一篇:点在多边形中判断程序IDL版
评论
共有 条评论