Hi all
I develop on dm8168 evm using dvrrdk3.50
I have a fpga connect to gpmc cs2, and i want to write a linux device driver for it .
I have test my gpmc configure use mmap funtion to init, it works well,
but when i insmod my driver, the function gpmc_cs_request() broken,
it rets null handle used in the kernel, so i find gpmc_cs_insert_mem() uncalled for CS2,fpga spce,
so i add cs2 configure register ,then it works, however i found the when i call gpmc_cs_request(),
the cs7 register is rewrite not what i want it, and when i rmmod gpmc_fpga.ko ,
it can not insmod anymore sees some resource are not released in kernel.
can anyone tell me is there something i have to change in the kernel
best regards
xavier
void __init gpmc_init(void)
{
u32 l, irq;
....
gpmc_write_reg(GPMC_SYSCONFIG, l);
gpmc_cs_write_reg(2, GPMC_CS_CONFIG1, gpmc_fpga[0]);
gpmc_cs_write_reg(2, GPMC_CS_CONFIG2, gpmc_fpga[1]);
gpmc_cs_write_reg(2, GPMC_CS_CONFIG3, gpmc_fpga[2]);
gpmc_cs_write_reg(2, GPMC_CS_CONFIG4, gpmc_fpga[3]);
gpmc_cs_write_reg(2, GPMC_CS_CONFIG5, gpmc_fpga[4]);
gpmc_cs_write_reg(2, GPMC_CS_CONFIG6, gpmc_fpga[5]);
gpmc_cs_write_reg(2, GPMC_CS_CONFIG7, gpmc_fpga[7]);
gpmc_mem_init();
....
}
following is my code:
static int __init fpga_init_cdev(void)
{
int error;
u32 val;
fpga_dev.devt = MKDEV(0, 0);
error = alloc_chrdev_region(&fpga_dev.devt, 0, 1, "fpga");
if (error) {
printk(KERN_ALERT "alloc_chrdev_region() failed: %d\n", error);
return error;
}
cdev_init(&fpga_dev.cdev, &fpga_fops);
fpga_dev.cdev.owner = THIS_MODULE;
error = cdev_add(&fpga_dev.cdev, fpga_dev.devt, 1);
if (error) {
printk(KERN_ALERT "cdev_add() failed: %d\n", error);
unregister_chrdev_region(fpga_dev.devt, 1);
return error;
}
printk("Getting Chip Select\n");
u32 l;
int err;
l = DM8168_GPMC_BASE;
gpmc_base = ioremap(l, SZ_16M);
printk("gpmc_base, address = %lx\n", gpmc_base);
// val = 0xf64;
// gpmc_cs_write_reg(GPMC_CS, GPMC_CS_CONFIG7, val);
//val = gpmc_read_reg(GPMC_REVISION);
//printk("GPMC revision %d.%d\n", (val >> 4) & 0x0f, val & 0x0f);
//gpmc_write_reg(GPMC_IRQENABLE, 0);
//gpmc_write_reg(GPMC_TIMEOUT_CONTROL, 0);
gpmc_write_cs_reg(GPMC_CS, GPMC_CS_CONFIG1, gpmc_fpga[0]);
gpmc_write_cs_reg(GPMC_CS, GPMC_CS_CONFIG2, gpmc_fpga[1]);
gpmc_write_cs_reg(GPMC_CS, GPMC_CS_CONFIG3, gpmc_fpga[2]);
gpmc_write_cs_reg(GPMC_CS, GPMC_CS_CONFIG4, gpmc_fpga[3]);
gpmc_write_cs_reg(GPMC_CS, GPMC_CS_CONFIG5, gpmc_fpga[4]);
gpmc_write_cs_reg(GPMC_CS, GPMC_CS_CONFIG6, gpmc_fpga[5]);
gpmc_write_cs_reg(GPMC_CS, GPMC_CS_CONFIG7, gpmc_fpga[6]);
val = gpmc_read_cs_reg(GPMC_CS, GPMC_CS_CONFIG7);
printk("GPMC_CS_CONFIG7 value 0x%x\n", val);
if (gpmc_cs_request(GPMC_CS, SZ_16M, (unsigned long *)&mem_base) < 0) {
printk(KERN_ERR "Failed request for GPMC mem for usrp_e\n");
return -1;
}
printk("Got CS2, address = %lx\n", mem_base);
if (!request_mem_region(mem_base, SZ_16M, "mem_fpga")) {
printk(KERN_ERR "Request_mem_region failed.\n");
gpmc_cs_free(GPMC_CS);
return -1;
}
val = gpmc_read_cs_reg(GPMC_CS, GPMC_CS_CONFIG7);
printk("GPMC_CS_CONFIG7 value 0x%x\n", val);
fpga_base = ioremap(mem_base, SZ_16M);
printk("fpga_base, address = %lx\n", fpga_base);
fpga_ver_read();
val = gpmc_read_cs_reg(GPMC_CS, GPMC_CS_CONFIG7);
printk("GPMC_CS_CONFIG7 value 0x%x\n", val);
return 0;
}