#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. PAT1007

    #include<stdio.h>#include<vector>#include<algorithm>using namespace std; int main( ...

  2. hbase 各个概念,region,storefile

    HBase中有两张特殊的Table,-ROOT-和.META. .META.:记录了用户表的Region信息,它可以有多高region(这的意思是说.META.表可以分 裂成多个region,和用户表 ...

  3. java 设计模式-代理

    代理模式对其他对象提供一种代理以控制对这个对象的访问.      在某些情况下,一个对象不想或者不能直接引用另一个对象,而代理对象可以在客户端和目标对象之间起到中介的作用.       代理模式的思想 ...

  4. Javascript 常用系统内置函数

    1:在数组指定位置插入元素 array.splice(2, 0, "three");   //在索引2的位置,删除0个元素后,插入元素“three” 例子: // 原来的数组 va ...

  5. 条款20 STL函数对象

    继承标准STL的函数对象 1: struct PopLess : public atd::binary_function<state,state,bool> 2: { 3: bool op ...

  6. MySQL 5 绿色版(BAT版本) mysql50green转自http://hi.baidu.com/dburu/blog/item/e753fcc4362458aa8226accb.htmlMySQL 5 绿色版(BAT版本) By )

    以前提供下载的那个 MySQL 绿色版是来自于 Web 开发工具箱之 Apache PHP MySQL 绿色套装版, 原作者是为了方便自己开发所做的一套整合了 Apache, PHP, MySQL 的 ...

  7. Objective-C数据类型、数据类型转换

    数据类型 1.Objective-C数据类型可以分为:基本数据类型.对象数据类型和id类型. 2.基本数据类型有:int.float.double和char类型. 3.对象类型就是类或协议所声明的指针 ...

  8. IOS多线程(一)

    一.绪论 1.进程:平时看到的一个应用程序,即可算作一个线程. 每个进程都有一个PID作为进程ID,有一个Process Name作为进程名字等. 2.线程:一个进程可以有多个线程,而每个线程只可属于 ...

  9. js实现文字字幕滚动

    <div class="dggd_r" id="h" style="height:400px;overflow:hidden;display:i ...

  10. .Net 内存泄露

    一.事件引起的内存泄露 1.不手动注销事件也不发生内存泄露的情况 我们经常会写EventHandler += AFunction; 如果没有手动注销这个Event handler类似:EventHan ...