I2c regmap_read issue

Hi all,

I am using Jetson Nano development kit with latest sdk. L4T-32.4.3
The query , i have might be bit different , but let me try to explain.

We have interfaced one imx219 camera with jetson nano, which is running absolutely fine with the default imx219.c driver provided by nvidia.

We got to know that, there is an temperature sensor in IMX219 which is register - 0x0140. The temperature register will give the temperature data once camera streaming is started.

So, from command line we just use “i2ctransfer” commands to read the value & we are able to get the value.

Commands are:
sudo i2ctransfer -f -y 6 w3@0x10 0x01 0x40 0x80
sudo i2ctransfer -f -y 6 w2@0x10 0x01 0x40 r1

Now my query starts, when i tried to do the same from imx219.c driver , i dont get the same result.

I have just created sysfs file to enable the temperature register by writing 0x80 to the register & then read the register again. All i got is the same value “0x80” from the register while i was expecting to get some other temperature data similar to i2ctransfer command.

Code snippet:
static ssize_t imx219_temp_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
int err=0;
u8 dev_temp_val = 0;
struct camera_common_data *s_data = tc_dev2->s_data;

    err = imx219_write_reg(s_data, IMX219_TEMP,  0x80);
    
    if(err)
            printk("error writing temp. reg\n");

    imx219_read_reg(s_data, IMX219_TEMP, &dev_temp_val);
    return sprintf(buf, "%d\n", dev_temp_val);

}

Any suggestion on the above issue. @ShaneCCC

Not really understand the problem, do you mean using the tools read value is different read from the driver?

How do you have i2ctransfer work without power on the sensor?

Apologies for not being clear !!
Let me try to explain again.

Our objective is to read the inbuilt temperature sensor data from IMX219 camera.
Register to measure temperature value : 0x0140

Now as per the data sheet of IMX219, we can read the temperature register after streaming of camera.
Once the streaming is started, we have to enable the temperature register to measurement mode & then read the value from it.

For validation, we have used gstreamer command to stream the imx219 camera in one terminal & in another terminal we used “i2ctransfer” commands to enable & read temperature register.

Commands are :
sudo i2ctransfer -f -y 6 w3@0x10 0x01 0x40 0x80 --> To enable temperature measurement mode
sudo i2ctransfer -f -y 6 w2@0x10 0x01 0x40 r1 --> Reads the temperature value. For. eg: 0x32 and so on.

Now, instead of using i2ctransfer command, we want to do the same from imx219 driver. So, we are using imx219_write_reg() & imx219_read_reg() to write/read the temperature register.

Followed the same process to first enable the temperature measurement by writing “0x80” to temperature register & then read back from it.

err = imx219_write_reg(s_data, IMX219_TEMP,  0x80);

if(err)
        printk("error writing temp. reg\n");

imx219_read_reg(s_data, IMX219_TEMP, &dev_temp_val);
return sprintf(buf, "%d\n", dev_temp_val);

Reading the register here, should give us some temperature value , whereas it only gives us what we have written to it.

I have attached the snapshot of temperature register from IMX219 datasheet.

Please add some delay between the reg write and read in your driver.

HI ShaneCCC

We found that problem was with regmap_read() . The cache was not cleared. So we just used cache_bypass & got the updated readings from the register. Yes a delay of 0.5 sec required between write & read.

Thanks for the support .

Best regards
Surya