LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 05-15-2009, 04:25 AM   #1
sunr2007
Member
 
Registered: Jan 2009
Location: Bangalore , India
Distribution: Fedora 12
Posts: 65

Rep: Reputation: 17
Taking keyboard driver from userspace to kernel space.


Hi all,
Im using a AT91SAM9261 board . I have a interfaced a Keyboard for my board through the internal SRAM interface.i have written a driver which runs in the user space using mmap function. now i want to write this driver in the kernel . can anybody let me know how to access the adresses uses the ioremap () and others so tat i can convert this into kernel space? any suggestions in the improvement of code are greatly welcome since this is my first one .

/***************************************************************************
* Copyright (C) 2009 by Ravi Kulkarni *
* sunr2007@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/

/***************************************************************************
This programs polls the keypad from the user space using the mmap function .
The processor pins are used as individual keys connected throught a internal SRAM interface.
***************************************************************************/
#define MAP_SIZE 4096UL
#define MAP_MASK (MAP_SIZE-1)

#define PSIZE = 50;
off_t target=0xFFFFF43C;



int get_key_pressed()
{

void *map_base,*virt_addr;



int i,j;



/*************&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
fOR POLLING KEY PAD FROM BOARD PORT-A
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&************************/

if(fd1 <=0)
/*key_input*/fd1 = open("/dev/mem",O_RDWR|O_SYNC);

if (fd1 <0/*key_input == NULL */)
{
perror("/dev/mem not opening"); exit(-1); }
else
{

map_base=mmap(0,MAP_SIZE,PROT_READ|PROT_WRITE,MAP_SHARED,fd1,target & ~ MAP_MASK);

if(map_base == (void *) -1)
{
perror("map_base"); exit(-1);
}
virt_addr = map_base + (target & MAP_MASK);
while(1)
{
if(in_map == 2)
break;

read_result= * ((unsigned long *) virt_addr);

if((read_result & 0x3ffff000)==0x3fffd000)
{

for(i=0;i<20;i++)
{
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
//
}
if((read_result & 0x3ffff000)==0x3fffd000)
key_pressed_val=1; // ESC PRESSED
read_result=0;

}
else
if((read_result & 0x3ffff000)==0x3fffb000)
{


for(i=0;i<20;i++)
{
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);

}
if((read_result & 0x3ffff000)==0x3fffb000)
key_pressed_val=2; // ENTER PRESSED
read_result=0;



}
else
if((read_result & 0x3ffff000)==0x3fff7000)
{

for(i=0;i<20;i++)
{
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);

}
if((read_result & 0x3ffff000)==0x3fff7000)
key_pressed_val=3; // MENU PRESSED
read_result=0;

}
else
if((read_result & 0x3ffff000)==0x3ffef000)
{

for(i=0;i<20;i++)
{
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);

}
if((read_result & 0x3ffff000)==0x3ffef000)
key_pressed_val=4; // NRS PRESSED
read_result=0;

}
else
if((read_result & 0x3ffff000)==0x3feff000)
{
// g_print(" \n\r UP key is pressed ");//puts(" UP KEY PRESSED ");
// read_result=0;

for(i=0;i<20;i++)
{
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);

}
if((read_result & 0x3ffff000)==0x3feff000)
key_pressed_val=5; // UP PRESSED
read_result=0;
//return(key_pressed_val);
}
else
if((read_result & 0x3ffff000)==0x3fbff000)
{
g_print(" \n\r RIGHT key is pressed ");//puts(" RIGHT KEY PRESSED ");
// read_result=0;

for(i=0;i<20;i++)
{
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);

}
if((read_result & 0x3ffff000)==0x3fbff000)
key_pressed_val=6; // RIGHT PRESSED
read_result=0;
//return(key_pressed_val);

}
else
if((read_result & 0x3ffff000)==0x3fdff000)
{

for(i=0;i<20;i++)
{
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);

}
if((read_result & 0x3ffff000)==0x3fdff000)
key_pressed_val=7; // LEFT PRESSED
read_result=0;

}
else
if((read_result & 0x3ffff000)==0x3f7ff000)
{


for(i=0;i<20;i++)
{
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);

}
if((read_result & 0x3ffff000)==0x3f7ff000)
key_pressed_val=8; // DOWN PRESSED
read_result=0;

}
else
if((read_result & 0x3ffff000)==0x3efff000)
{


for(i=0;i<20;i++)
{
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);

}
if((read_result & 0x3ffff000)==0x3efff000)
key_pressed_val=9; // NAV PRESSED
read_result=0;
//return(key_pressed_val);

}
else
if((read_result & 0x3ffff000)==0x3Dfff000)
{

for(i=0;i<20;i++)
{
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);
for(j=0;j<65536;j++);

}
if((read_result & 0x3ffff000)==0x3Dfff000)
key_pressed_val=10; // STR PRESSED
read_result=0;

}

}//while
munmap ((caddr_t) map_base,MAP_SIZE);
//printf("after gggg");
g_thread_exit(key_thr);


}



}
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Userspace handling of driver interrupts AustinMarton Linux - Kernel 12 01-14-2009 08:48 PM
Can we register a userspace funtion as a callback to kernel space? duyuyang Linux - Kernel 0 12-20-2008 12:24 AM
Selective ethernet frame forwarding via userspace / kernel space program neur0tic Linux - Networking 5 12-24-2007 03:52 PM
Keyboard scanning in linux kernel space floflette Programming 3 07-20-2004 12:43 PM
Keyboard scanning in linux kernel space floflette Linux - Newbie 3 07-20-2004 09:38 AM


All times are GMT -5. The time now is 07:00 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