LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 01-28-2010, 05:48 AM   #1
archanac07
LQ Newbie
 
Registered: Jan 2010
Posts: 26

Rep: Reputation: 15
Exclamation 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

Last edited by archanac07; 01-28-2010 at 05:49 AM. Reason: add tag
 
Old 01-28-2010, 06:19 AM   #2
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,598
Blog Entries: 29

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
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 !!

Last edited by TheIndependentAquarius; 01-28-2010 at 07:19 AM.
 
Old 01-28-2010, 01:40 PM   #3
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2013.07, Slack14.1 DebWheezy, +50+ other Linux OS, for test only.
Posts: 13,196

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
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.
.....
 
Old 01-29-2010, 06:00 AM   #4
archanac07
LQ Newbie
 
Registered: Jan 2010
Posts: 26

Original Poster
Rep: Reputation: 15
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
 
Old 01-29-2010, 06:11 AM   #5
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,598
Blog Entries: 29

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
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

Last edited by TheIndependentAquarius; 01-29-2010 at 06:17 AM.
 
Old 01-29-2010, 06:36 AM   #6
archanac07
LQ Newbie
 
Registered: Jan 2010
Posts: 26

Original Poster
Rep: Reputation: 15
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
 
Old 01-29-2010, 06:47 AM   #7
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,598
Blog Entries: 29

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
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 !!

Last edited by TheIndependentAquarius; 01-29-2010 at 06:49 AM.
 
Old 01-29-2010, 06:55 AM   #8
archanac07
LQ Newbie
 
Registered: Jan 2010
Posts: 26

Original Poster
Rep: Reputation: 15
Thumbs up

Quote:
Originally Posted by anishakaul View Post
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..

 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
writing on a DVD using Udf driver in linux jadhavpiyush Linux - Kernel 1 03-05-2009 04:08 PM
Writing own Linux ipmi driver Yoga Bharathi Linux - Newbie 2 01-25-2008 07:15 AM
Writing Simple Device Driver In Linux i_love_linux Linux - Kernel 6 09-04-2007 07:16 PM
writing printer device driver in linux sidbash Programming 3 07-04-2004 11:16 PM


All times are GMT -5. The time now is 01:43 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration