I am having trouble understanding the way that a device driver interacts with user space. We are writing a char driver to send configuration information to a switch IC (ZL50408) in an embedded system, running uClinux on a NIOS2 processor.
Someone has contributed a large portion of the driver, but I am unsure of the way it operates. I know every driver has the init
functions, they work when we load the module, and we are able to access registers and read/set the values by placing code in the init function.
Once the module has been loaded, when are the other functions called? When a user space application attempts to write to the file in the /dev
directory, I assume the write function specified in the file_operations
structure is what is called?
The author of the driver has made two different file_operations
so I am confused how the kernel knows which one to use if there is only one entry in the /dev
I am trying to write a user space application to test the driver, I simply want to write and read from a few registers. This is an example I found in a book and have been playing around with:
fh = open("/dev/zl504xx",O_RDWR);
cnt = read(fh,bfr,1);
printf("Data read: %x\n", bfr);
printf("Fail open device\n");
Is this read
command what I want to be using?
I am confused because the read function in our driver has 4 arguments:
static ssize_t zl_read_cfg(struct file *filp, char __user *buf, size_t len, loff_t *off)
And my last point of confusion, we are wanting to have a user space application with does the switch management, it will set certain registers to change different settings. This seems quite different to the 'stream' nature of a file? For example, to examine the 5th byte in memory, would we access the 5th character in the file in /dev
Thanks, answers or hints to ANY of the above questions would be MUCH appreciated!!