AnsweredAssumed Answered

GPIO toggle problem in LKM imx6

Question asked by vijesh reddy on Dec 6, 2017
Latest reply on Dec 6, 2017 by igorpadykov



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/module.h>
#include <linux/gpio.h>



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;
  ptr2 = ioremap(dir,4);
  result = ioread32(ptr2);
  result = result| 0x0d000000 ;
  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 ;  


  result = ioread32(ptr1);
  result = result| 0x0d000000 ;  




printk(KERN_ALERT "before\n");
result = ioread32(ptr1);
  result = result| 0x0d000000 ;  




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);
    printk(KERN_ALERT "Exiting LKM Module\n");