keyboard driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
I'm trying to replace the standard keyboard driver with my own 
module ( which i have copied from kernel_module_programming guide 
by Peter Jay Salzman,Ori Pomerantz )

after insmod i see this:
In /var/log/messages
---------------------
Feb 23 11:00:27 localhost kernel: request_irq successful!


in /proc/interrupts
-------------------
[root@localhost study]# cat /proc/interrupts
           CPU0
  0:     922981          XT-PIC  timer
  1:          7          XT-PIC  test_keyboard_irq_handler
  2:          0          XT-PIC  cascade
  5:      58852          XT-PIC  usb-uhci, eth0


in /proc/modules/
------------------
intrpt                  1841   0 (unused)
soundcore               6532   0 (autoclean)
bcm5700               103780   1

i.e. module gets loaded properly, but on pressing any key, i don't 
see any message from got_char function. Don't know whether the handler 
is being called or not! i had put a prink in the handler function 
( not sure its allowed or not!/) to see if control reaches there. 
But i don't see this in the /var/log/messages file. 
Kernel version is 2.4.18-14.

am i missing something here? 

Pls Help!

Dhanashri
=================================================================
Here's the code:

/* intrpt.c - An interrupt handler. */

#include <linux/kernel.h> 
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/tqueue.h>
#include <asm/io.h>
#include <linux/interrupt.h>
#ifndef KERNEL_VERSION
#define KERNEL_VERSION(a,b,c) ((a)*65536+(b)*256+(c))
#endif

/* Bottom Half  */
static void got_char(void *scancode)
{
        printk("Scan Code %x %s.\n",
                        (int) *((char *) scancode) & 0x7F,
                        *((char *) scancode) & 0x80 ? "Released" : "Pressed");
}

/* The keyboard interrupt handler function */
void irq_handler(int irq, void *dev_id, struct pt_regs *regs)
{
        /* This variables are static because they need to be
         * * accessible (through pointers) to the bottom half routine.
         * */
        static unsigned char scancode;
        static struct tq_struct task =
        {
                routine:got_char,
                data:&scancode
        };

        unsigned char status;
        /* Read keyboard status */
        status = inb(0x64);
        scancode = inb(0x60);
        printk( "<1> in the irq_handler function\n");

        /* Scheduale bottom half to run */
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,2,0)
        queue_task(&task, &tq_immediate);
#else
        queue_task_irq(&task, &tq_immediate);
#endif
        mark_bh(IMMEDIATE_BH);
}
/* Initialize the module . register the IRQ handler */
int init_module()
{
        int result = 0;

        /* Since the keyboard handler won't co.exist with another handler,
         * * such as us, we have to disable it (free its IRQ) before we do
         * * anything. Since we don't know where it is, there's no way to
         * * reinstate it later . so the computer will have to be rebooted
         * * when we're done.
         * */
        free_irq(1, NULL);

        /* Request IRQ 1, the keyboard IRQ, to go to our irq_handler. */
        /* return value 0 => success */
        result = request_irq(1,irq_handler,0,"test_keyboard_irq_handler",NULL);
        if ( result != 0 )
        {
                printk ( "<1>request_irq failed, with result=%d\n",result );
                return -1;
        }
        else
        {
                printk ( "<1>request_irq successful!\n" );
                return 0;
        }

}
/* Cleanup */
void cleanup_module()
{
        free_irq(1, NULL);
}
===============================================================






--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux