分类: LINUX
2011-08-22 11:31:33
函数原型:s3c2410_gpio_cfgpin(unsigned int pin,unsigned int function) 位置:/linux-2.6.32.2/arch/arm/plat-s3c24xx/gpio.c 函数内容: void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int function) if (pin < S3C2410_GPIO_BANKB) { else { switch (function) { case S3C2410_GPIO_INPUT: /* modify the specified register wwith IRQs off */ local_irq_save(flags); con = __raw_readl(base + 0x00); __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中这样定义: ==== http://blog.csdn.net/yming0221/article/details/6543869
{
void __iomem *base = S3C24XX_GPIO_BASE(pin); // 得到某组管脚基地址 GPA或GPB等
unsigned long mask;
unsigned long con;
unsigned long flags;
mask = 1 << S3C2410_GPIO_OFFSET(pin);
}
mask = 3 << S3C2410_GPIO_OFFSET(pin)*2; // 11左移,每个管脚占用两位,GPA占用一位
}
case S3C2410_GPIO_LEAVE:
mask = 0;
function = 0;
break;
case S3C2410_GPIO_OUTPUT:
case S3C2410_GPIO_SFN2:
case S3C2410_GPIO_SFN3:
if (pin < S3C2410_GPIO_BANKB) {
function -= 1;
function &= 1;
function <<= S3C2410_GPIO_OFFSET(pin);
} else {
function &= 3;
function <<= S3C2410_GPIO_OFFSET(pin)*2;
}
}
con &= ~mask;
con |= function;
}