#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驱动的更多相关文章

  1. Mini2440 DM9000 驱动分析(一)

    Mini2440 DM9000 驱动分析(一) 硬件特性 Mini2440开发板上DM9000的电气连接和Mach-mini2440.c文件的关系: PW_RST 连接到复位按键,复位按键按下,低电平 ...

  2. mini2440触摸屏驱动分析

    mini2440驱动分析系列之 ---------------------------------------Mini2440触摸屏程序分析 By JeefJiang July,8th,2009 这是 ...

  3. Mini2440 LED驱动程序设计

    1 LED初始化: 2 LED闪烁设计 位或操作:| 取反操作:~ 位与操作:& http://www.tuicool.com/articles/eQzEJv

  4. Linux网络设备驱动架構學習(二)

    Linux网络设备驱动架構學習(二) 接下來會從以下幾個方面介紹網絡設備驅動的編寫流程: 1.網絡設備的註冊與註銷 2.網絡設備的初始化 3.網絡設備的打開與釋放 4.網絡數據發送流程 5.網絡數據接 ...

  5. io重定向打开关闭 Eclipse中c开发printf无法输出解决办法

    if(freopen("e:\\lstm-comparec\\lstm\\lstm\\output.txt","a",stdout)==NULL)fprintf ...

  6. DM9000驱动移植在mini2440(linux2.6.29)和FS4412(linux3.14.78)上的实现(deep dive)篇一

    关于dm9000的驱动移植分为两篇,第一篇在mini2440上实现,基于linux2.6.29,也成功在在6410上移植了一遍,和2440非常类似,第二篇在fs4412(Cortex A9)上实现,基 ...

  7. mini2440移植uboot-2008.10 (二) DM9000网卡驱动移植

    还是利用 mini2440移植uboot-2008.10 (一)  修改好的代码 通过观察可以发现,mini2400使用的网卡芯片是DM9000,在uboot-2008.10源码中已经支持该芯片的驱动 ...

  8. mini2440驱动奇谭——ADC驱动与測试(动态挂载驱动)

    博客:http://blog.csdn.net/muyang_ren 实现功能:开发板动态载入adc驱动模块并能通过測试程序 系统:Ubuntu 14.04     驱动交叉编译内核:linux-2. ...

  9. LinuxI2C核心、总线驱动与设备驱动

    I2C体系结构分为三个部分:I2C核心.总线驱动.设备驱动 I2C核心: I2C核心提供了一组不依赖硬件的接口函数,I2C总线驱动和设备驱动之间依赖于I2C核心作为纽带 (1)增加/删除i2c_ada ...

随机推荐

  1. sql语句小练习二

    1.创建一个数据库StudentManage, 初始化大小10M,不足以1M每次增长 create database StudentManage   on ( name = 'StudentManag ...

  2. 做好SEO需要掌握的20个基础知识

    作为一个网站优化者,有一些基础seo知识点是大家必须要掌握的,网站排名的好快,和这些基础的SEO优化知识有没做好,有没做到位,有着直接的关系!今天,伟伟SEO就把我前面讲的SEO优化基础知识做个总结, ...

  3. repeater标签双重循环的使用

    在网站开发中,.NET中的repeater标签几乎是笔者首选,也是唯一一个不会生成多余元素的标签,所有样式都是自定义的,这点类似 struts中的<s:iterator/>标签. 在日常编 ...

  4. redmine添加自定义属性

    使用redmine创建问题的时候,可能会发现没有我们需要的属性,这时候我们可以添加自定义的属性. 以添加满意度属性为例: 1.进入redmine管理界面,选择自定义属性 2.选择问题下面的新建自定义属 ...

  5. 观察者(observer)设计模式

    转载:http://www.tracefact.net/CSharp-Programming/Delegates-and-Events-in-CSharp.aspx 假设我们有个高档的热水器,我们给它 ...

  6. EF 4.1 一些操作

    1.执行返回表类型的存储过程 Create PROCEDURE [dbo].[ProSelectStu] @StudentID int AS BEGIN Select Student.* from E ...

  7. VS2008无法切换到视图设计器

    编写人:CC阿爸 2014-2-17 近来用于干活的笔记本电脑实在太慢了,在领导的安排下,有幸更换了一台配置好的电脑.经过一天的努力,所有之前的开发软件都安装完成了.并且OS从xp升级到win7.SQ ...

  8. WIN8 下 Hyper-V和Vmware Workstation

    1 管理员身份运行命令提示符 cmd bcdedit /copy {current} /d “Windows Without Hyper-V 2 记下 { } 中的代码 bcdedit /set {X ...

  9. WordPress 撰写文章页面显示所有标签

    WordPress 撰写文章时,点击"从常用标签中选择"只显示45个常用的标签,很多情况下还需手工再次输入标签,这样的限制感觉很不方便,通过下面的方法可以解除这个限制,显示全部标签 ...

  10. android里面线程睡眠事件使用方法

    SystemClock.sleep(时间); 不用Thread.sleep()的原因:要抛异常,占用资源