This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/AM5718: i2c register read/write using ov490 driver

Part Number: AM5718

Tool/software: Linux

Hello everyone,

we are using the i2c subdev(ov490) driver for reference to developed our driver on am5718 custom board. We have lots of try to direct read write the i2c register of sensor but we are failed so now we have added the below api in ov490 driver. Note: we have enable "CONFIG_VIDEO_ADV_DEBUG" macro using menuconfig.

static int ar1335_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
{
    u16 val = 0;
    int ret;
    struct i2c_client *client = cli;
    
    printk("%d - %s() \n", __LINE__, __FUNCTION__ );

    ret=AR1335_reg_read_test(client, reg->reg & 0xff, &val);
    reg->val = val;
    reg->size = 1;
    return ret;
}

static int ar1335_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
{
    struct i2c_client *client = cli;
    printk("%d - %s() \n", __LINE__, __FUNCTION__ );
    ar1335_write_reg(client, AR1335_16BIT, reg->reg & 0xff, reg->val & 0xff);
    
    return 0;
}


static const struct v4l2_subdev_core_ops AR1335_core_ops = {
    .log_status        = v4l2_ctrl_subdev_log_status,
    .subscribe_event    = v4l2_ctrl_subdev_subscribe_event,
    .unsubscribe_event    = v4l2_event_subdev_unsubscribe,
    .g_register        = ar1335_g_register,
    .s_register        = ar1335_s_register,
};

We have used the below sample application to check the ar1335_g_register ioctl call.

#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <linux/videodev2.h>
#include <string.h>
#include <stdio.h>

int main()
{
    int ret=0;
    int fd = open("/dev/video0", O_RDWR);
    printf("FD:- %d\n",fd);

    struct v4l2_dbg_register cap;
    memset(&cap, 0, sizeof(cap));
   
    
    ret=ioctl(fd, VIDIOC_DBG_G_REGISTER, &cap);
    
     printf("ret: %d \n",ret);
}

Please help us to solve the above issue

  • Hello,

    Nikunj Patel said:
    Note: we have enable "CONFIG_VIDEO_ADV_DEBUG" macro using menuconfig.

    But I do not see it in the code that you have shared. For exmaple:

    #ifdef CONFIG_VIDEO_ADV_DEBUG

    .g_register =ar1335_g_register,

    .s_register =ar1335_g_register,

    #endif

    Please take a look into ov772x.c for example. Hope it is helpful for you.

    BR
    Margarita

  • Hi Margartita,

    We have done same changes as ov772x driver but still same issue.

    Now we have to checked the "v4l_dbg_g_register" api of "/drivers/media/v4l2-core/v4l2-ioctl.c" file but we  got the "null" value of "sd->ops".

    and due to that "return v4l2_subdev_call(sd, core, g_register, p)" call got failed and then kernel crash with below error.

    [  251.656054] Unable to handle kernel NULL pointer dereference at virtual address 00000000

    [  251.664931] pgd = ed20ccc0

    [  251.667650] [00000000] *pgd=ad2a2003, *pmd=bc059003

    [  251.673296] Internal error: Oops: 207 [#1] PREEMPT SMP ARM

    [  251.678805] Modules linked in: ov490 dwc3 udc_core usb_common snd_soc_simple_card snd_soc_simple_card_utils snd_soc_omap_hdmi_audio omap_aes_driver ahci_platform libahci_platform omap_sham libahci omap_wdt libata scsi_mod rtc_o)

    [  251.714910] CPU: 0 PID: 406 Comm: v4l2-dbg Tainted: G           O    4.9.59-ga75d8e9305 #343

    [  251.723384] Hardware name: Generic DRA72X (Flattened Device Tree)

    [  251.729501] task: ed2b4c80 task.stack: ed2b0000

    [  251.734056] PC is at v4l_dbg_g_register+0x17c/0x1fc

    [  251.738959] LR is at irq_work_queue+0xc0/0xd4

    [  251.743334] pc : [<c06e10a8>]    lr : [<c02c1170>]    psr: 60070013

    [  251.743334] sp : ed2b1d70  ip : ed2b1c30  fp : ed2b1d9c

    [  251.754860] r10: ecd8b900  r9 : 00000000  r8 : ece4b0b0

    [  251.760104] r7 : ed20c4c0  r6 : c0c01e8c  r5 : ece4afc8  r4 : ed2b1e18

    [  251.766656] r3 : 00000000  r2 : 00000000  r1 : ef692420  r0 : c0c01f9c

    [  251.773210] Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user

    [  251.780374] Control: 30c5387d  Table: ad20ccc0  DAC: fffffffd

    [  251.786142] Process v4l2-dbg (pid: 406, stack limit = 0xed2b0210)

    [  251.792259] Stack: (0xed2b1d70 to 0xed2b2000)

    [  251.796633] 1d60:                                     c02014a0 c027f44c c08d540c 00000003

    [  251.804846] 1d80: c0385650 ece4b0b0 c06e0f2c c103e910 ed2b1e04 ed2b1da0 c06e3254 c06e0f38

    [  251.813058] 1da0: c108c628 a00e0013 00000140 00000000 c103efac ed20c4c0 ed2b1e18 ed20c4c0

    [  251.821271] 1dc0: 00000000 ec4e81f8 ed2b1de4 ed2b1dd8 c059f628 c05a6504 ed2b1e1c c0385650

    [  251.829484] 1de0: 00000038 00000038 ed2b1e18 beac19f8 00000000 00000003 ed2b1ec4 ed2b1e08

    [  251.837694] 1e00: c06e2c70 c06e2fc8 ecee9600 00000000 c06e2fbc ecd8b900 00000004 00000000

    [  251.845907] 1e20: b6f23880 b6f23958 beac1ba0 00000000 00000000 00010684 00010684 00000000

    [  251.854119] 1e40: 00000002 00000000 00000000 00000000 ed2b4c80 ecee9600 ec607828 0000001d

    [  251.862331] 1e60: 00035f4d 0000001d ed2b1e8c ed2b1e78 ed2b1e8c ed2b1e80 c058c328 c058e754

    [  251.870543] 1e80: ed2b1ed4 ed2b1e90 c0584140 c058c31c 00000a07 0000001d ecee1bc0 ece4b0b0

    [  251.878755] 1ea0: ecd8b900 c0385650 beac19f8 ece4b4a8 ed2b0000 00000000 ed2b1ed4 ed2b1ec8

    [  251.886966] 1ec0: c06e2fb8 c06e2af0 ed2b1efc ed2b1ed8 c06dd870 c06e2fac beac19f8 ece3f9c0

    [  251.895178] 1ee0: ecd8b900 00000003 beac19f8 ed2b0000 ed2b1f7c ed2b1f00 c03418fc c06dd7d4

    [  251.903389] 1f00: 5bbd8c01 21f93f8b 5bbd8c01 ec607828 00000000 00000000 000003b5 00000000

    [  251.911600] 1f20: ecc3c600 ec607828 00000002 0000001d ecc3c608 00000000 ed2b1f74 ed2b1f48

    [  251.919812] 1f40: c032fd58 c036ebcc 00000000 00000000 ecc3c600 ecd8b900 00000003 ecd8b900

    [  251.928023] 1f60: c0385650 beac19f8 ed2b0000 00000000 ed2b1fa4 ed2b1f80 c034208c c0341860

    [  251.936235] 1f80: 00000000 00000003 00035f10 00000036 c0207d84 ed2b0000 00000000 ed2b1fa8

    [  251.944445] 1fa0: c0207be0 c034205c 00000000 00000003 00000003 c0385650 beac19f8 00000000

    [  251.952658] 1fc0: 00000000 00000003 00035f10 00000036 c0385650 0001375c 00013788 00000018

    [  251.960870] 1fe0: 000259a0 beac18cc 00011f5c b6cf4116 20070030 00000003 54204004 42486510

    [  251.969077] Backtrace:

    [  251.971545] [<c06e0f2c>] (v4l_dbg_g_register) from [<c06e3254>] (__video_do_ioctl+0x298/0x30c)

    [  251.980194]  r8:c103e910 r7:c06e0f2c r6:ece4b0b0 r5:c0385650 r4:00000003

    [  251.986926] [<c06e2fbc>] (__video_do_ioctl) from [<c06e2c70>] (video_usercopy+0x18c/0x4bc)

    [  251.995227]  r10:00000003 r9:00000000 r8:beac19f8 r7:ed2b1e18 r6:00000038 r5:00000038

    [  252.003088]  r4:c0385650

    [  252.005634] [<c06e2ae4>] (video_usercopy) from [<c06e2fb8>] (video_ioctl2+0x18/0x1c)

    [  252.013409]  r10:00000000 r9:ed2b0000 r8:ece4b4a8 r7:beac19f8 r6:c0385650 r5:ecd8b900

    [  252.021270]  r4:ece4b0b0

    [  252.023815] [<c06e2fa0>] (video_ioctl2) from [<c06dd870>] (v4l2_ioctl+0xa8/0xe0)

    [  252.031246] [<c06dd7c8>] (v4l2_ioctl) from [<c03418fc>] (do_vfs_ioctl+0xa8/0x7fc)

    [  252.038761]  r9:ed2b0000 r8:beac19f8 r7:00000003 r6:ecd8b900 r5:ece3f9c0 r4:beac19f8

    [  252.046540] [<c0341854>] (do_vfs_ioctl) from [<c034208c>] (SyS_ioctl+0x3c/0x64)

    [  252.053880]  r10:00000000 r9:ed2b0000 r8:beac19f8 r7:c0385650 r6:ecd8b900 r5:00000003

    [  252.061740]  r4:ecd8b900

    [  252.064288] [<c0342050>] (SyS_ioctl) from [<c0207be0>] (ret_fast_syscall+0x0/0x34)

    [  252.071889]  r9:ed2b0000 r8:c0207d84 r7:00000036 r6:00035f10 r5:00000003 r4:00000000

    [  252.079666] Code: ebefd19e e5953068 e3010f9c e34c00c0 (e5931000)

    [  252.093104] ---[ end trace 43d705e44ff5c998 ]---

    Thanks & Best Regards;

    Nikunj Patel

  • Hi...
    Above issue is happen due to our custom application.
    Now we have used the v4l2-dbg application and due to this we are able to access the g_register and s_register api.

    Now we are using ar1335 sensor in which some register are of 8 bit address and some registers are of 16bit address. So is there any way to pass the 8 bit and 16 bit in same above api?

    Thanks & Best regards;
    Nikunj Patel
  • Hello,

    I can not allocate ar1335 in the kernel.
    I would recommend you to search in the documentation about g_register and s_register.


    In additional, here is some wiki pages.
    software-dl.ti.com/.../Foundational_Components_Kernel_Drivers.html
    software-dl.ti.com/.../Foundational_Components_Kernel_Drivers.html


    BR
    Margarita
  • Hi Margarita;
    We have managed by validating individual register and solve our issue.

    Thanks & Best Regards;
    Nikunj Patel
  • Hello,

    I am glad that this issue is solved.

    BR
    Margarita