I2C1和DS2460驅動

來源:互聯網
上載者:User
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.c656 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就沒有問題了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.