[i.MX] i2c slave设备读写没有ack返回

[复制链接]
7196|2
 楼主| yueyesighhz 发表于 2014-12-17 15:10 | 显示全部楼层 |阅读模式
本帖最后由 yueyesighhz 于 2014-12-17 15:12 编辑

我用TI的TCA8424,在board文件中定义如下:
  1. static struct imxi2c_platform_data mxci2c_data = {
  2.        .bitrate = 20000,
  3. };

  4. static struct tca8424_keypad_platform_data tca8424_date = {
  5.         .keymap_data = &tca8424_mkdata,
  6.         .rows=16,
  7.         .cols=8,
  8.         .rep=1,
  9.         .irq_is_gpio=1,
  10. };

  11. static struct i2c_board_info mxc_i2c2_board_info[] __initdata = {
  12.         {
  13.                 I2C_BOARD_INFO("rtc-pcf8563", 0x51),
  14.                 .type = "pcf8563"
  15.         },
  16.         {
  17.         I2C_BOARD_INFO("tca8424_keypad", 0x3b),
  18.         .type = "tca8424_keypad" ,
  19.         .irq  = MX53_TCA6416_IRQ,
  20.         .platform_data = &tca8424_date
  21.     },
  22. };
设备地址是7位的,可以肯定是3b。照我的理解这样注册之后,就应该可以和i2c通信了,但是在probe函数中读写i2c就会失败。查看日子是没有ack。

  1. static int tca8424_keypad_probe(struct i2c_client *client,
  2.                                           const struct i2c_device_id *id)
  3. {
  4.          struct device *dev = &client->dev;
  5.          const struct tca8424_keypad_platform_data *pdata =
  6.                                                  dev_get_platdata(dev);
  7.          struct tca8424_keypad *keypad_data;
  8.          struct input_dev *input;
  9.          const struct matrix_keymap_data *keymap_data = NULL;
  10.          u32 rows = 0, cols = 0;
  11.          bool rep = false;
  12.          bool irq_is_gpio = false;
  13.          int irq;
  14.          int error, row_shift, max_keys;

  15. #if 1
  16.         /* Copy the platform data */
  17.         if (pdata) {
  18.                 if (!pdata->keymap_data) {
  19.                         dev_err(dev, "no keymap data defined\n");
  20.                         return -EINVAL;
  21.                 }
  22.                 keymap_data = pdata->keymap_data;
  23.                 rows = pdata->rows;
  24.                 cols = pdata->cols;
  25.                 rep  = pdata->rep;
  26.                 irq_is_gpio = pdata->irq_is_gpio;
  27.         }/* else {
  28.                 struct device_node *np = dev->of_node;
  29.                 int err;

  30.                 err = matrix_keypad_parse_of_params(dev, &rows, &cols);
  31.                 if (err)
  32.                         return err;
  33.                 rep = of_property_read_bool(np, "keypad,autorepeat");
  34.         }*/

  35.         if (!rows || rows > TCA8424_MAX_ROWS) {
  36.                 dev_err(dev, "invalid rows\n");
  37.                 return -EINVAL;
  38.         }

  39.         if (!cols || cols > TCA8424_MAX_COLS) {
  40.                 dev_err(dev, "invalid columns\n");
  41.                 return -EINVAL;
  42.         }

  43.         /* Check i2c driver capabilities */
  44.         if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
  45.                 dev_err(dev, "%s adapter not supported\n",
  46.                         dev_driver_string(&client->adapter->dev));
  47.                 return -ENODEV;
  48.         }

  49.         row_shift = get_count_order(cols);
  50.         max_keys = rows << row_shift;

  51.         /* Allocate memory for keypad_data and input device */
  52.         keypad_data = devm_kzalloc(dev, sizeof(*keypad_data), GFP_KERNEL);
  53.         if (!keypad_data)
  54.                 return -ENOMEM;

  55.         keypad_data->client = client;
  56.         keypad_data->row_shift = row_shift;
  57. //        printk("^^^^^^^^^^^\n",keypad_data->);

  58.         i2c_set_clientdata(client, keypad_data);

  59.         /* Initialize the chip or fail if chip isn't present */
  60.         error = tca8424_configure(keypad_data, rows, cols);
  61.         if (error < 0)
  62.                 return error;
  63. #endif
  64.         /* Configure input device
  65.         input = devm_input_allocate_device(dev);
  66.         if (!input)
  67.                 return -ENOMEM;*/

  68.         keypad_data->input = input;
  69.         input = input_allocate_device();
  70.         if (!input) {
  71.                 error = -ENOMEM;
  72.                 return error;
  73.         }
  74.         printk("2-----row = %d,cols = %d\n",rows,cols);


  75.         input->phys = "tca8424-keys/input0";
  76.         input->name = client->name;
  77.         input->id.bustype = BUS_I2C;
  78.         input->id.vendor  = 0x0001;
  79.         input->id.product = 0x0001;
  80.         input->id.version = 0x0001;

  81.         input->keycode = keymap_data->keymap;
  82.         printk("3----------%d,keymap[0]=%d | %d\n",keymap_data->keymap_size,keymap_data->keymap[1],KEY(0, 6, KEY_RESERVED));

  83.         matrix_keypad_build_keymap(keymap_data, row_shift, input->keycode, input->keybit);
  84.         if (!input->keybit) {
  85.                 dev_err(dev, "Failed to build keymap\n");
  86.                 return error;
  87.         }
  88.         
  89.         if (rep)
  90.                 __set_bit(EV_REP, input->evbit);
  91.         input_set_capability(input, EV_MSC, MSC_SCAN);

  92.         input_set_drvdata(input, keypad_data);

  93.         irq = client->irq;
  94.         if (irq_is_gpio)
  95.                 irq = gpio_to_irq(irq);

  96.         printk("5----------%d,%d\n",irq,!tca8424_irq_handler);
  97.         error = devm_request_threaded_irq(dev, irq, NULL, tca8424_irq_handler,
  98.                                           IRQF_TRIGGER_FALLING |
  99. //                                                IRQF_SHARED |
  100.                                                 IRQF_ONESHOT,
  101.                                           client->name, keypad_data);
  102.         if (error) {
  103.                 dev_err(dev, "Unable to claim irq %d; error %d\n",
  104.                         client->irq, error);
  105.                 return error;
  106.         }

  107.         error = input_register_device(input);
  108.         if (error) {
  109.                 dev_err(dev, "Unable to register input device, error: %d\n",
  110.                         error);
  111.                 return error;
  112.         }
  113.         printk("[TCA8424] tca8424_keypad_probe.\n");
  114.         return 0;
  115. }
里面的tca8424_configure()函数就有读写i2c:
        error = i2c_smbus_write_byte_data(keypad_data->client,REG_COMMAND_REG_L,COMMAND_RESET);
        if(error < 0)
                printk("reset device error!\n");

串口打印:
[   38.293434] i2c i2c-2: master_xfer[0] W, addr=0x43, len=2
[   38.301546] i2c i2c-2: <i2c_imx_xfer>
[   38.305247] i2c i2c-2: <i2c_imx_start>
[   38.309079] i2c i2c-2: <i2c_imx_bus_busy>
[   38.313105] i2c i2c-2: <i2c_imx_xfer> transfer message: 0
[   38.318522] i2c i2c-2: <i2c_imx_xfer> CONTROL: IEN=1, IIEN=1, MSTA=1, MTX=1, TXAK=1, RSTA=0
[   38.326890] i2c i2c-2: <i2c_imx_xfer> STATUS: ICF=1, IAAS=0, IBB=1, IAL=0, SRW=0, IIF=0, RXAK=1
[   38.335660] i2c i2c-2: <i2c_imx_write> write slave address: addr=0x86
[   38.342748] i2c i2c-2: <i2c_imx_trx_complete> TRX complete
[   38.348252] i2c i2c-2: <i2c_imx_acked> No ACK
[   38.352619] i2c i2c-2: <i2c_imx_stop>
[   38.356291] i2c i2c-2: <i2c_imx_bus_busy>
[   38.360313] i2c i2c-2: <i2c_imx_xfer> exit with: error: -5
[   38.365815] tca8424_keypad 2-0043: tca8424_write_byte failed, reg: 1536, val: 27, error: -5

请问可能是什么原因导致从设备没有返回ACK呢?
FSL_TICS_Rita 发表于 2014-12-17 15:46 | 显示全部楼层
楼主你好,请问你这里使用的是哪块板子呢?
 楼主| yueyesighhz 发表于 2014-12-17 15:57 | 显示全部楼层
FSL_TICS_Rita 发表于 2014-12-17 15:46
楼主你好,请问你这里使用的是哪块板子呢?

imx53_loco的板子,我也根据网上所说的,将i2c3的引脚配置做了修改:

  1. #undef MX53_PAD_GPIO_5__I2C3_SCL
  2. #undef _MX53_PAD_GPIO_5__I2C3_SCL
  3. #define _MX53_PAD_GPIO_5__I2C3_SCL                IOMUX_PAD(0x6C0, 0x330, 6| IOMUX_CONFIG_SION, 0x824, 2, 0)
  4. #define MX53_PAD_GPIO_5__I2C3_SCL                (_MX53_PAD_GPIO_5__I2C3_SCL | MUX_PAD_CTRL(NO_PAD_CTRL))
您需要登录后才可以回帖 登录 | 注册

本版积分规则

11

主题

80

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部