The driver for AT24C08 is already available in the Linux kernel, in the/drivers/misc/eeprom/at24.c file. There is a function in the corresponding probe function that creates the/sys/.../eeprom file, and the application reads and writes the device by invoking the/sys/.../eeprom device file.
Porting AT24C08 Drivers
1. Modify the kernel register EEPROM device
The IIC equipment is registered under Machine_init in KERNEL/LINUX-MINI2440/ARCH/ARM/MACH-S3C2440.C.
Mach-mini2440.c
Static structAt24_platform_data AT24C08 ={. Byte_len=8192/8,//byte length. page_size =8,//size per page. Flags =0};Static structI2c_board_info __initdata mini2440_i2c_devices[] ={{I2c_board_info ("24C08",0x50),//"24C08" means model, 0x50 means address. Platform_data = &AT24C08}};Static void__init Mini2440_machine_init (void) {I2c_register_board_info (0, Mini2440_i2c_devices,array_size (mini2440_i2c_devices));}
2. Configuring Kernel support EEPROM Driver
Make Menuconfig Arch=arm
Device Drivers->[*]misc Devices->eeprom support->
<*>I2C eeproms Form Most venders->exit->save
Make Uimage arch=arm cross_compile=arm-linux-
3. Download the kernel to the Development Board
The/sys/bus/i2c/devices/0-0050/eeprom file is the EEPROM device file registered by the kernel. 0x50 corresponds to 0-0050 folder, 24c08 corresponding EEPROM file.
I2capp.c
#include <stdio.h>#include<sys/types.h>#include<sys/stat.h>#include<fcntl.h>#include<unistd.h>intMainintargcChar**argv) { //Open File intFD; FD= Open ("/sys/bus/i2c/devices/0-0050/eeprom", O_RDWR); if(FD <0) {printf ("error\n"); return-1; } //Write Data inti; unsignedCharwrdata[Ten]; for(i =0; I <Ten; i++) {Wrdata[i]=i; } lseek (FD,0, Seek_set); Write (FD, Wrdata,Ten); //reading DataUnsignedCharrddata[Ten]; Lseek (FD,0, Seek_set); Read (FD, Rddata,Ten); for(i =0; I <Ten; i++) {printf ("%d", Rddata[i]); } printf ("\ n"); //Close FileClose (FD); return 0;}
[Country EMBED strategy] [156] [I²c self-coding device drive design]