Esempio n. 1
0
static int tcm9001md_sensor_init_probe(const struct msm_camera_sensor_info *data)
{
    int rc = 0;
    unsigned char v = 0;
    printk("tcm9001md_sensor_init_probe: Entry.\n");

    printk("tcm9001md_sensor_init_probe entry.\n");
    sensor_init_parameters(data,&tcm9001md_parameters);

#ifdef CONFIG_TCM9001MD_STANDBY
    if (tcm9001md_first_init == 1)
    {
        tcm9001md_first_init = 0;

        rc = tcm9001md_power_on();
        if (rc < 0)
        {
            printk("tcm9001md_sensor_init_probe: ERR: tcm9001md_power_on() failed for first init !\n");
            goto init_probe_fail;
        }
    }
    else
    {
        rc = tcm9001md_sensor_standby(0);
        if (rc < 0)
        {
            printk("tcm9001md_sensor_init_probe: ERR: tcm9001md_sensor_standby(0) failed !\n");
            goto init_probe_fail;
        }
    }
#else
    rc = tcm9001md_power_on();
    if (rc < 0)
    {
        printk("tcm9001md_sensor_init_probe: ERR: tcm9001md_power_on() failed !\n");
        goto init_probe_fail;
    }
#endif

    rc = tcm9001md_reg_init();
    if (rc < 0)
    {
        rc = - EIO;
        printk("tcm9001md_sensor_init_probe: ERR: tcm9001md_reg_init() failed, err = %d !\n", rc);
        goto init_probe_fail;
    }

    // Here to check chip version identification.
    rc = tcm9001md_i2c_read(tcm9001md_client, REG_TCM9001MD_MODEL_ID_1, &v);
    if (rc < 0 || v != TCM9001MD_MODEL_ID_1)
    {
        printk("tcm9001md_sensor_init_probe: ERR: Red MODEL_ID_1 = 0x%x failed !\n", v);
        goto init_probe_fail;
    }
    printk("tcm9001md_sensor_init_probe: MODEL_ID_1 = 0x%x .\n", v);

    rc = tcm9001md_i2c_read(tcm9001md_client, REG_TCM9001MD_MODEL_ID_2, &v);
    if (rc < 0 || v != TCM9001MD_MODEL_ID_2)
    {
        printk("tcm9001md_sensor_init_probe: ERR: Red MODEL_ID_2 = 0x%x failed !\n", v);
        goto init_probe_fail;
    }
    printk("tcm9001md_sensor_init_probe: MODEL_ID_2 = 0x%x .\n", v);

    return rc;

init_probe_fail:
    printk("tcm9001md_sensor_init_probe: ERR: FAIL !\n");
    return rc;
}
static int tcm9001md_sensor_init_probe(const struct msm_camera_sensor_info *data)
{
    int rc = 0;
    unsigned char v = 0;
    uint16_t retry_count = 0;
    printk("tcm9001md_sensor_init_probe: Entry.\n");

    sensor_init_parameters(data,&tcm9001md_parameters);

#ifdef CONFIG_TCM9001MD_STANDBY
    if (tcm9001md_first_init == 1)
    {
        printk("tcm9001md_sensor_init_probe: tcm9001md_first_init = 1 ...\n");

        rc = tcm9001md_power_on();
        if (rc < 0)
        {
            printk("tcm9001md_sensor_init_probe: ERR: tcm9001md_power_on() failed for first init !\n");
            goto init_probe_fail;
        }
    }
    else
    {
        rc = tcm9001md_sensor_standby(0);
        if (rc < 0)
        {
            printk("tcm9001md_sensor_init_probe: ERR: tcm9001md_sensor_standby(0) failed !\n");
            tcm9001md_power_off();
            msleep(200);
            tcm9001md_power_on();
            printk("tcm9001md_sensor_init_probe: Reset sensor power for re-init ~~\n");
        }
        else
        {
            printk("tcm9001md_sensor_init_probe: Exit SW standby success !\n");
        }
    }
#else
    rc = tcm9001md_power_on();
    if (rc < 0)
    {
        printk("tcm9001md_sensor_init_probe: ERR: tcm9001md_power_on() failed !\n");
        goto init_probe_fail;
    }
#endif

    rc = tcm9001md_reg_init();
    if (rc < 0)
    {
        do 
        {
            tcm9001md_power_off();
            msleep(200);
            tcm9001md_power_on();
            rc = tcm9001md_reg_init();
            retry_count++;
            printk("hm0357_sensor_init_probe  retry_count = 0x%d\n", retry_count);
        } 
        while((rc < 0)&&(retry_count<3));

        if(rc < 0)
        {
            rc = - EIO;
            printk("tcm9001md_sensor_init_probe: ERR: tcm9001md_reg_init() failed, err = %d !\n", rc);
            goto init_probe_fail;
        }
    }
    

    // Here to check chip version identification.
    rc = tcm9001md_i2c_read(tcm9001md_client, REG_TCM9001MD_MODEL_ID_1, &v);
    if (rc < 0 || v != TCM9001MD_MODEL_ID_1)
    {
        printk("tcm9001md_sensor_init_probe: ERR: Red MODEL_ID_1 = 0x%x failed !\n", v);
        goto init_probe_fail;
    }
    printk("tcm9001md_sensor_init_probe: MODEL_ID_1 = 0x%x .\n", v);

    rc = tcm9001md_i2c_read(tcm9001md_client, REG_TCM9001MD_MODEL_ID_2, &v);
    if (rc < 0 || v != TCM9001MD_MODEL_ID_2)
    {
        printk("tcm9001md_sensor_init_probe: ERR: Red MODEL_ID_2 = 0x%x failed !\n", v);
        goto init_probe_fail;
    }
    printk("tcm9001md_sensor_init_probe: MODEL_ID_2 = 0x%x .\n", v);

    return rc;

init_probe_fail:
    printk("tcm9001md_sensor_init_probe: ERR: FAIL !\n");
    return rc;
}