主题 : mini6410 android 2.3上面调试camera 驱动,I2C无法正常通信 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 54599
精华: 0
发帖: 8
金钱: 40 两
威望: 8 点
综合积分: 16 分
注册时间: 2011-09-02
最后登录: 2012-06-15
楼主  发表于: 2011-12-29 16:06

 mini6410 android 2.3上面调试camera 驱动,I2C无法正常通信

我用的是android2.3的源码,20111022发布的。在camera fimc驱动部分,我自己增加了一款sensor的驱动。做了如下修改:
(1)mach_mini6410.c:static struct i2c_board_info i2c_devs0[] __initdata = {
    //{ I2C_BOARD_INFO("ov965x", 0x30), },
    { I2C_BOARD_INFO("ov7725", 0x21), },
(2)config_android_a70:CONFIG_OV7725=y
                                           CONFIG_VIDEO_FIMC_CAM_RESET=0  //原先为1
(3)驱动部分代码如下:

static int ov7725_reg_read(struct i2c_client *client, unsigned char reg, unsigned char *val)
{
    int ret;
    unsigned char data[1] = {0};
    struct i2c_msg msg = {
        .addr    = client->addr,
        .flags    = 0,
        .len    = 1,
        .buf    = data,
    };
    int retry = 0;

    data[0] = reg;
    do {
        ret = i2c_transfer(client->adapter, &msg, 1);
        if (ret == 1)
            return 0;
        retry++;
        info("ov7725 : i2c transfer failed, retrying ret=%d\n",ret);
        msleep(3);
    } while (retry <= 10);


    msg.flags = I2C_M_RD;
    msg.len = 1;
    ret = i2c_transfer(client->adapter, &msg, 1);
    if (ret < 0)
    {
        info("%s i2c_transfer:2 ret = %d\n", __FUNCTION__, ret);
        goto err;
    }

    *val = data[0];

    info("%s 0x%04x = 0x%02x\n", __FUNCTION__, reg, data[0]);
    return 0;

err:
    dev_err(&client->dev, "Failed reading register 0x%02x!\n", reg);
    return ret;
}
static int ov7725_detect(struct i2c_client *client)
{
  unsigned char id_check[2] = {0};
  

  ov7725_reg_read(client, 0x0A, &id_check[0]);
  ov7725_reg_read(client, 0x0B, &id_check[1]);

  if((id_check[0] != 0x77) || (id_check[1] != 0x21))
    return -1;
    dev_info(&client->dev, "Detected a ov7725 chip\n");

  return 0;
}
static int ov7725_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
    struct ov7725_state *ov7725_state;
    struct v4l2_subdev *sd;
    int ret;

    info("****************%s****************\n", __func__);
    ov7725_state = kzalloc(sizeof(struct ov7725_state), GFP_KERNEL);
    if (ov7725_state == NULL)
    {
        info("*************ov7725:ov7725_state == NULL*****************\n");
        return -ENOMEM;
    }

    ov7725_state->i2c_client = client;
    sd = &ov7725_state->sd;
    strcpy(sd->name, "ov7725");

    /* Registering subdev */
    v4l2_i2c_subdev_init(sd, client, &ov7725_ops);
    
    ret = ov7725_detect(client);
    if (ret) {
        dev_info(&client->dev, "ov7725 sensor not found\n");
        goto err;
    }

    info("*************ov7725 has been probed*****************\n");
    return 0;
err:
    kfree(ov7725_state);
    info("*************ov7725 probed error:ret=%d*****************\n",ret);
    return 0;
}

static int ov7725_remove(struct i2c_client *client)
{
    struct v4l2_subdev *sd = i2c_get_clientdata(client);
    info("****************%s****************\n", __func__);
    v4l2_device_unregister_subdev(sd);
    kfree(to_state(sd));
    return 0;
}

static const struct i2c_device_id ov7725_id[] = {
    { "ov7725", 0 },
    { },
};
MODULE_DEVICE_TABLE(i2c, ov7725_id);

static struct v4l2_i2c_driver_data v4l2_i2c_data = {
    .name = "ov7725",
    .probe = ov7725_probe,
    .remove = ov7725_remove,
    .id_table = ov7725_id,
};

代码已成功编译到FIMC驱动中去,并且开机的时候跑到了probe函数,但是在跑到i2c_transfer的时候执行adap->algo->master_xfer(adap, msgs, num)返回-6,
我查了这个错误是no such device or address,
但是我测试三路电压都是正常的,并且同样的sensor和硬件设备我在android2.1上面是可以跑起来的,所以硬件应该没有问题吧。

我现在不知道问题出在哪了,请求各位大侠指点,不胜感激!
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2011-12-29 21:19
看起来像是I2C通信过程中出错,我想你可以在drivers/i2c/busses/i2c-s3c2410.c头上加上“#define DEBUG 1”来输出更多的调试信息。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
try
级别: 新手上路
UID: 73201
精华: 0
发帖: 42
金钱: 210 两
威望: 42 点
综合积分: 84 分
注册时间: 2012-07-05
最后登录: 2013-06-19
2楼  发表于: 2012-07-19 17:14
哥们  结果怎么样了?