s3c2410_gpio_cfgpin函數(shù)解析
位置:/linux-2.6.32.2/arch/arm/plat-s3c24xx/gpio.c
本文引用地址:http://m.butianyuan.cn/article/201611/318857.htm函數(shù)內(nèi)容:
void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int function)
{
void __iomem *base =S3C24XX_GPIO_BASE(pin);
unsigned long mask;
unsigned long con;
unsigned long flags;
if (pin
else {
mask = 3 << S3C2410_GPIO_OFFSET(pin)*2;
}
switch (function) {
caseS3C2410_GPIO_LEAVE:
mask = 0;
function = 0;
break;
caseS3C2410_GPIO_INPUT:
caseS3C2410_GPIO_OUTPUT:
caseS3C2410_GPIO_SFN2:
caseS3C2410_GPIO_SFN3:
if (pin
function &= 1;
function <<= S3C2410_GPIO_OFFSET(pin);
} else {
function &= 3;
function <<= S3C2410_GPIO_OFFSET(pin)*2;
}
}
/* modify the specified register wwith IRQs off */
local_irq_save(flags);
con = __raw_readl(base + 0x00);
con &= ~mask;
con |= function;
__raw_writel(con, base + 0x00);
local_irq_restore(flags);
}
EXPORT_SYMBOL(s3c2410_gpio_cfgpin);
/***************************************************************************
首先確定一下各宏定義所在的位置和意義:
S3C24XX_GPIO_BASE(pin) -->
S3C2410_GPIO_OFFSET(pin)-->
S3C2410_GPIO_INPUT-->
S3C2410_GPIO_OUTPUT-->
S3C2410_GPIO_SFN2-->
S3C2410_GPIO_SFN3-->
以上宏都是在/linux2.6.32.2/arch/arm/mach-s3c2410/include/regs_gpio.h定義.
S3C2410_GPIO_BANKB-->
此宏的定義是在/linux-2.6.32.2/arch/arm/mach-s3c2410/include/mach/gpio-nrs.h中定義.
接下來,順序解析程序:
#define S3c2410_GPIO_BASE(pin) ((((pin) & ~31) >>1) +S3C24XX_VA_GPIO)
S3C24XX_VA_GPIO在/linux-2.6.32.2/arch/arm/plat-s3c24xx/include/plat/map.h中是這樣定義的:
S3C24XX_PA_GPIO在/linux-2.6.32.2/arch/arm/mach-s3c2410/include/mach/map.h中這樣定義:
而S3C2410_PA_GPIO在/linux-2.6.32.2/arch/arm/plat-s3c24xx/include/plat/map.h中這樣定義:
S3C24XX_PA_UART在中這樣定義:
而S3C2410_PA_UART在/linux-2.6.32.2/arch/arm/plat-s3c24xx/include/plat/map.h中這樣定義:
S3C24XX_VA_UART在linux-2.6.32.2/arch/arm/plat-s3c24xx/include/plat/map.h中這樣定義:
而S3C_VA_UART在linux-2.6.32.2/arch/arm/plat-s3c/include/plat/map.h中這樣定義:
由以上宏定義可以推出:
S3C24XX_VA_GPIO=((S3C24XX_PA_GPIO - S3C24XX_PA_UART) + S3C24XX_VA_UART)
=((0x56000000 - 0x50000000) + (0xF4000000 + 0x01000000))
= (0x06000000 + 0xF5000000)
= (0xFB000000)
這里假設設置GPB5引腳為輸出:
s3c2410_gpio_cfgpin(S3C2410_GPB(5),S3C2410_GPB_OUTPUT);
首先S3C2410_GPB(_nr)在/linux-2.6.32.2/arch/arm/mach-s3c2410/include/mach/gpio-nrs.h中這樣定義:
評論