i am using imx6qsabresd board. and using eclipse for user space application development.
I can able to access i2c and read or write address. But for that first i need to remove particular .ko module.
But i want to use functions of MMA8451Q or MAG3110 's driver in my application without removing the ko module.
So how can i do that?
Hello Ritesh,
Sorry if I missunderstood, you are creating an application in user space, that it is going to need the usage of the i2c module, but when you try to access you are read and write, functions are not working until removed of MMA8451 Module (KO ). If this is the scenario, I think you are using the same I2C bus that has the Accelerometer and the Magnetometer, so you have two options access a diferent I2C bus or then it is necesary to remove the Sensor KOs, since they are handling the same bus.
Have a great day,
Jaime
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello,
Thanks for the Reply.
What ever u have written that's right. And i am telling the same in my question. That i can able to access MMA8451 after i removed its module. Otherwise open command will give me error that "resource or device busy".
Actually i am new to linux environment. And i am learning linux driver development.
I have one basic question that how can i use linux driver in user space? As i read somewhere i found using ioctl or sysfs interface.
In MMA8451 or MAG3110 driver sysfs is created as user interface.
So my question is how to use sysfs or ioctl in my user application so i can able to access my driver and thus the IC.?
int fd = open(NULL == device ? default_device : device, O_WRONLY);
if (fd != -1) {
drv8825_rotate cfg;
cfg.step = step;
cfg.delay = delay;
ioctl(fd, DRV8825_SET_ROTATE, &cfg);
close(fd);
}
#define GPIO_SYSFS "/sys/class/gpio"
static int gpio_enable(int gpio, unsigned char enable)
{
const char *export_file = GPIO_SYSFS "/export";
const char *unexport_file = GPIO_SYSFS "/unexport";
int fd;
int status = -1;
if (gpio <= 0)
return -1;
fd = open(enable ? export_file : unexport_file, O_WRONLY);
if (fd != -1) {
char number[4] = {0};
const size_t len = 3;
snprintf(number, len, "%u", gpio);
if ((ssize_t)len == write(fd, number, len))
status = 0;
close(fd);
}
return status;
}
Thanks for the reply.
I have tested with ov5640 driver. i can set exposer using ioctl.
but i unable to use sysfs of MAG3110.
This device is detected as "/dev/input/event5".
I can successfully open the device. But there's some functions like "mag3110_position_show", "mag3110_position_store" etc.
How can i access this function from user space program.?
You can't execute kernel function from user-space.
If you should configure device throw kernel functions you can modify driver, e.g. add ioctl support. As result you can follow path: user_space -> ioctl -> kernel_space.
MAG3110 driver has sysfs for user interface.
Please find driver code.
https://drive.google.com/file/d/0B5xLP5YaPU3_TkFITU1KNDlvRHc/view?usp=sharing
Can you tell me how can i use sysfs read/write for this driver?
This is a very simple - you can use standart functions open, close, read and write.
As you can see driver create some files in /sys:
- mag3110_dr_mode_show return curren value, use read
- mag3110_dr_mode_store apply decimal value, should be <= 7, use write
- mag3110_enable_store apply decimal value, use write
- mag3110_enable_show return current value, use read
- mag3110_position_show return current value, use read
- mag3110_position_store apply decimal value, use write
I appreciate your effort. But i'm sorry but as i am new to this field.
Can you show one example how to use this?
i can open by this function.
fd = open("/dev/input/event5", O_RDWR);
i am using read( fd, "mag3110_position_show", 10, &buf);
but dont getting result.
This is incorrect!
You should't use /dev/input/event5, you should find mag3110_position_show file in /sys and use it.
Read examples without check return:
char buf[10] = {0};
in fd = open("file", O_RDONLY);
read(fd, buf, 9);
close(fd);
Write example without check return:
const char *buf = "5";
in fd = open("file", O_WRONLY);
write(fd, buf, strlen(buf));
close(fd);