ARM Linux clock implement

Source: Internet
Author: User

It is not complete enough to write it casually. Remember it for the moment, and there are still some things you haven't figured out !~

 

Recently, we are working on porting the new kernel version, and bringing the original BSP to the latest kernel 2.6.31-rc7 (which has been released again ).

 

When rewriting the system timer (sys_timer), I found that there is always something missing, and I don't know anything. The boss's proposal + refer to Daniel'sCodeAnd found that the BSP did not have the code for clock management, but it was also true that they were able to run the BSP in line with the concept of doing it. If they were not used, they were omitted and cannot blame them. We have to implement it ourselves! Hardware and clock are hard for me, And the principle is still unclear. I have read the kernel code and Datasheet of several boards and found that the clock is basically the same in name, I thought every board was blind.

 

Clock management, the main function is to enable a clock, because a clock source can pass through the frequency of the PLL, coupled with the divisor processing, it can achieve a programmable clock frequency, each hardware module can have its own frequency, and each hardware module can switch the clock independently. So it needs to be managed!

 

Our board mainly involves the following clock types:

PLL: clock from the clock source, which can be understood as the xtal clock source;

Pll_cpu: When providing clock for other hardware modules;

Pll_usb: USB Host Controller clock

Fclk: CPU clock (arm926)

Hclk: hardware module clock on AHB Bus

Pclk: hardware module clock on PHB Bus

RTC: Real-Time Clock

Wdt: watchdog clock

Timer: timer clock

Because timer's clock source can be selected, 1 kHz or pclk, if pclk is selected, it should be calculated from the above hierarchy that the pclk frequency is used by the timer, the clock management seems dispensable, but for expansion, there is still better than none.

 

The following is the implementation, found CLK in ARM Linux, there are two main types, a class such as mach-s3c24xx, their own management clock, a class such as Mach-epxxx using common/clock. c's code manages clock through the kernel. This common code is written by Russell and is also a newly promoted method. Of course I will use it to directly put Mach-epxxx/clock. C and the header file are copied and modified as needed. Ops is not required. Three APIs are provided: enable/disable/get_rate, because the clock operation on this board is relatively simple, this is enough! ~ Haha, there's nothing. By the way, you still need to add clkdev under Mach-xxx/include/Mach. h. Just copy other people. You can see why you need to read the code.

 

That is to say, implementing clock management in ARM Linux is very simple. There are three files:

Mach-xxx/clock. c

Mach-xxx/clock. h

Mach-xxx/include/Mach/clkdev. c

Other files are required to register some clocks, do the work, configure the configuration, and use clk_get () to obtain the clock and then perform the operation, which is quite simple. This is what we do now.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.