Configuring peripheral timer

Discussion in 'Kernels' started by Puneet, Jan 14, 2019.

  1. Puneet

    Puneet New Member

    Joined:
    Jan 14, 2019
    Messages:
    1
    Likes Received:
    0
    I want to write a kernel module to configure the peripheral timer (using the General Purpose Timer module) on my Udoo Quad board. Currently it is running the below kernel:

    root@udoo:~# uname -a
    Linux udoo 3.14.56-udooqdl-02044-gddaad11 #3 SMP PREEMPT Tue Dec 6 16:26:55 UTC 2016 armv7l armv7l armv7l GNU/Linux

    However, I see that after the board boots up, the timer is already running. I don't know how it gets configured, but the counter value of the timer is seen to be continuously incrementing.

    So I tried to first reset the timer, and then configure the module with my parameters. However, the moment I reset the timer, the board becomes inaccessible and I have to reboot it to be able to access it again (possibly due to a kernel panic).

    Please suggest what I am doing wrong and what should be the correct approach to configure the GPT for Udoo Quad. Any help in this direction would be greatly appreciated.

    Here is the code which crashes the system:
    (Note: I have used this reference manual as the main documentation to configure the timer: https://www.nxp.com/webapp/Download?colCode=IMX6DQRM)

    Code:
    #include <linux/module.h>
    #include <asm/io.h>
    
    MODULE_LICENSE("GPL");
    MODULE_AUTHOR("Puneet Mehta");
    MODULE_DESCRIPTION("Timer with udoo");
    MODULE_VERSION("0.1");
    
    #define BASE 0x2098000
    #define GPT_Control_Register(x)          ((x) + 0)
    
    void __iomem *io;
    
    static int __init MyModuleInit(void)
    {
       int result = 0;
       io = ioremap(BASE, SZ_4K);
       printk(KERN_INFO "Control register value = %x\n", ioread32(GPT_Control_Register(io)));
       iowrite32(ioread32(GPT_Control_Register(io)) | 1<<15, GPT_Control_Register(io));       // sw reset the timer
       return result;
    }
    
    static void __exit MyModuleExit(void)
    {
       printk(KERN_INFO "Good bye!");
    }
    
    module_init(MyModuleInit);
    module_exit(MyModuleExit);
    
     

Share This Page