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.

How to change clock source for GPTIMERs in Linux driver?

Other Parts Discussed in Thread: AM3517

Hi

I have a question regarding the GPTIMERs on AM3517 under Linux.

I'm writing a PWM driver for Linux that use GPTIMER10 for PWM generation by default the timer is setup to use the 32kHz as the clock source.

How do I change the clock source from the 32kHz to the system clock in my driver code?

I'm using the Linux source from AM35x-OMAP35x-PSP-04.02.00.07.

Best regards,
Anders

 

  • So this is the code in the probe function of my PWM driver that tries to change the clock source to the sys_clk.

            pwm_data[i].clk_fck = clk_get(&pdev->dev, clk_fck_id[i]);     // i=0 and clk_fck_id[0] = "gpt10_fck"
            if ( IS_ERR(pwm_data[i].clk_fck)) {
                ret = PTR_ERR(pwm_data[i].clk_fck);
                goto probe_exit;
            }
            
            ret = clk_enable(pwm_data[i].clk_fck);
            if(ret)
            {
                dev_err(&pdev->dev, "Unable to start clk_fck%d, %d\n", i, ret);
                goto probe_exit;
            }

            sys_ck = clk_get(&pdev->dev, "sys_ck");
            if ( IS_ERR(sys_ck) ) {
                ret = PTR_ERR(sys_ck);
                goto probe_exit;
            }
            rate = clk_get_rate(pwm_data[i].clk_fck);
            printk("PWM%d init, sys_ck: %dHz\n", i, rate);

            ret = clk_set_rate(pwm_data[i].clk_fck, rate);
            if(ret)
            {
                dev_err(&pdev->dev, "Unable to set clk rate clk_fck%d, %d\n", i, ret);
                goto probe_exit;
            }

    And I get the following error when booting Linux, an "-EINVAL" from the omap2_clk_set_rate function.

    [    1.680328] at24 1-0050: 16384 byte 24c128 EEPROM (writable)
    [    1.686920] omap_device: omap_i2c.1: new worst case activate latency 0: 91552
    [    1.695404] Read MAC addr from EEPROM: 02:05:7d:04:01:50
    [    1.702423] PWM0 init, sys_ck: 13000000Hz
    [    1.706726] clock: set_rate for clock gpt10_fck to rate 13000000
    [    1.712982] r5cdupwm r5cdupwm.0: Unable to set clk rate clk_fck0, -22
    [    1.719818] r5cdupwm: probe of r5cdupwm.0 failed with error -22
    [    1.729949] R5 CDU LED dirver initialized successfully

    There are no set_rate() functions defined for the GPTIMERs in clock3xxx_data.c.
    Is this the wrong way of doing it, using the clk_set_rate() function, is there any other way?

    Regards,
    Anders

     

  • I solved the problem with changing clock source for the GPTIMERs.

    The clock source is changed by using the clk_set_parent method.

            sys_ck = clk_get(&pdev->dev, "sys_ck");
            if ( IS_ERR(sys_ck) ) {
                ret = PTR_ERR(sys_ck);
                goto probe_exit;
            }
            rate = clk_get_rate(sys_ck);

            ret = clk_set_parent(pwm_data[i].clk_fck, sys_ck);

    // Anders

  •  

     

    Hi Anders Gabert,

    I am also working on am3517 pwm driver, but don't know how to get started,  could you give me some suggestions or would you like to send me yours as my example?

    I'm not very familiar about this, and ti dev-kit doesn't include the pwm driver.

     

     

     

    Thanks,

    Kevin

     

     

  • Hi Kevin

    Sorry for not responding to your message.

    The driver I wrote that include a PWM driver is not that general so maybe that's not the best example code.

    But you can take a look at this page http://elinux.org/BeagleBoard/GSoC/2010_Projects/Pulse_Width_Modulation it's a PWM driver for BeagleBoard and the OMAP3 which has the same PWM circuit as the AM3517. It is the code that I used as an example when writing my driver. Take a look at the code and if you have any questions, feel free to ask.

    //Anders

     

  • Hello,

    Here's another fine tutorial about using OMAP general-purpose hardware timers: I sucessfully compiled and ran it on the AM3517 processor.  As for clock source control, I selected system clock as the source for all the timers my app requests, then 'go with the flow'. The timer driver just enquires about its freqency and live with that. Mine is about 6.5 MHz, which is fine for me because I use the timer to trigger events every 50 ms.

    http://www.kunen.org/uC/beagle/omap_dmtimer.html