Chinaunix首页 | 论坛 | 博客
  • 博客访问: 532029
  • 博文数量: 116
  • 博客积分: 2063
  • 博客等级: 大尉
  • 技术积分: 1174
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-26 16:44
个人简介

none

文章分类

全部博文(116)

文章存档

2023年(2)

2020年(3)

2019年(4)

2018年(7)

2017年(6)

2016年(17)

2015年(13)

2014年(19)

2013年(6)

2012年(13)

2011年(5)

2010年(11)

2008年(10)

分类: 嵌入式

2012-08-01 09:52:51

At91sam9260ek with 2 available i2c device at addr 0x32 and 0x50, which works with linux-3.0

1: Use kernel included i2c-stub driver
cat linux-3.0/Documentation/i2c/i2c-stub 
... ...
... ...
The typical use-case is like this:
    1. load this module
    2. use i2cset (from the i2c-tools project) to pre-load some data
    3. load the target chip driver module
    4. observe its behavior in the kernel log
... ...
... ...
# insmod i2c-stub.ko chip_addr=0x50
# dmesg | grep "stub"
[   69.310000] i2c-stub: Virtual chip at 0x32
[  461.170000] i2c-stub: Virtual chip at 0x33
[ 2436.450000] i2c-stub: Virtual chip at 0x50

2: use only i2c-tools
After download i2c-tools-3.1.0.tar.bz2 finished and compile it for your device with crossCompile, u will got such useful CMD

[wenjing@centos6 linux-3.0]$ ls /tmp/test/sbin/    
i2cdetect  i2cdump  i2cget  i2cset  i2c-stub-from-dump

Before use those CMD MUST make sure unload the specified i2c device drivers, As my kerenel the struct ek_i2c_devices of file linux-3.0/arch/arm/mach-at91/board-sam9260ek.c is empty
   
static struct i2c_board_info __initdata ek_i2c_devices[] = {
#if 0
... ...
#endif
    /* more devices can be added using expansion connectors */
};

Or u will get following print infos
====================================================================================================
# ls /sys/devices/platform/i2c-gpio/i2c-0/
0-0032         0-004d         0-0050         delete_device  i2c-dev        name           new_device     power          subsystem      uevent
# ./i2cdetect i2c-gpio-1
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x03-0x77.
Continue? [Y/n] 
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- UU -- -- 
50: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
---------> UU  means this address is busy
#
# ./i2cdump i2c-gpio-1 0x32
No size specified (using byte-data access)
Error: Could not set address to 0x32: Device or resource busy

====================================================================================================
The correct infos from SYS Filesystem is

# ls /sys/devices/platform/i2c-gpio/i2c-0/
delete_device  i2c-dev        name           new_device     power          subsystem      uevent

And also following is correct info test with i2c-tools

# ./i2cdetect -l
i2c-0   i2c             i2c-gpio-1                              I2C adapter
# ./i2cdetect -F i2c-gpio-1
Functionalities implemented by /dev/i2c-0:
I2C                              yes
SMBus Quick Command              yes
SMBus Send Byte                  yes
SMBus Receive Byte               yes
SMBus Write Byte                 yes
SMBus Read Byte                  yes
SMBus Write Word                 yes
SMBus Read Word                  yes
SMBus Process Call               yes
SMBus Block Write                yes
SMBus Block Read                 yes
SMBus Block Process Call         yes
SMBus PEC                        yes
I2C Block Write                  yes
I2C Block Read                   yes
# ./i2cdetect i2c-gpio-1
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x03-0x77.
Continue? [Y/n] 
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- 32 -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
# ./i2cget 
Usage: i2cget [-f] [-y] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]
  I2CBUS is an integer or an I2C bus name
  ADDRESS is an integer (0x03 - 0x77)
  MODE is one of:
    b (read byte data, default)
    w (read word data)
    c (write byte/read byte)
    Append p for SMBus PEC
# ./i2cget i2c-gpio-1 0x50 1
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-0, chip address 0x50, data address
0x01, using read byte data.
Continue? [Y/n] 
0x41
# ./i2cget i2c-gpio-1 0x50 2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-0, chip address 0x50, data address
0x02, using read byte data.
Continue? [Y/n] 
0x43
# ./i2cget i2c-gpio-1 0x51 4
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-0, chip address 0x51, data address
0x04, using read byte data.
Continue? [Y/n] 
Error: Read failed
# ./i2cget i2c-gpio-1 0x32
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-0, chip address 0x32, current data
address, using read byte.
Continue? [Y/n] 
0x10
# ./i2cget i2c-gpio-1 0x32 1
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-0, chip address 0x32, data address
0x01, using read byte data.
Continue? [Y/n] 
0x16
# ./i2cget i2c-gpio-1 0x33 2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-0, chip address 0x33, data address
0x02, using read byte data.
Continue? [Y/n] 
Error: Read failed
#
#
# ./i2cdump i2c-gpio-1 0x50
No size specified (using byte-data access)
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0, address 0x50, mode byte
Continue? [Y/n] 
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 4d 41 43 3d 30 30 3a 30 30 3a 30 30 3a 61 31 3a    MAC=00:00:00:a1:
10: 33 63 3a 65 33 0a 20 20 20 20 20 20 20 20 20 20    3c:e3?          
20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                    
30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                    
40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                    
50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                    
60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                    
70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                    
80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                    
90: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                    
a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                    
b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                    
c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                    
d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                    
e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                    
f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0a                   ?
# ./i2cdump i2c-gpio-1 0x32
No size specified (using byte-data access)
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0, address 0x32, mode byte
Continue? [Y/n] 
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 12 12 12 12 10 10 10 10 12 12 12 12 12 12 12 12    ????????????????
10: 27 27 27 27 10 10 10 10 27 27 27 27 27 27 27 27    ''''????''''''''
20: 09 09 09 09 10 10 10 10 09 09 09 09 09 09 09 09    ????????????????
30: 04 04 04 04 10 10 10 10 04 04 04 04 04 04 04 04    ????????????????
40: 01 01 01 01 10 10 10 10 01 01 01 01 01 01 01 01    ????????????????
50: 08 08 08 08 10 10 10 10 08 08 08 08 08 08 08 08    ????????????????
60: 12 12 12 12 10 10 10 10 12 12 12 12 12 12 12 12    ????????????????
70: 00 00 00 00 10 10 10 10 00 00 00 00 00 00 00 00    ....????........
80: 00 00 00 00 10 10 10 10 00 00 00 00 00 00 00 00    ....????........
90: 00 00 00 00 10 10 10 10 00 00 00 00 00 00 00 00    ....????........
a0: 00 00 00 00 10 10 10 10 00 00 00 00 00 00 00 00    ....????........
b0: 00 00 00 00 10 10 10 10 00 00 00 00 00 00 00 00    ....????........
c0: 02 02 02 02 10 10 10 10 02 02 02 02 02 02 02 02    ????????????????
d0: 00 00 00 00 10 10 10 10 00 00 00 00 00 00 00 00    ....????........
e0: 00 00 00 00 10 10 10 10 00 00 00 00 00 00 00 00    ....????........
f0: 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10    ????????????????
# ./i2cdump i2c-gpio-1 0x4d
No size specified (using byte-data access)
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0, address 0x4d, mode byte
Continue? [Y/n] 
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
10: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
20: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
30: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
40: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
50: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
60: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
70: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
80: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
90: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
a0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
b0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
c0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
d0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
e0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
f0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
阅读(3126) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~