U-Boot下的I2C设备的读写
来源:互联网 发布:淘宝如何设置花呗支付 编辑:程序博客网 时间:2024/06/18 07:56
在嵌入式中,I2C设备的使用比较广泛,U-Boot集成了i2c的操作函数及命令。如下
mpc8349@MITC> help i2c
i2c speed [speed] - show or set I2C bus speed
i2c dev [dev] - show or set current I2C bus
i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device
i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)
i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)
i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)
i2c crc32 chip address[.0, .1, .2] count - compute CRC32 checksum
i2c probe - show devices on the I2C bus
i2c reset - re-init the I2C Controller
i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device
i2c sdram chip - print SDRAM configuration information
mpc8349@MITC> i2c dev
Current bus is 1
mpc8349@MITC> iprobe
Valid chip addresses: 51 68
Excluded chip addresses: 20 21 38 39
mpc8349@MITC> imd 0x51 0.0
0000: 08 07 0d 0a 01 40 00 04 50 70 00 82 10 00 01 0e
一开始在板子上操作iprobe命令时,发现始终读写不了设备地址0x50,后来看了一下U-Boot实现i2c eeprom写HRCW的实现,
mpc8349@MITC> i2c dev 0
Setting bus to 0
mpc8349@MITC> iprobe
Valid chip addresses: 50
Excluded chip addresses:
mpc8349@MITC> imd 0x50 .2 17
0000: aa 55 aa 7c 02 40 04 04 00 00 7c 02 41 b4 60 a0
0010: 00 ff ff ff ff ff ff
mpc8349@MITC> imm 0x50 .2
00000000: ff ? aa
00000001: ff ? .
mpc8349@MITC> isdram 0x51
SPD data revision
Bytes used
Serial memory size
.....
在u-boot代码中如下实现HRCW对I2C EEPROM的写入。
// board/freescale/mpc8349itx/mpc8349itx.c
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300