LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 08-07-2019, 10:21 PM   #1
OliverChen
LQ Newbie
 
Registered: Aug 2019
Posts: 6

Rep: Reputation: Disabled
Can't use ioctl() to control a device owned by kernel module?


Hi!

I failed to use C/C++ to access the image sensor OV5645's register on my system via I2C bus. Below are some information about my system:

Hardware:
Dragonboard 410c +
96Boards MIPI Adapter with Dual OV5645
(https://www.ebay.com/itm/96Boards-MI...525BC%25252589)
OS :
Linaro Linux (Debian based) 19.01


As I can use GStreamer to control the two OV5645 to feedback captured images, the hardware connections seems to be fine. Below are some information about the I2C master and OV5645 in my system:
Code:
    linaro@linaro-developer:~$ sudo i2cdetect -l
    i2c-3   i2c             QUP I2C adapter                         I2C adapter
    i2c-1   i2c             QUP I2C adapter                         I2C adapter
    i2c-4   i2c             Qualcomm Camera Control Interface       I2C adapter
    i2c-0   i2c             QUP I2C adapter                         I2C adapter

    linaro@linaro-developer:~$ dmesg | grep ov5645
    [   11.825197] ov5645 4-003b: OV5645 detected at address 0x3b
    [   12.290626] ov5645 4-003a: OV5645 detected at address 0x3a
And here is my short program: https://gist.github.com/oliverjungen...7e7a3c0678c41e

What it does are simply:

1. Open /dev/i2c-4

Code:
file = open(filename, O_RDWR);
2. Set I2C slave address 0x3b

Code:
errno = ioctl(file, I2C_SLAVE_FORCE, CAM_REAR_I2C_ADDR);
3. Send 16-bit register address 0x300a to this I2C slave

Code:
ret = write(file, &reg, 2);
However, when it runs, I always get:

Code:
Write i2c internal address error: Input/output error
This message was printed by perror() in this program’s Line 54, after writing the register address (0x300a, SENSOR CHIP ID HIGH BYTE) to OV5645.

I found that, when this error occurs, the kernel module i2c-qcom-cci reports error messages like:

Code:
    linaro@linaro-developer:~$ dmesg | grep cci
    [ 1280.099448] i2c-qcom-cci 1b0c000.cci: Master 0 error 0x08000000
    [ 1280.099502] i2c-qcom-cci 1b0c000.cci: master 0 queue 0 error -5
    [ 1280.104247] i2c-qcom-cci 1b0c000.cci: cci i2c xfer error -5
These I2C slaves (these OV5645) are actually owned by kernel modules. That's the reason why I use I2C_SLAVE_FORCE instead of I2C_SLAVE as the flag when I set the I2C slave address: errno = ioctl(file, I2C_SLAVE_FORCE, CAM_REAR_I2C_ADDR);

I'm wondering whether I can't use ioctl() to control a device owned by kernel modules?

Last edited by OliverChen; 08-07-2019 at 10:25 PM.
 
Old 08-08-2019, 02:27 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,153

Rep: Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265
I don't think you should be opening the i2c device to talk to the camera. That bus probably is owned by the kernel i2c driver and not shared. You should be opening the ov5645 device as described here:

https://www.linuxtv.org/downloads/le...v4l2.html#open
 
Old 08-08-2019, 07:35 PM   #3
OliverChen
LQ Newbie
 
Registered: Aug 2019
Posts: 6

Original Poster
Rep: Reputation: Disabled
Hi smallpond,
First thank you for your reply.
OK, I understand. I've found a lot of information in the Video for Linux Two API Specification I should study. Hopefully it will lead me to find the solution of this issue.
Thanks again and I wish you a good day!
 
Old 08-12-2019, 08:04 AM   #4
OliverChen
LQ Newbie
 
Registered: Aug 2019
Posts: 6

Original Poster
Rep: Reputation: Disabled
For anyone who may concern:
The root cause of this symptom is:
OV5645’s kernel module will turn OV5645’s power off (or power-saving?) after initializing it. After turning its power on manually, now it’s OK to access OV5645’s registers.
FYR.

Hi smallpond,
Thank you for your kind help, anyway!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] device-mapper: remove ioctl on failed: Device or resource busy jheengut Linux - Kernel 1 10-23-2013 08:38 AM
In linux platform how to use ioctl function to read/write data to hid device zyroot998 Linux - Software 3 06-28-2011 10:06 PM
How to pass IOCTL arguments from usespace ioctl call devkpict Linux - Kernel 1 12-07-2007 06:45 PM
tc traffic control tc traffic control Linux QoS control tool(noob help) inv|s|ble Linux - General 1 07-26-2007 11:12 AM
Make a file owned by root owned by a user sharpie Linux - Newbie 2 02-26-2004 01:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 01:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration