3.4.2內(nèi)核下I2C驅(qū)動(dòng)之24CXX實(shí)例
#include "linux/kernel.h"
#include "linux/module.h"
#include "linux/platform_device.h"
#include "linux/i2c.h"
#include "linux/err.h"
#include "linux/regmap.h"
#include "linux/slab.h"
static struct i2c_board_info at24cxx_info = {
};
static struct i2c_client *at24cxx_client;
static int at24cxx_dev_init(void)
{
}
static void at24cxx_dev_exit(void)
{
}
module_init(at24cxx_dev_init);
module_exit(at24cxx_dev_exit);
MODULE_LICENSE("GPL");
=================================================================
at24cxx_drv.c部分:
#include "linux/kernel.h"
#include "linux/module.h"
#include "linux/platform_device.h"
#include "linux/i2c.h"
#include "linux/err.h"
#include "linux/regmap.h"
#include "linux/slab.h"
#include "linux/fs.h"
#include "asm/uaccess.h"
static int major;
static struct class *class;
static struct i2c_client *at24cxx_client;
// 傳入: buf[0] : addr
// 輸出: buf[0] : data
//
static ssize_t at24cxx_read(struct file * file, char __user *buf, size_t count, loff_t *off)
{
}
// buf[0] : addr
// buf[1] : data
//
static ssize_t at24cxx_write(struct file *file, const char __user *buf, size_t count, loff_t *off)
{
}
static struct file_operations at24cxx_fops = {
};
static int __devinit at24cxx_probe(struct i2c_client *client,
{
}
static int __devexit at24cxx_remove(struct i2c_client *client)
{
}
static const struct i2c_device_id at24cxx_id_table[] = {
};
// 1. 分配/設(shè)置i2c_driver //
static struct i2c_driver at24cxx_driver = {
};
static int at24cxx_drv_init(void)
{
}
static void at24cxx_drv_exit(void)
{
}
module_init(at24cxx_drv_init);
module_exit(at24cxx_drv_exit);
MODULE_LICENSE("GPL");
=================================================================
i2c_test.c測(cè)試程序:
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
// i2c_test r addr
// i2c_test w addr val
void print_usage(char *file)
{
}
int main(int argc, char **argv)
{
}
================================================================
Makefile:
KERN_DIR = /work/system/linux-3.4.2
all:
clean:
obj-m += at24cxx_dev.o
obj-m += at24cxx_drv.o
#obj-m += i2c_bus_s3c2440.o
評(píng)論