This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Enabling PWM on TMS320C6A8168 with Linux 2.6.37

Environment:

TMS320C6A8168  

 Linux 2.6.37.psp04-00-01-13.patch2

How do I enable PWM on the TIM6_OUT/GPMC_A[24]/GP0[30]-pin?

Have muxed the pin to TIM6_OUT but can't figure out how to configure the timer module and connect it to the pin.

Where should I look?

  • I figured it out:

    Create a kernel module and use arch/arm/plat-omap/dmtimer.h 

    Example code below to create a 4KHz 50/50 PWM output.

    #include <linux/module.h>
    #include <linux/kernel.h>
    #include <linux/init.h>
    #include <linux/clk.h>
    #include <linux/irq.h>
    #include <linux/interrupt.h>
    #include <asm/io.h>
    #include <plat/dmtimer.h>
    #include <linux/types.h>

    MODULE_AUTHOR("Ulf Tisting <ulf@svep.se>");
    MODULE_DESCRIPTION("TI816xx PWM module");
    MODULE_LICENSE("GPL");

    #define SPEAKER_TIMER_ID 6

    // pointer to timer object
    static struct omap_dm_timer *timer_ptr;

    // initialize the kernel module
    static int __init pwm_init(void)
    {
    struct clk *gt_fclk;
    uint32_t gt_rate;

    // request the GPT6-timer (speaker output)
    timer_ptr = omap_dm_timer_request_specific(SPEAKER_TIMER_ID);
    if(timer_ptr == NULL){
    printk("PWM module : timer connected to speaker unavailable, bailing out\n");
    return -1;
    }

    // set the clock source to system clock
    omap_dm_timer_set_source(timer_ptr, OMAP_TIMER_SRC_SYS_CLK);

    // set prescalar to 1:1
    omap_dm_timer_set_prescaler(timer_ptr, 0);

    // get clock rate in Hz
    gt_fclk = omap_dm_timer_get_fclk(timer_ptr);
    gt_rate = clk_get_rate(gt_fclk);

    // setup Timer Control Register (TCLR) for PWM (SCPWM=1, PT=1, TRG=1)
    omap_dm_timer_set_pwm(timer_ptr, 1, 1, 1);

    // set Timer Load Register (TLDR) to 4KHz (AR=1)
    omap_dm_timer_set_load(timer_ptr, 1, 0xFFFFFFFF - (gt_rate/250));

    // start the timer!
    omap_dm_timer_start(timer_ptr);

    // debug printout
    printk("PWM module : GP Timer initialized and started (%lu Hz)\n",\
    (long unsigned)gt_rate);

    // return success
    return 0;

    }


    // cleanup
    static void __exit pwm_exit(void)
    {
    printk("PWM module : cleanup called\n");

    // stop the timer
    omap_dm_timer_stop(timer_ptr);

    // release the timer
    omap_dm_timer_free(timer_ptr);
    }

    // provide the kernel with the entry/exit routines
    module_init(pwm_init);
    module_exit(pwm_exit);