mini2440 linuxi2c驱动
#include <linux/kernel.h> #include <linux/init.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/delay.h> #include <linux/mutex.h> #include <linux/sysfs.h> #include <linux/mod_devicetable.h> #include <linux/log2.h> #include <linux/bitops.h> #include <linux/jiffies.h> #include <linux/i2c.h> #include <linux/i2c/at24.h> #include <linux/fs.h> #include <asm/uaccess.h>
static struct i2c_client *at24_client;
static int major=0;
static struct class *cls;
static const struct i2c_device_id at24_ids[] = {
{"at24",8}, {}, };
MODULE_DEVICE_TABLE(i2c,at24_ids);
static ssize_t at24_read(struct file *file, char __user *buf, size_t len, loff_t *offset)
{ unsigned char address;
unsigned char data;
struct i2c_msg msg[2];
int ret;
if(len!=1) return -EINVAL; copy_from_user(&address,buf,1); msg[0].addr=at24_client->addr; msg[0].buf=&address; msg[0].len=1; msg[0].flags=0; msg[1].addr=at24_client->addr; msg[1].buf=&data; msg[1].len=1; msg[1].flags =I2C_M_RD; ret=i2c_transfer(at24_client->adapter,msg,2); if(ret==2) { copy_to_user(buf,&data,1); return 1; } else return -EIO; printk("read !\n"); return 0; } static ssize_t at24_write(struct file *file, const char __user *buf, size_t len, loff_t *offset) { unsigned char val[2]; struct i2c_msg msg[1]; int ret; if(len!=2) return -EINVAL; copy_from_user(val,buf,2); msg[0].addr=at24_client->addr; msg[0].buf=val; msg[0].len=2; msg[0].flags=0; ret=i2c_transfer(at24_client->adapter,msg,1); if(ret==1) { return 2; } else return -EIO; printk("write !\n"); return 0; }
static struct file_operations fop={ .owner =THIS_MODULE, .write =at24_write, .read =at24_read, }; static int at24_probe(struct i2c_client *client, const struct i2c_device_id *ids) { printk("probe ok!\n"); at24_client=client; major=register_chrdev(0,"at24",&fop); cls=class_create(THIS_MODULE,"at24"); device_create(cls,NULL,MKDEV(major,0),NULL,"at24"); return 0; } static int at24_remove(struct i2c_client *client) { kfree(at24_client); unregister_chrdev(major,"at24"); device_destroy(cls,MKDEV(major,0)); class_destroy(cls); printk("remove ok!\n"); return 0; }
static struct i2c_driver at24cx_driver = { .driver = { .name = "at24", .owner = THIS_MODULE, }, .probe = at24_probe, .remove = at24_remove, .id_table =at24_ids, };
static int at24cx_init(void) { return i2c_add_driver(&at24cx_driver); }
static void at24cx_exit(void) { i2c_del_driver(&at24cx_driver); } module_init(at24cx_init); module_exit(at24cx_exit); MODULE_LICENSE("GPL");
static struct at24_platform_data at24_i2c_info = {
.byte_len = 8, .page_size = 8, };
static struct i2c_board_info at24_i2c_devices[] =
{ { I2C_BOARD_INFO("at24", 0x50),
.platform_data = &at24_i2c_info, },
};
mini2440 linuxi2c驱动的更多相关文章
- Mini2440 DM9000 驱动分析(一)
Mini2440 DM9000 驱动分析(一) 硬件特性 Mini2440开发板上DM9000的电气连接和Mach-mini2440.c文件的关系: PW_RST 连接到复位按键,复位按键按下,低电平 ...
- mini2440触摸屏驱动分析
mini2440驱动分析系列之 ---------------------------------------Mini2440触摸屏程序分析 By JeefJiang July,8th,2009 这是 ...
- Mini2440 LED驱动程序设计
1 LED初始化: 2 LED闪烁设计 位或操作:| 取反操作:~ 位与操作:& http://www.tuicool.com/articles/eQzEJv
- Linux网络设备驱动架構學習(二)
Linux网络设备驱动架構學習(二) 接下來會從以下幾個方面介紹網絡設備驅動的編寫流程: 1.網絡設備的註冊與註銷 2.網絡設備的初始化 3.網絡設備的打開與釋放 4.網絡數據發送流程 5.網絡數據接 ...
- io重定向打开关闭 Eclipse中c开发printf无法输出解决办法
if(freopen("e:\\lstm-comparec\\lstm\\lstm\\output.txt","a",stdout)==NULL)fprintf ...
- DM9000驱动移植在mini2440(linux2.6.29)和FS4412(linux3.14.78)上的实现(deep dive)篇一
关于dm9000的驱动移植分为两篇,第一篇在mini2440上实现,基于linux2.6.29,也成功在在6410上移植了一遍,和2440非常类似,第二篇在fs4412(Cortex A9)上实现,基 ...
- mini2440移植uboot-2008.10 (二) DM9000网卡驱动移植
还是利用 mini2440移植uboot-2008.10 (一) 修改好的代码 通过观察可以发现,mini2400使用的网卡芯片是DM9000,在uboot-2008.10源码中已经支持该芯片的驱动 ...
- mini2440驱动奇谭——ADC驱动与測试(动态挂载驱动)
博客:http://blog.csdn.net/muyang_ren 实现功能:开发板动态载入adc驱动模块并能通过測试程序 系统:Ubuntu 14.04 驱动交叉编译内核:linux-2. ...
- LinuxI2C核心、总线驱动与设备驱动
I2C体系结构分为三个部分:I2C核心.总线驱动.设备驱动 I2C核心: I2C核心提供了一组不依赖硬件的接口函数,I2C总线驱动和设备驱动之间依赖于I2C核心作为纽带 (1)增加/删除i2c_ada ...
随机推荐
- js设计模式-建造者模式
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【Linux】inode_针对MySQL读写操作在系统层的进一步学习【转】
转自http://www.cnblogs.com/itech/archive/2012/05/15/2502284.html 一.inode是什么? 理解inode,要从文件储存说起. 文件储存在硬盘 ...
- leetcode 8
string类型转换为int类型,需要考虑不同的转换情况. “ 04” 转换结果 4: “ 4 43” 转换结果 4: “a@12 ” 转换结果 0: “12a” ...
- Android IOS WebRTC 音视频开发总结(二四)-- p2p调用堆栈
本文主要分析webrtc音视频点对点部分的代码结构,文章来自博客园RTC.Blacker,转载请说明出处. 前段时间在查一个偶尔断线的问题(这种问题最蛋疼,不好重现,只能凭经验去搞),所以理了下web ...
- eclipse启动tomcat时设置端口
近在做项目需要更改tomcat的端口号,开发工具用的是Eclipse,更改后在Eclipse中重启发现,端口号依然是8080,原来在配置文件更改了tomcat端口号后,要在Eclipse重新装载一次, ...
- 三、第一个Struts2应用案例(编码步骤)
第一个Struts2应用案例(编码步骤) 编写2个jsp hello.jsp <body> <a href="${pageContext.request.conte ...
- linux使用dd命令快速生成大文件
dd命令可以轻易实现创建指定大小的文件,如 dd if=/dev/zero of=test bs=1M count=1000 会生成一个1000M的test文件,文件内容为全0(因从/dev/zero ...
- jQ $.extend用法
$.extend()函数 1.用将一个对象或多个对象的内容合并到目标对象, 2.如果多个对象具有相同的属性,则后者覆盖前者的属性值. 例子: var object1={ apple:1, banana ...
- CentOS下修复grub引导程序
1.早上装系统,试了好几次.最终grub修复成功! 解决方法大致如下: 开机遇见 grub>的时候 下面看解决方法 首先是既然插上U盘能进系统 那我们插上U盘 正常进入系统 然后看操作 [r ...
- mutex 简单介绍
“mutex”是术语“互相排斥(mutually exclusive)”的简写形式,也就是互斥量. 当两个或更多线程需要同时访问一个共享资源时,系统需要使用同步机制来确保一次只有一个线程使用该资源.M ...