Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1229099
  • 博文数量: 479
  • 博客积分: 12240
  • 博客等级: 上将
  • 技术积分: 4999
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-24 17:12
文章分类

全部博文(479)

文章存档

2014年(1)

2013年(1)

2012年(1)

2011年(95)

2010年(177)

2009年(167)

2008年(16)

2007年(21)

分类: LINUX

2010-01-09 10:46:54


I2C1 和 DS2460驱动

Linux 2.6.27在i2c上没有2.6.29上成熟,不能按照那一套来做,譬如在board-smartarm.c中增加:
499 //static struct i2c_board_info __initdata smartarm3250_i2c_ds2460_info [] = {
500 //  {
501 //      I2C_BOARD_INFO("epc-ds2460", 0x40),
502 //  },
503 //};

698     /* I2C based DS2460 on I2C1 */
699 //  i2c_register_board_info(0, smartarm3250_i2c_ds2460_info,
700 //              ARRAY_SIZE(smartarm3250_i2c_ds2460_info));
这是行不通的。

只能来硬的,直接在i2c驱动中增加i2c器件的绑定:
drivers/i2c/busses/i2c-pnx.c
656 if (pdev->id == 1) { //I2C2

657 struct i2c_board_info info = {
658 I2C_BOARD_INFO("pcf8563", 0xa3 >> 1),
659 };
660 client = i2c_new_device(i2c_pnx->adapter, &info);
661
662 if (client == NULL) {
663 printk("check pcf8563 failed \n");
664 }
665 }
666
667 if (pdev->id == 0) { //I2C1

668 struct i2c_board_info info2 = {
669 I2C_BOARD_INFO("ds2460", 0x80 >> 1),
670  };
671 client = i2c_new_device(i2c_pnx->adapter, &info2);
672
673 if (client == NULL) {
674 printk("check ds2460 failed \n");
675  }
676 }

注意,这里的I2C_BOARD_INFO中的名称一定要与ds2460.c的id表中的一致,否则无法注册。

另外,郁闷的事情还在后面,读取EEPROM的时候,使用了i2c_transfer函数,结果老是读取出错,然而这个读取函数在OMAP3530上是没有任何问题的,代码如下:
25 int read_from_ds2460(unsigned char *kbuf, int start_addr, int len)
 26 {
 27 unsigned char tempbuf[8] = {start_addr};
 28 int i;
 29 int ret = 0;
 30
 31 // printk("###ABING in %s %d\n", __FUNCTION__, __LINE__);

 32 #if 0
 33 struct i2c_msg msgs[] = {
 34 { ds2460_client->addr, 0, 1, tempbuf }, /* setup read ptr -- start_addr */
 35 { ds2460_client->addr, I2C_M_RD, len, kbuf }, /* read from ds2460 */
 36 };
 37
 38 if (kbuf == NULL) {
 39 printk("a NULL pointer found!\n");
 40 return -ENOSYS;
 41 }
 42
 43 return i2c_transfer(ds2460_client->adapter, msgs, 2);
 44 #else
 45
 46 ret = i2c_master_send(ds2460_client, tempbuf, 1);
 47 if (ret < 0) {
 48 printk("I2C err: %s, %d send data to i2c bus failed \n", __FUNCTION__,__LINE__);
 49 return ret;
 50 }
 51
 52 ret = i2c_master_recv(ds2460_client, kbuf, len);
 53 if (ret < 0) {
 54 printk("I2C err: %s, %d get i2c bus data failed \n", __FUNCTION__,__LINE__);
 55 return ret;
 56 }
 57
 58 return 0;
 59 #endif
 60 }

改为i2c_master_send和i2c_master_recv就没有问题了。


阅读(3597) | 评论(0) | 转发(1) |
0

上一篇:如何处理BOOL类型

下一篇:UART2引脚配置

给主人留下些什么吧!~~