mini2440的时钟

mini2440上为了降低电磁干扰配备了12MHz的晶振,如果直接给当做cpu的时钟,那这个s3c2440a就屈才了。幸好cpu内部自带了MPLL将晶振时钟倍频使得cpu工作在FCLk及AHB总线上的外设工作在HCLK和APB总线上的外设工作在PCLK。当然还配有一个UPLL来产生恒定的48MHZ以支持usb2.0.
①.时钟源选择
在系统复位时检测引脚OM3:OM2,若是0:0,则主时钟源选择外部晶振,usb时钟源选择外部晶振

②.MPLLCON  main pll control  主时钟寄存器控制
用于设定FCLK和Fin的倍数。


Mpll(FCLK) = ( 2 × m × Fin ) / ( p × 2^s )
其中m=MDIV+8, p=PDIV+2, s=SDIV,Fin晶振频率

比如
Fin=12MHz
MDIV=0x7F=127,m=135
PDIV=2,p=4
SDIV=1,s=1
则FCLK=405MHz

注意:系统复位时,必须写一次
MPLLCON   UPLLCON ,这样系统才能正常工作。即使不改变其值,即使复位后MPLL UPLL都是使能的,也要写一次,另外还有如下   



③.CLKDIVN clock divider control 时钟分频控制寄存器 
用于设置 FCLK  HCLK PCLK三者的比例


而CAMDIVN如下

比如
CAMDIVN[8]=0
CAMDIVN[9]=0
HDIVN=2,则HCLK=FCLK / 4
PDIVN=1,,则PCLK=HCLK / 2

有以下示例,摘自嵌入式linux开发完全手册
 



/*********************************************************************************************************************************/
2011-12-18
2440的片内外设时钟使能控制


linux下将各个片内外设时钟统一管理,组成时钟队列。
arch/arm/plat-s3c24xx/s3c2410-clock.c
/* standard clock definitions */

static struct clk init_clocks_disable[] = {
	{
		.name		= "nand",
		.id		= -1,
		.parent		= &clk_h,
		.enable		= s3c2410_clkcon_enable,
		.ctrlbit	= S3C2410_CLKCON_NAND,
	}, {
		.name		= "sdi",
		.id		= -1,
		.parent		= &clk_p,
		.enable		= s3c2410_clkcon_enable,
		.ctrlbit	= S3C2410_CLKCON_SDI,
	}, {
		.name		= "adc",
		.id		= -1,
		.parent		= &clk_p,
		.enable		= s3c2410_clkcon_enable,
		.ctrlbit	= S3C2410_CLKCON_ADC,
	}, {
		.name		= "i2c",
		.id		= -1,
		.parent		= &clk_p,
		.enable		= s3c2410_clkcon_enable,
		.ctrlbit	= S3C2410_CLKCON_IIC,
	}, {
		.name		= "iis",
		.id		= -1,
		.parent		= &clk_p,
		.enable		= s3c2410_clkcon_enable,
		.ctrlbit	= S3C2410_CLKCON_IIS,
	}, {
		.name		= "spi",
		.id		= -1,
		.parent		= &clk_p,
		.enable		= s3c2410_clkcon_enable,
		.ctrlbit	= S3C2410_CLKCON_SPI,
	}
};

static struct clk init_clocks[] = {
	{
		.name		= "lcd",
		.id		= -1,
		.parent		= &clk_h,
		.enable		= s3c2410_clkcon_enable,
		.ctrlbit	= S3C2410_CLKCON_LCDC,
	}, {
		.name		= "gpio",
		.id		= -1,
		.parent		= &clk_p,
		.enable		= s3c2410_clkcon_enable,
		.ctrlbit	= S3C2410_CLKCON_GPIO,
	}, {
		.name		= "usb-host",
		.id		= -1,
		.parent		= &clk_h,
		.enable		= s3c2410_clkcon_enable,
		.ctrlbit	= S3C2410_CLKCON_USBH,
	}, {
		.name		= "usb-device",
		.id		= -1,
		.parent		= &clk_h,
		.enable		= s3c2410_clkcon_enable,
		.ctrlbit	= S3C2410_CLKCON_USBD,
	}, {
		.name		= "timers",
		.id		= -1,
		.parent		= &clk_p,
		.enable		= s3c2410_clkcon_enable,
		.ctrlbit	= S3C2410_CLKCON_PWMT,
	}, {
		.name		= "uart",
		.id		= 0,
		.parent		= &clk_p,
		.enable		= s3c2410_clkcon_enable,
		.ctrlbit	= S3C2410_CLKCON_UART0,
	}, {
		.name		= "uart",
		.id		= 1,
		.parent		= &clk_p,
		.enable		= s3c2410_clkcon_enable,
		.ctrlbit	= S3C2410_CLKCON_UART1,
	}, {
		.name		= "uart",
		.id		= 2,
		.parent		= &clk_p,
		.enable		= s3c2410_clkcon_enable,
		.ctrlbit	= S3C2410_CLKCON_UART2,
	}, {
		.name		= "rtc",
		.id		= -1,
		.parent		= &clk_p,
		.enable		= s3c2410_clkcon_enable,
		.ctrlbit	= S3C2410_CLKCON_RTC,
	}, {
		.name		= "watchdog",
		.id		= -1,
		.parent		= &clk_p,
		.ctrlbit	= 0,
	}, {
		.name		= "usb-bus-host",
		.id		= -1,
		.parent		= &clk_usb_bus,
	}, {
		.name		= "usb-bus-gadget",
		.id		= -1,
		.parent		= &clk_usb_bus,
	},
};

//在需要操作各个外设的时钟时,就调用用内核提供的各个函数即可。如摘自mini2440_adc.c
static struct clk    *adc_clock;
adc_clock = clk_get(NULL, "adc");//获取时钟
if (!adc_clock) {
printk(KERN_ERR "failed to get adc clock source\n");
return -ENOENT;
}
clk_enable(adc_clock);//使能时钟

//在不需要时,禁止掉
if (adc_clock) {
clk_disable(adc_clock);//禁止时钟
clk_put(adc_clock);
adc_clock = NULL;//源码下是一个空操作,可能是预留
}
此文的adc不错哦,记一下网址
http://www.cnblogs.com/hanyan225/archive/2011/03/29/1998667.html


posted on 2011-10-21 08:38  _song  阅读(350)  评论(0编辑  收藏  举报