一下是学习附件led的驱动在网上找的资料
比较好
可以参考下
s3c2410_gpio_setpin()在gpio.c中
作用:设置相应GPIO口的值,
如pin=S3C2410_GPB5
to=0
则:设置S3C2410_GPB5的输出值为0
如pin=S3C2410_GPB5
to=1 则:设置S3C2410_GPB5的输出值为1
如pin=S3C2410_GPB5
如pin=S3C2410_GPB5
void s3c2410_gpio_setpin(unsigned int pin, unsigned int
to)
{
void __iomem
*base = S3C2410_GPIO_BASE(pin);
unsigned
long offs = S3C2410_GPIO_OFFSET(pin);
unsigned
long flags;
unsigned
long dat;
{
}
EXPORT_SYMBOL(s3c2410_gpio_setpin);
说明:
1.
S3C2410_GPIO_BASE(pin)-------------
在linux/include/asm/hardware/s3c2410/regs-gpio.h中
#define S3C2410_GPIO_BASE(pin)
((((pin) & ~31) >> 1)
+S3C24XX_VA_GPIO)
1.
S3C2410_GPIO_BASE(pin)-------------
在linux/include/asm/hardware/s3c2410/regs-gpio.h中
#define S3C2410_GPIO_BASE(pin)
S3C24XX_VA_GPIO------------
在linux/include/asm-arm/arch-s3c2410/map.h中
#define S3C24XX_VA_GPIO
S3C2410_ADDR(0x00E00000)
----GPIO的虚拟偏移地址:0x00E00000
#define S3C2410_ADDR(x)
(0xF0000000 + (x))
----所有寄存器的虚拟首地址:0xF0000000
则:
S3C24XX_VA_GPIO =0xF0E0 0000
----GPIO的虚拟首地址
在linux/include/asm-arm/arch-s3c2410/map.h中
#define S3C24XX_VA_GPIO
----GPIO的虚拟偏移地址:0x00E00000
#define S3C2410_ADDR(x)
----所有寄存器的虚拟首地址:0xF0000000
则:
S3C24XX_VA_GPIO =0xF0E0 0000
如:pin = S3C2410_GPB5
而在linux/include/asm/hardware/s3c2410/regs-gpio.h中
#define S3C2410_GPB5
S3C2410_GPIONO(S3C2410_GPIO_BANKB, 5)
#define S3C2410_GPIONO(bank,offset) ((bank) + (offset))
#define S3C2410_GPIO_BANKB (32*1)
则:
S3C2410_GPB5 =32*1+5=37
而在linux/include/asm/hardware/s3c2410/regs-gpio.h中
#define S3C2410_GPB5
#define S3C2410_GPIONO(bank,offset) ((bank) + (offset))
#define S3C2410_GPIO_BANKB (32*1)
则:
S3C2410_GPB5 =32*1+5=37
由:
#define S3C2410_GPIO_BASE(pin)
((((pin) & ~31) >> 1)
+S3C24XX_VA_GPIO)
pin = S3C2410_GPB5 = 37
S3C24XX_VA_GPIO =0xF0E0 0000
则:
S3C2410_GPIO_BASE(S3C2410_GPB5)
((((S3C2410_GPB5) & ~31)
>> 1) +0xF0E0 0000 )
#define S3C2410_GPIO_BASE(pin)
pin = S3C2410_GPB5 = 37
S3C24XX_VA_GPIO =0xF0E0 0000
则:
S3C2410_GPIO_BASE(S3C2410_GPB5)
S3C2410_GPIO_BASE(37)
((((37) & ~31) >> 1)
+0xF0E0 0000 )
S3C2410_GPIO_BASE(37) =((10 0101 &0 0000)>>1)+0xF0E0
0000
=
1 0000+0xF0E0 0000
= 0xF0E1
0000
~31主要是为了清除S3C2410_GPB5的后5位,
~31主要是为了清除S3C2410_GPB5的后5位,
2.
S3C2410_GPIO_OFFSET(pin);
S3C2410_GPIO_OFFSET(pin);
s3c2410_gpio_pullup()在gpio.c中
作用:设置相应GPIO口的上拉电阻,
如pin=S3C2410_GPB5
to=0
则:设置S3C2410_GPB5的不要上拉电阻
如pin=S3C2410_GPB5
to=1 则:设置S3C2410_GPB5的要上拉电阻
如pin=S3C2410_GPB5
如pin=S3C2410_GPB5
void s3c2410_gpio_pullup(unsigned int pin, unsigned int
to)
{
void __iomem *base = S3C24XX_GPIO_BASE(pin);
unsigned long offs = S3C2410_GPIO_OFFSET(pin);
unsigned long flags;
unsigned long up;
{
void __iomem *base = S3C24XX_GPIO_BASE(pin);
unsigned long offs = S3C2410_GPIO_OFFSET(pin);
unsigned long flags;
unsigned long up;
if (pin < S3C2410_GPIO_BANKB)
return;
return;
local_irq_save(flags);
up = __raw_readl(base + 0x08);
[color=Red]up &= ~(1L << offs);
up |= to << offs;[/color]
__raw_writel(up, base + 0x08);
[color=Red]up &= ~(1L << offs);
up |= to << offs;[/color]
__raw_writel(up, base + 0x08);
local_irq_restore(flags);
}
EXPORT_SYMBOL(s3c2410_gpio_pullup);
}
EXPORT_SYMBOL(s3c2410_gpio_pullup);
s3c2410_gpio_cfgpin()在gpio.c中
作用:配置相应GPIO口的功能,
如pin=S3C2410_GPB5
function=00
则:设置S3C2410_GPB5为输入口
如pin=S3C2410_GPB5
function=01 则:设置S3C2410_GPB5为输出口
如pin=S3C2410_GPB5
function=10
则:设置S3C2410_GPB5为多功能口
如pin=S3C2410_GPB5
如pin=S3C2410_GPB5
如pin=S3C2410_GPB5
void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int
function)
{
void __iomem
*base = S3C2410_GPIO_BASE(pin);
unsigned
long mask;
unsigned
long con;
unsigned
long flags;
{
}
EXPORT_SYMBOL(s3c2410_gpio_cfgpin);
s3c2410_gpio_getcfg()在gpio.c中
作用:用于返回相应GPIO口的配置
如:pin=S342410_GPB5
则:返回S3C2410_GPB5的配置情况
如:pin=S342410_GPB5
unsigned int s3c2410_gpio_getcfg(unsigned int pin)
{
void __iomem
*base = S3C2410_GPIO_BASE(pin);
unsigned
long mask;
{
}
EXPORT_SYMBOL(s3c2410_gpio_getcfg);
由简单的LED驱动分析内核源码包中的s3c2410寄存器宏定义及物理/虚拟内存映射 - gmkernel
s3c2410相关 2009-09-16
10:31
阅读29
评论1 字号: 大大
中中 小小
上个月在qq2440的光盘里发现了一段简单的LED驱动程序,大致看了一下明白了大意;但是由于里面的宏定义很是麻烦,看起来绕来绕去,于是我也懒得看明白了,干脆在CU论坛里发了个帖一问了事。
上个月在qq2440的光盘里发现了一段简单的LED驱动程序,大致看了一下明白了大意;但是由于里面的宏定义很是麻烦,看起来绕来绕去,于是我也懒得看明白了,干脆在CU论坛里发了个帖一问了事。
/linux/include/asm/hardware/s3c2410/regs-gpio.h 中:
#define S3C2410_GPIONO(bank,offset) ((bank) + (offset))
#define S3C2410_GPIO_BANKA
(32*0)
#define S3C2410_GPIO_BANKB
(32*1)
#define S3C2410_GPIO_BANKC
(32*2)
....
#define
S3C2410_GPIO_BASE(pin) ((((pin)
& ~31) >> 1) +
S3C24XX_VA_GPIO)
#define S3C2410_GPIO_OFFSET(pin) ((pin) &
31)
#define
S3C2410_GPBCON
S3C2410_GPIOREG(0x10)
#define
S3C2410_GPBDAT
S3C2410_GPIOREG(0x14)
#define
S3C2410_GPBUP
S3C2410_GPIOREG(0x18)
#define
S3C2410_GPB0
S3C2410_GPIONO(S3C2410_GPIO_BANKB, 0)
#define
S3C2410_GPB0_INP
(0x00 << 0)
#define
S3C2410_GPB0_OUTP
(0x01 << 0)
#define S3C2410_GPB0_TOUT0
(0x02 << 0)
#define
S3C2410_GPB1
S3C2410_GPIONO(S3C2410_GPIO_BANKB, 1)
#define
S3C2410_GPB1_INP
(0x00 << 2)
#define
S3C2410_GPB1_OUTP
(0x01 << 2)
#define S3C2410_GPB1_TOUT1
(0x02 << 2)
....
driver中有这样的代码:
其中
static unsigned long led_table [] = {
};
static unsigned int led_cfg_table [] = {
};
void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int
function)
{
}
EXPORT_SYMBOL(s3c2410_gpio_cfgpin);
void s3c2410_gpio_setpin(unsigned int pin, unsigned int
to)
{
}
EXPORT_SYMBOL(s3c2410_gpio_setpin);
#ifndef __ASSEMBLY__
#define
S3C2410_ADDR(x)
((void __iomem *)0xF0000000 + (x))
#else
#define
S3C2410_ADDR(x)
(0xF0000000 +
(x))
#endif
#define
S3C2400_ADDR(x)
S3C2410_ADDR(x)
#define
S3C24XX_VA_GPIO
S3C2410_ADDR(0x00E00000)
#define
S3C2400_PA_GPIO
(0x15600000)
#define
S3C2410_PA_GPIO
(0x56000000)
#define
S3C24XX_SZ_GPIO
SZ_1M
#define
S3C24XX_VA_RTC
S3C2410_ADDR(0x00F00000)
#define
S3C24XX_VA_GPIO
S3C2410_ADDR(0x00E00000)
#define
S3C24XX_VA_IIS
S3C2410_ADDR(0x00D00000) 等等..
#define
S3C2410_GPIO_BASE(pin) ((((pin)
& ~31) >> 1) +
S3C24XX_VA_GPIO)
0x10+S3C24XX_VA_GPIO,GPB是0x20+S3C24XX_VA_GPIO,GPC是0x30+S3C24XX_VA_GPIO...
创建于: 2008-10-06 23:31:23,修改于: 2008-10-06 23:31:23,已浏览592次,有评论6条
网友评论