Find the answer to your Linux question:
Results 1 to 2 of 2
Hi all, I am writing a driver for a device which acts as both mouse and joy stick based on the bits set in the status registers and uses spi ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2006
    Posts
    24

    How drivers maintains Device state information


    Hi all,
    I am writing a driver for a device which acts as both mouse and joy stick based on the bits set in the status registers and uses spi and twi protocols . My application sends ioctl to change device mode and bus mode whenever it needs to change. I also have to load patch file into the device when the driver is initalising. My application also queries about the device state information whenever it requires through ioctl.
    My question is how can a driver maintains all these information because my application don't need to know maintains this informations. So my driver has to maintain this information i.e device mode whether it is mouse or joystick and bus modes whether it is spi or twi and patch file location to load into the device. And also when the system reboots the device has to be in the previous state what ever it is before shutdown. Can any one help me in this case.
    I try to store the information in a file through structure which contains device mode ,busmode and patch file location and peform file operations through driver whenever any one of the structure element changes but it is not working because we are not supposed to do file operations in a kernel module . Please help whether there is any way to do this. I also want to know how normal driver in linux are maintaining the device configuration files i.e how display driver maintains the screen height and width i.e at any time i can change the screen size and resolution when the system reboots also the screen will be in same height and resolution which i was set before shutdown. How this is maintained by the drivers whether the driver or maintaining or someelse is maintaining this information.

  2. #2
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    Quote Originally Posted by raju82
    My question is how can a driver maintains all these information because my application don't need to know maintains this informations. So my driver has to maintain this information i.e device mode whether it is mouse or joystick and bus modes whether it is spi or twi and patch file location to load into the device. And also when the system reboots the device has to be in the previous state what ever it is before shutdown
    Your module shouldn't access files. The kernel is simply not prepared to do that (really, there is no fopen and the open syscall doesn't work cause it checks if it is been calling from user space and if not, it fails). You can fix the twi/spi or mouse/joystick passing parameters to the module when loading it. Use module_param declared at linux/moduleparam.h. But this doesn't fix the patch file problem. (Note that the module loading with the proper parameters is done by the proper userland application (probably a startup script).)
    If the patch file to be loaded is some kind of firmware maybe you want to take ta look to the ipw2200 driver (Intel ProWireless)

    Quote Originally Posted by raju82
    And also when the system reboots the device has to be in the previous state what ever it is before shutdown
    Your mouse driver doesn't store if you use 3-button emulation. Your soundcar driver doesn't store your master level and so on... that is a user program responsability (for the gnome desktop and the sound daemon for example... and both of them has their configuration files.)

    Quote Originally Posted by raju82
    i.e how display driver maintains the screen height and width
    They do not do that.

    That kind of information is stored in X server configuration file (/etc/X11/xorg.conf or similar). The X server (remember that the X server is a normal application, it is not a driver and it is not a module or kernel code at all) reads this information and then uses the driver to paint pixels, lines etc. The limits are stablished by the X server, not by the driver.

    If you want to read files from the kernel there is a horrible and ugly hack that you can find via Google, but be careful: it will be more difficult to make this hack work than write a userland application to store and restore the values that you need.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •