GPIO driver

cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO driver

555 Views
Contributor IV

Hi,

I am trying to write a GPIO driver, for On and Off a peripheral, Im unable to find the register address definition IOMUXC_SW_MUX_CTL_PAD_SAI5_RXD1 to configure as GPIO and set the direction as output and set and clear the pin.

help me with example for writing the driver

The Contents in /sys/class/gpio

root@imx8mmevk:/sys/class/gpio# ls
export     gpiochip128  gpiochip496  gpiochip96
gpiochip0  gpiochip32   gpiochip64   unexport

Also i tried to use sys/class/gpio that also didnt work for me

For GPIO3_IO22 would get the kernel GPIO number
* N = (BANK – 1) * 32 + IO
* N = (3 – 1) * 32 + 22 = 86
* echo 86 > /sys/class/gpio/export   -- Command to Export GPIO44

* To set the value of output GPIOs by first setting the direction
*  echo out > /sys/class/gpio/gpio86/direction
* and then set the value low by
* echo 0 > /sys/class/gpio/gpio86/value
* or to high
* echo 1 > /sys/class/gpio/gpio86/value

Regards

0 Kudos
3 Replies

60 Views
NXP TechSupport
NXP TechSupport

Hello Santhosh Kumar,

Which processor you are using? You can find the register address on the Reference Manual of the processor you are using.

For example, for the i.MX8MM the Pad Mux Register IOMUXC_SW_MUX_CTL_PAD_SAI5_RXD1 has an absolute address of 3033_014C (hex) as shown on the IOMUXC Memory Map in section 8.2.5 of the Reference Manual.

I hope this helps!

Regards,

0 Kudos

60 Views
Contributor IV

Hi,

I am using NXP I.MX8MMINI EVK board 

I have found the SAI5_RXD1 from datasheet but im unable to locate the reg address in the header file in kernel source code.

i have learnt that there is no direct fsl write to address in the latest linux kernel, instead the devicetree source is included in a fsl-imx8mm.dts or .dtsi file

so I have written platform device driver and assigned the .compatible = "fsl,imx8mm-gpio" and trying the prob the physical address and map to virtual address but its unable probe the address

i have got invalid address when  r_mem =  platform_get_resource(pdev, IORESOURCE_MEM, 0); is called in probe

below is the source code for quick review

/***************************************************************************************/

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/io.h>
#include <linux/interrupt.h>
#include <linux/of_address.h>
#include <linux/bitops.h>
#include <linux/err.h>
#include <linux/gpio.h>

#include <linux/irqdomain.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <linux/pm_qos.h>
#include <linux/rpmsg.h>
#include <linux/virtio.h>
#define DRIVER_NAME "GPIO_DRIVER"


struct simpmod_local {
    int irq;
    unsigned long mem_start;
    unsigned long mem_end;
    void __iomem *base_addr;
    };
      
static int gpiodriver_probe(struct platform_device *pdev)
{
    struct resource *r_mem; /*IO Mem Resource */
    struct device *dev = &pdev->dev;
    struct simpmod_local *lp = NULL;
    int rc=0;
    printk(KERN_ALERT "\n  Device Tree address.... \n");
    
    r_mem =  platform_get_resource(pdev, IORESOURCE_MEM, 0);
#if 1        
    if(!r_mem)
    {
        dev_err(dev, "Invalid Address\n");
        return ENODEV;    
    }
#endif
    lp = (struct simpmod_local *) kmalloc(sizeof(struct simpmod_local),GFP_KERNEL);
    if(!lp){
        printk(KERN_ALERT "\ncould not allocate Memory \n");
    }
    printk(KERN_ALERT "\n  Save data on local structure \n");
    dev_set_drvdata(dev,lp);
   
    //Save data on local structure
    lp->mem_start = r_mem->start;
    lp->mem_end = r_mem->end;
#if 0
    //Ask kernel the memory region defined on the device tree and prevent other drivers to overlap on this region
    //this is needed before ioremap
    if(!request_mem_region(lp->mem_start,lp->mem_end - lp->mem_start+1,DRIVER_NAME)){
    dev_err(dev,"Couldn't lock memory at %p\n",(void *)lp->mem_start);    
    rc=EBUSY;
    //goto error1:
    }
#endif    
    printk("lp->mem_start:0x%X\t mapped to 0x%X",(unsigned int __force)lp->mem_start,(unsigned int __force)lp->base_addr);   
    return 0;
}

static int gpiodriver_remove(struct platform_device *pdev)
{
    return 0;
}

static void gpio_device_release(struct device *pdev)
{
}

static const struct of_device_id imx_gpio_ctrl[] = {
    { .compatible = "fsl,imx8mm-gpio" ,},
    { /* sentinel */ }
};
static struct platform_driver gpio_driver = {
    .driver = {
        .name = DRIVER_NAME,
        .owner = THIS_MODULE,
        .of_match_table = imx_gpio_ctrl
    },
    .probe = gpiodriver_probe,
    .remove = gpiodriver_remove,
};

static struct platform_device gpio_device = {
    .name = DRIVER_NAME,
    .id = 0,
    .dev = {
        .release = gpio_device_release,
    },
};

static int __init gpio_device_init(void)
{
    printk(KERN_ALERT "\nDriver test init\n");
    platform_device_register(&gpio_device);
    platform_driver_register(&gpio_driver);
    return 0;
}

static void __exit gpio_device_exit(void)
{
    printk(KERN_ALERT "\nDriver test exit\n");
    platform_driver_unregister(&gpio_driver);
    platform_device_unregister(&gpio_device);
}

module_init(gpio_device_init);
module_exit(gpio_device_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Santhosh");
MODULE_DESCRIPTION("IMX8MM GPIO Driver");

/***************************************************************************************/

need your help to resolve

Regards

Santhosh

0 Kudos

60 Views
NXP TechSupport
NXP TechSupport

Hello Santhosh Kumar,

Are you still experiencing problems with the GPIO driver?

Regards,

0 Kudos