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 *
* *
* *
* 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);


}



}