LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   writing keyboard driver in linux (http://www.linuxquestions.org/questions/linux-software-2/writing-keyboard-driver-in-linux-785316/)

archanac07 01-28-2010 05:48 AM

writing keyboard driver in linux
 
Hi,
I want to write driver for keyboard.

To do this first i need to remove existing driver and i'm not able to find the location of kernel's keyboard driver in linux ..

If anyone knows the location of keyboard driver then plz rply

TheIndependentAquarius 01-28-2010 06:19 AM

U can think of writing a keyboard interrupt handler first, then u can extend it as a driver..It 'll be easier for u this way..

I have myself written a keyboard interrupt handler though I didn't convert it into a full fledged driver !!

knudfl 01-28-2010 01:40 PM

The kernel drivers, example
/lib/modules/2.6.2x.xx/kernel/drivers/input/keyboard/
sunkbd.ko newtonkbd.ko lkkbd.ko xtkbd.ko


The driver, you are using is probably the one from xorg :
/usr/lib/xorg/modules/input/kbd_drv.so

All the above is from PCLinuxOS.
.....

archanac07 01-29-2010 06:00 AM

hi
anisha, as you say i'll start with keyboard interrupt handler.
if you have any reference material plz share with me. it'll helpful.

knudlf
as you mentioned i didnt found any such file.
i installed linux kernel 2.6.23.47 version

TheIndependentAquarius 01-29-2010 06:11 AM

Quote:

Originally Posted by archanac07
hi
anisha, as you say i'll start with keyboard interrupt handler.
if you have any reference material plz share with me. it'll helpful.

Here s a simple keyboard interrupt handler, I wrote few months back !

After u have inserted this module, if you press Esc key, U'll get something printed which u can see with dmesg.


keyboardInterruptHandler.c
Code:

#include <linux/kernel.h>
#include <linux/interrupt.h>
#include <asm/io.h>

/*
 This function services keyboard interrupts.
*/
irq_handler_t irq_handler (int irq, void *dev_id, struct pt_regs *regs)
{
        static unsigned char scancode;
       
        /*
        Read keyboard status
        */
        scancode = inb (0x60);

        if ((scancode == 0x01) || (scancode == 0x81))
        {
                printk ("\nYou pressed Esc !");
        }

        return (irq_handler_t) IRQ_HANDLED;
}

/*
 Initialize the module − register the IRQ handler
*/
int init_module ()
{
        /*
          Request IRQ 1, the keyboard IRQ, to go to our irq_handler SA_SHIRQ means we're willing to have othe handlers on this IRQ. SA_INTERRUPT can be used to make the handler into a fast interrupt.
        */
        return request_irq (1, (irq_handler_t) irq_handler, SA_SHIRQ, "test_keyboard_irq_handler", (void *)(irq_handler));
}

MODULE_LICENSE ("GPL");

Makefile
Code:

obj-m += keyboardInterruptHandler.o

all:       
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:       
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

I hope it helps u to get started :)
Though it looks simple, I had to take great pains writing it :)

archanac07 01-29-2010 06:36 AM

thanks anisha...
it is g8 start for me...

if i stuck somewhere i'll post reply to you..

how much time you have taken to write this code and how you started study purpose or something else..
if you want you can share this info...

again thanks

TheIndependentAquarius 01-29-2010 06:47 AM

Quote:

Originally Posted by archanac07
how much time you have taken to write this code and how you started study purpose or something else..
if you want you can share this info...

First thing which I did wrong was to start writing the interrupt handler without knowing the pattern of writing an interrupt handler. I was just searching internet without knowing what to search :(

Second thing I did not understand the underlying hardware (keyboard in this case) !!! (Unless u understand the hardware crystal clear, your program will never never work)

Writing a Serial Port RS232 interrupt handler was an Eye opener for me ..

All I can advise u is : do not try to finish this job by any means, it won't work unless u know what u are doing !!

archanac07 01-29-2010 06:55 AM

Quote:

Originally Posted by anishakaul (Post 3844754)
First thing which I did wrong was to start writing the interrupt handler without knowing the pattern of writing an interrupt handler. I was just searching internet without knowing what to search :(

Second thing I did not understand the underlying hardware (keyboard in this case) !!! (Unless u understand the hardware crystal clear, your program will never never work)

Writing a Serial Port RS232 interrupt handler was an Eye opener for me ..

All I can advise u is : do not try to finish this job by any means, it won't work unless u know what u are doing !!

ya i have already gone through it..
so i'll no do any kind of hurry for this task..

:)


All times are GMT -5. The time now is 10:41 PM.