Linux驱动之IIC总线
<作用>


















.owner = THIS_MODULE,
.llseek = eep_llseek,
.read = eep_read,
.ioctl = eep_ioctl,
.open = eep_open,
.release = eep_release,
.write = eep_write,
};
static dev_t dev_number; /* Allotted Device Number */
static struct class *eep_class; /* Device class */
/* Per-device client data structure for each
* memory bank supported by the driver
*/
struct eep_bank {
struct i2c_client *client; /* I2C client for this bank */
unsigned int addr; /* Slave address of this bank */
unsigned short current_pointer; /* File pointer */
int bank_number; /* Actual memory bank number */
/* ... */ /* Spinlocks, data cache for slow devices,.. */
};
#define NUM_BANKS 2 /* Two supported banks */
#define BANK_SIZE 2048 /* Size of each bank */
struct ee_bank *ee_bank_list; /* List of private data
structures, one per bank */
c:初始化函数
int __init
eep_init(void)
{
int err, i;
/* Allocate the per-device data structure, ee_bank */
ee_bank_list = kmalloc(sizeof(struct ee_bank)*NUM_BANKS, GFP_KERNEL);
memset(ee_bank_list, 0, sizeof(struct ee_bank)*NUM_BANKS);
/* Register and create the /dev interfaces to access the EEPROM
banks. Refer back to Chapter 5, "Character Drivers" for more details */
if (alloc_chrdev_region(&dev_number, 0,
NUM_BANKS, "eep") < 0) {
printk(KERN_DEBUG "Can't register device\n");
return -1;
}
eep_class = class_create(THIS_MODULE, DEVICE_NAME);
for (i=0; i < NUM_BANKS;i++) {
/* Connect the file operations with cdev */
cdev_init(&ee_bank[i].cdev, &ee_fops);
/* Connect the major/minor number to the cdev */
if (cdev_add(&ee_bank[i].cdev, (dev_number + i), 1)) {
printk("Bad kmalloc\n");
return 1;
}
device_create(eep_class, NULL, MKDEV (MAJOR) (dev_number),i),
"eeprom%d", i);
}
/* Inform the I2C core about our existence. See the section
"Probing the Device" for the definition of eep_driver */
err = i2c_add_driver(&eep_driver);
if (err) {
printk("Registering I2C driver failed, errno is %d\n", err);
return err;
}
printk("EEPROM Driver Initialized.\n");
return 0;
}
{
.driver = {
.name = "EEP", /* Name */
},
.id = I2C_DRIVERID_EEP, //设备标志符I2C_DRIVERID_EEP对于每个设备应该是唯一的
.detach_client = eep_detach, /* Detach Method */
};
/* The EEPROM has two memory banks having addresses SLAVE_ADDR1
* and SLAVE_ADDR2, respectively
*/
static unsigned short normal_i2c[] = {
SLAVE_ADDR1, SLAVE_ADDR2, I2C_CLIENT_END
};
static struct i2c_client_address_data addr_data = {
.normal_i2c = normal_i2c,
.probe = ignore,
.ignore = ignore,
.forces = ignore,
};
{
/* The callback function eep_attach(), is shown in Listing 8.5 */
return i2c_probe(adapter, &addr_data, eep_attach);
}
int eep_attach(struct i2c_adapter *adapter, int address, int kind)
{
static struct i2c_client *eep_client;
eep_client = kmalloc(sizeof(*eep_client), GFP_KERNEL);
eep_client->driver = &eep_driver; /* Registered in Listing 8.2 */
eep_client->addr = address; /* Detected Address */
eep_client->adapter = adapter; /* Host Adapter */
eep_client->flags = 0;
strlcpy(eep_client->name, "eep", I2C_NAME_SIZE);
/* Populate fields in the associated per-device data structure */
/* ... */
/* Attach */
i2c_attach_client(new_client);
}


Linux驱动之IIC总线的更多相关文章
- Linux驱动之I2C总线设备以及驱动
[ 导读] 本文通过阅读内核代码,来梳理一下I2C子系统的整体视图.在开发I2C设备驱动程序时,往往缺乏对于系统整体的认识,导致没有一个清晰的思路.所以从高层级来分析一下I2C系统的设计思路,将有助于 ...
- Linux驱动之USB总线驱动程序框架简析
通用串行总线(USB)是主机和外围设备之间的一种连接.USB总线规范有1.1版和2.0版,当然现在已经有了3.0版本.USB1.1支持两种传输速度:低速为1.5Mbps,高速为12Mbps.USB2. ...
- Exynos4412 IIC总线驱动开发(一)—— IIC 基础概念及驱动架构分析
关于Exynos4412 IIC 裸机开发请看 :Exynos4412 裸机开发 —— IIC总线 ,下面回顾下 IIC 基础概念 一.IIC 基础概念 IIC(Inter-Integrated Ci ...
- 迅为4412开发板Linux驱动教程——总线_设备_驱动注册流程详解
本文转自:http://www.topeetboard.com 视频下载地址: 驱动注册:http://pan.baidu.com/s/1i34HcDB 设备注册:http://pan.baidu.c ...
- SHT20 IIC总线驱动概述
SHT20温湿度传感器使用iic总线的驱动方式,以下资料参考SHT20 datasheet总结 1.IIC总线 Start信号 IIC总线的起始信号以SDA由高电平变为低电平,等待5us以上,再由SC ...
- 迅为4412开发板Linux驱动教程——总线_设备_驱动注冊流程具体解释
视频下载地址: 驱动注冊:http://pan.baidu.com/s/1i34HcDB 设备注冊:http://pan.baidu.com/s/1kTlGkcR 总线_设备_驱动注冊流程具体解释 • ...
- RT-thread 设备驱动组件之IIC总线设备
本文主要介绍RT-thread中IIC总线设备驱动,涉及到的主要文件有:驱动框架文件(i2c_core.c,i2c_dev.c,i2c-bit-ops.c,i2c_dev.h,i2c.h):底层硬件驱 ...
- Linux I2C核心、总线和设备驱动
目录 更新记录 一.Linux I2C 体系结构 1.1 Linux I2C 体系结构的组成部分 1.2 内核源码文件 1.3 重要的数据结构 二.Linux I2C 核心 2.1 流程 2.2 主要 ...
- 【Linux开发】【DSP开发】Linux设备驱动之——PCI 总线
PCI总线概述 随着通用处理器和嵌入式技术的迅猛发展,越来越多的电子设备需要由处理器控制.目前大多数CPU和外部设备都会提供PCI总线的接口,PCI总线已成为计算机系统中一种应用广泛.通用的总线标准 ...
随机推荐
- HDU 3535 AreYouBusy (混合背包之分组背包)
题目链接 Problem Description Happy New Term! As having become a junior, xiaoA recognizes that there is n ...
- java矩阵包jama的简单操作
本文转自http://www.cnblogs.com/zangbo/p/5622351.html 一.jama简介 Jama是一个基本的线性代数java包.包括一个基本的Matrix类和5个矩阵分解类 ...
- JS设计模式——12.装饰者模式
装饰者模式概述 本章讨论的是一种为对象添加特性的技术,她并不使用创建新子类这种手段. 装饰者模式可以用来透明的把对象包装在具有同样接口的另一个对象中.这样一来,就可以给一个方法添加一些行为,然后将方法 ...
- 2016.08.02 math(leetcode) 小结
math(leetcode) 小结 在leetcode中有些知识点(套路) 判断一个数是不是能被某些数整除,可以用 n%x == 0,循环除的话,就将while(n%x == 0)的循环条件设置判断整 ...
- 使用qt写的进制转换器
没有使用什么数据结构,直接使用qt自带的进制转换函数, 实时出结果,代码在后面的链接中,由于初学qt,好多不会,代码构造就有点乱 截图如下
- 4 - django-orm基本使用
目录 1 数据库与ORM 2 orm的配置 2.1 引擎和配置 2.2 mysql驱动程序 3 orm 表模型 3.1 创建表对象 3.2 Django字段类型 3.3 常用字段参数说明 3.4 特殊 ...
- linux文件管理 -> 系统压缩打包
如果希望windows和Linux互相能使用的压缩工具, 建议.zip格式 压缩的好处主要有: 节省磁盘空间占用率 节省网络传输带宽消耗 网络传输更加快捷 Linux系统常见的后缀名所对应的压缩工具 ...
- RabbitMQ--work queues(二)
封装一个task到一个message,并发送到queue.consumer会去除task并执行这个task. 这里我们简化了操作,发送消息到队列中,consumer取出消息计算里面'.'号有几个就sl ...
- [ python ] 学习目录大纲
简易博客[html+css]练习 MySQL 练习题及答案 MySQL视图.触发器.函数.存储过程 MySQL 操作总结 Day41 - 异步IO.协程 Day39/40 - 线程的操作 Day36/ ...
- 使用JS实现2048小游戏
JS实现2048小游戏源码 效果图: 代码如下,复制即可使用: (适用浏览器:360.FireFox.Chrome.Opera.傲游.搜狗.世界之窗. 不支持Safari.IE8及以下浏览器.) &l ...