免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 611 | 回复: 0
打印 上一主题 下一主题

2.6.33+2440 led 灯 驱动程序 代码分析 (三) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-20 09:44 |只看该作者 |倒序浏览

代码查看:http://lxr.linux.no
我们直接看代码

1.

  1. #define S3C2410_GPBCON S3C2410_GPIOREG(0x10)
  2. #define S3C2410_GPBDAT S3C2410_GPIOREG(0x14)
  3. #define S3C2410_GPBUP S3C2410_GPIOREG(0x18)


等同于

 #define S3C2410_GPBCON (*(volatile unsigned long *)0x56000010)
 #define S3C2410_GPBDAT (*(volatile unsigned long *)0x56000014)
 #define S3C2410_GPBUP (*(volatile unsigned long *)0x56000018)


  这里,我们自己定义  3 个寄存器的地址
      S3C2410_GPIOREG定义在     arch/arm/mach-s3c2410/include/mach/regs-gpio.h

  1. #define S3C2410_GPIOREG(x) ((x) + S3C24XX_VA_GPIO)
  2. #define S3C24XX_GPIOREG2(x) ((x) + S3C24XX_VA_GPIO2)
S3C24XX_VA_GPIO:定义在linux/include/asm-arm/plat-s3c24xx/map.h
  1. 72 #define S3C2410_PA_GPIO (0x56000000)

而在 S3C2440手册中,我们定义了

  1. Register Address R/W Description Reset Value

  2. GPBCON 0x56000010 R/W Configures the pins of port B 0x0

  3. GPBDAT 0x56000014 R/W The data register for port B Undef.

  4. GPBUP 0x56000018 R/W Pull-up disable register for port B
  1. #define S3C2410_GPBCON S3C2410_GPIOREG(0x10)
等同于
  #define S3C2410_GPBCON (*volatile unsigned long *)(0x56000000+0x10)



2.设置管脚

  1. #define S3C2410_GPB5 S3C2410_GPIONO(S3C2410_GPIO_BANKB, 5)
  2. #define S3C2410_GPB6 S3C2410_GPIONO(S3C2410_GPIO_BANKB, 6)
  3. #define S3C2410_GPB7 S3C2410_GPIONO(S3C2410_GPIO_BANKB, 7)
  4. #define S3C2410_GPB8 S3C2410_GPIONO(S3C2410_GPIO_BANKB, 8)
S3C2410_GPIONO 定义在: arch/arm/mach-s3c2410/include/mach/gpio-nrs.h

  1. 17#define S3C2410_GPIONO(bank,offset) ((bank) + (offset))
  2. 18
  3. 19#define S3C2410_GPIO_BANKA (32*0)
  4. 20#define S3C2410_GPIO_BANKB (32*1)   有疑问??



3. 设置输出管脚
  1. #define S3C2410_GPB5_OUTP (0x01 << 10)
  2. #define S3C2410_GPB6_OUTP (0x01 << 12)
  3. #define S3C2410_GPB7_OUTP (0x01 << 14)
  4. #define S3C2410_GPB8_OUTP (0x01 << 16)
在 S3C2440 手册中定义了,当为 01 时,表示输出功能
  1. GPB8 [17:16] 00 = Input 01 = Output
  2.              10 = nXDREQ1 11 = Reserved

  3. GPB7 [15:14] 00 = Input 01 = Output
  4.              10 = nXDACK1 11 = Reserved

  5. GPB6 [13:12] 00 = Input 01 = Output
  6.              10 = nXBREQ 11 = reserved

  7. GPB5 [11:10] 00 = Input 01 = Output
  8.              10 = nXBACK 11 = reserved

4.设置
  1. static unsigned long gpio_table [] =
  2. {
  3.     S3C2410_GPB(5),
  4.     S3C2410_GPB(6),
  5.     S3C2410_GPB(7),
  6.     S3C2410_GPB(8),
  7. };
在哪里定义了 S3C2410_GPB(5)呢??arch/arm/mach-s3c2410/include/mach/gpio-nrs.h
  1. 60    /* S3C2410 GPIO number definitions. */
  2. 61
  3. 62    #define S3C2410_GPA(_nr) (S3C2410_GPIO_A_START + (_nr))
  4. 63    #define S3C2410_GPB(_nr) (S3C2410_GPIO_B_START + (_nr))
  1.      enum s3c_gpio_number {
  2. 48   S3C2410_GPIO_A_START = 0,  ?? 是虚拟内存,映射实现?? 第一个地址 0
  3. 49   S3C2410_GPIO_B_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_A),  32+0吗??
  4. 50   S3C2410_GPIO_C_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_B),

 S3C2410_GPB(5) () 0x56000010+


5 管脚设置

  1. s3c2410_gpio_setpin(gpio_table[arg], 0);
::::
  s3c2410_gpio_setpin( S3C2410_GPB(5),0);
s3c2410_gpio_setpin 定义在: arch/arm/mach-s3c2410/include/mach/gpio-fns.h
  1. 99   extern int s3c2410_gpio_getpull(unsigned int pin);
  2. 100
  3. 101  extern void s3c2410_gpio_setpin(unsigned int pin, unsigned int to);
  4. 102
  5. 103  extern unsigned int s3c2410_gpio_getpin(unsigned int pin);
s3c2410_gpio_setpin 代码实现在:linux/arch/arm/plat-s3c24xx/gpio.c

  1.        void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
  2.  140   {
  3.  141      void __iomem *base = S3C24XX_GPIO_BASE(pin);
  4.  142      unsigned long offs = S3C2410_GPIO_OFFSET(pin);
  5.  143      unsigned long flags;
  6.  144      unsigned long dat;
  7.  145
  8.  146      local_irq_save(flags);
  9.  147
  10.  148      dat = __raw_readl(base + 0x04);
  11.  149      dat &= ~(1 << offs);
  12.  150      dat |= to << offs;
  13.  151      __raw_writel(dat, base + 0x04);
  14.  152
  15.  153     local_irq_restore(flags);
  16.  154  }
  17.  155
  18.  156  EXPORT_SYMBOL(s3c2410_gpio_setpin);

不知道 怎么实现的 ????





6 上网看看资料,以后补充


您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP