Hi,
I am trying to toggle an LED inside the init() function called during insmod of an LKM Module. Following are the steps i followed. Step1: set the pin mux to GPIO by changing the pin mux register using ioremap(), ioread32(),iowrite32(). step 2: set the direction of gpio in gpio direction register using ioremap(), ioread32(),iowrite32(). step 3: toggle the gpio by writing to gpio data register using ioremap(), ioread32(),iowrite32(). I am able to toggle the LED,but the LED is becoming OFF once the init() function is returned - It should be ON continuously as I have written high in data register before quitting. Source code attached for your reference. Please give your comments Is there any problem with the way i am using the ioremap() function or any issues with my .dtb. Also please provide if you have any references of using ioremp() for imx6 My actual requirement is to configure the CPU registers of SPI/EIM modules using ioremap() - before that i wanted to ensure ioremap() working with GPIO.
Please give your comments.
Thanks in advance.
#include<linux/init.h>
#include <linux/module.h>
#include <linux/gpio.h>
#include<linux/kernel.h>
#include<linux/interrupt.h>
#include<linux/ioport.h>
#include<linux/mm.h>
#include<asm/uaccess.h>
#include<asm/page.h>
#include<asm/io.h>
#include<linux/delay.h>
MODULE_LICENSE("GPL") ;
static int mux= 0x020e01d8 ; // gpio pad mux register
static int dat= 0x0209c000 ; //gpio01_24 data register
static int dir= 0x0209c004 ; //gpio01_24 direction register
unsigned int result ;
static void __iomem *ptr ;
static void __iomem *ptr1 ;
static void __iomem *ptr2 ;
static void __iomem *ptr3 ;
void *a ;
void *b ;
static int __init gpio_init(void)
{
char i ;
printk(KERN_ALERT "inside init function ");
ptr = ioremap(mux,4);
result = 0x05;
iowrite32(result,ptr);
ptr2 = ioremap(dir,4);
result = ioread32(ptr2);
result = result| 0x0d000000 ;
iowrite32(result,ptr2);
ptr1 = ioremap(dat,4);
result = ioread32(ptr1);
printk(KERN_ALERT "value =%x\n",result);
for(i =0 ; i < 5 ; i++)
{
result = ioread32(ptr1);
result = result& 0xf2ffffff ;
iowrite32(result,ptr1);
msleep(100);
result = ioread32(ptr1);
result = result| 0x0d000000 ;
iowrite32(result,ptr1);
msleep(100);
}
printk(KERN_ALERT "before\n");
msleep(5000);
result = ioread32(ptr1);
result = result| 0x0d000000 ;
iowrite32(result,ptr1);
msleep(5000);
printk(KERN_ALERT "after \n");
return 0 ;
}
static void __exit gpio_exit(void)
{
// release_mem_region(0x209c000,100);
result = ioread32(ptr1);
printk(KERN_ALERT "value =%x\n",result);
iounmap(ptr);
iounmap(ptr1);
iounmap(ptr2);
printk(KERN_ALERT "Exiting LKM Module\n");
}
module_init(gpio_init);
module_exit(gpio_exit);
Hi vijesh
general answer one can find on linux documentation
How to acess the physical address from linux kernel space? - Stack Overflow
for i.mx gpio manipulation examples one can look at linux documentation provided on
Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------