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