《精通Linux设备驱动开发》——i2c协议(代码1)
来源:互联网 发布:dnz端口 编辑:程序博客网 时间:2024/05/29 11:21
/* 代码清单8-2 *//* 初始化EEPROM驱动程序 *//* Driver entry points */static struct file_operation eep_fops = {.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 *//* ... */};#define NUM_BANKS 2/* Two supported banks */#define BANK_SIZE 2048/* Size of each bank */struct eep_bank *ee_bank_list;/* List of private data structures,one per bank *//* Device Initialization */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_numbers, 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, &eep_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 out 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;}
0 0
- 《精通Linux设备驱动开发》——i2c协议(代码1)
- 《精通Linux设备驱动程序开发》——I2C
- Linux设备驱动篇——[I2C设备驱动-1]
- linux下 i2c设备驱动开发(1)
- 《Linux设备驱动开发详解》——I2C核心、总线与设备驱动
- Linux设备驱动——I2C总线
- Linux I2C设备驱动(一)——物理拓扑结构与协议
- 《精通Linux设备驱动程序开发》——Linux无线设备驱动
- Linux下I2C设备驱动开发和实现(转)
- linux下 i2c设备驱动开发(2)
- linux i2c设备驱动
- Linux I2C 设备驱动
- linux i2c设备驱动 .
- linux I2C设备驱动
- Linux 设备驱动 - I2C
- linux i2c设备驱动
- linux i2c设备驱动
- linux i2c设备驱动
- C++转换构造函数和隐式转换函数
- android4.4短信新概念
- C++异常处理
- 用loadrunner11写java脚本小例子(java Vuser) - 欢迎加易学QQ
- android发送get请求时报错
- 《精通Linux设备驱动开发》——i2c协议(代码1)
- 磁盘文件读入数组,处理后输入磁盘文件和屏幕
- 过山车 邻接表 匈牙利算法
- 【转】WebService JWS部署方法
- HDU 2046 骨牌铺方格
- 20复变函数的积分(六)
- MeasureSpec与自定义属性
- ov9650摄像头驱动之——linux内核v4l2架构分析1
- c++ release和debug编译后的结果不一致