LED驱动GPIO相关头文件简要分析

来源:互联网 发布:网络禁书四十 编辑:程序博客网 时间:2024/05/10 12:24

在简要介绍了led驱动相关头文件的基础上(参考:点击打开链接),可以发现这些头文件里面包含了很多gpio的宏定义和gpio的操作函数。利用这些宏定义和操作函数,我们就能够很好地控制gpio以达到我们的目的。GPIO相关的的头文件包括<mach/gpio.h>、<plat/regs-gpio.h>和<plat/gpio-cfg.h>。下面是对这些头文件进行简单的分析,如有不正确,希望留言指正:

一、<mach/gpio.h>头文件:
[cpp] view plaincopy
  1. /* linux/arch/arm/mach-s3c6400/include/mach/gpio.h  
  2.  *  
  3.  * Copyright 2008 Openmoko, Inc.  
  4.  * Copyright 2008 Simtec Electronics  
  5.  *  http://armlinux.simtec.co.uk/  
  6.  *  Ben Dooks <ben@simtec.co.uk>  
  7.  *  
  8.  * S3C6400 - GPIO lib support  
  9.  *  
  10.  * This program is free software; you can redistribute it and/or modify  
  11.  * it under the terms of the GNU General Public License version 2 as  
  12.  * published by the Free Software Foundation.  
  13. */    
  14.     
  15. #define gpio_get_value  __gpio_get_value   //对gpio单个引脚的读函数进行了宏定义  
  16. #define gpio_set_value  __gpio_set_value   //对gpio单个引脚的写函数进行了宏定义  
  17. #define gpio_cansleep   __gpio_cansleep   //???  
  18. #define gpio_to_irq __gpio_to_irq   //???  
  19.     
  20. /* GPIO bank sizes */    
  21. //这里对每个端口(gpioa--gpioq)的引脚个数进行了宏定义  
  22. #define S3C64XX_GPIO_A_NR   (8)     
  23. #define S3C64XX_GPIO_B_NR   (7)     
  24. #define S3C64XX_GPIO_C_NR   (8)     
  25. #define S3C64XX_GPIO_D_NR   (5)     
  26. #define S3C64XX_GPIO_E_NR   (5)     
  27. #define S3C64XX_GPIO_F_NR   (16)     
  28. #define S3C64XX_GPIO_G_NR   (7)     
  29. #define S3C64XX_GPIO_H_NR   (10)     
  30. #define S3C64XX_GPIO_I_NR   (16)     
  31. #define S3C64XX_GPIO_J_NR   (12)     
  32. #define S3C64XX_GPIO_K_NR   (16)     
  33. #define S3C64XX_GPIO_L_NR   (15)     
  34. #define S3C64XX_GPIO_M_NR   (6)     
  35. #define S3C64XX_GPIO_N_NR   (16)     
  36. #define S3C64XX_GPIO_O_NR   (16)     
  37. #define S3C64XX_GPIO_P_NR   (15)     
  38. #define S3C64XX_GPIO_Q_NR   (9)     
  39.     
  40. /* GPIO bank numbes */    
  41.     
  42. /* CONFIG_S3C_GPIO_SPACE allows the user to select extra  
  43.  * space for debugging purposes so that any accidental  
  44.  * change from one gpio bank to another can be caught.  
  45. */    
  46.     
  47. #define S3C64XX_GPIO_NEXT(__gpio) \     
  48.     ((__gpio##_START) + (__gpio##_NR) + CONFIG_S3C_GPIO_SPACE + 1)    
  49. //用黏贴符号(双#号)来运算的,以A组的0起始,依次加每组的GPIO个数    
  50. enum s3c_gpio_number {    
  51.     S3C64XX_GPIO_A_START = 0,                                            
  52.     S3C64XX_GPIO_B_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_A),    
  53.     S3C64XX_GPIO_C_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_B),    
  54.     S3C64XX_GPIO_D_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_C),    
  55.     S3C64XX_GPIO_E_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_D),    
  56.     S3C64XX_GPIO_F_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_E),    
  57.     S3C64XX_GPIO_G_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_F),    
  58.     S3C64XX_GPIO_H_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_G),    
  59.     S3C64XX_GPIO_I_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_H),    
  60.     S3C64XX_GPIO_J_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_I),    
  61.     S3C64XX_GPIO_K_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_J),    
  62.     S3C64XX_GPIO_L_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_K),    
  63.     S3C64XX_GPIO_M_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_L),    
  64.     S3C64XX_GPIO_N_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_M),    
  65.     S3C64XX_GPIO_O_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_N),    
  66.     S3C64XX_GPIO_P_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_O),    
  67.     S3C64XX_GPIO_Q_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_P),    
  68. };    
  69.     
  70. /* S3C64XX GPIO number definitions. */    
  71.  //以下定义了单个引脚的号码,在某些函数中我们可以直接这些宏定义访问单个引脚   
  72. #define S3C64XX_GPA(_nr)  (S3C64XX_GPIO_A_START + (_nr))     
  73. #define S3C64XX_GPB(_nr)    (S3C64XX_GPIO_B_START + (_nr))     
  74. #define S3C64XX_GPC(_nr)    (S3C64XX_GPIO_C_START + (_nr))     
  75. #define S3C64XX_GPD(_nr)    (S3C64XX_GPIO_D_START + (_nr))     
  76. #define S3C64XX_GPE(_nr)    (S3C64XX_GPIO_E_START + (_nr))     
  77. #define S3C64XX_GPF(_nr)    (S3C64XX_GPIO_F_START + (_nr))     
  78. #define S3C64XX_GPG(_nr)    (S3C64XX_GPIO_G_START + (_nr))     
  79. #define S3C64XX_GPH(_nr)    (S3C64XX_GPIO_H_START + (_nr))     
  80. #define S3C64XX_GPI(_nr)    (S3C64XX_GPIO_I_START + (_nr))     
  81. #define S3C64XX_GPJ(_nr)    (S3C64XX_GPIO_J_START + (_nr))     
  82. #define S3C64XX_GPK(_nr)    (S3C64XX_GPIO_K_START + (_nr))     
  83. #define S3C64XX_GPL(_nr)    (S3C64XX_GPIO_L_START + (_nr))     
  84. #define S3C64XX_GPM(_nr)    (S3C64XX_GPIO_M_START + (_nr))     
  85. #define S3C64XX_GPN(_nr)    (S3C64XX_GPIO_N_START + (_nr))     
  86. #define S3C64XX_GPO(_nr)    (S3C64XX_GPIO_O_START + (_nr))     
  87. #define S3C64XX_GPP(_nr)    (S3C64XX_GPIO_P_START + (_nr))     
  88. #define S3C64XX_GPQ(_nr)    (S3C64XX_GPIO_Q_START + (_nr))     
  89.     
  90. /* the end of the S3C64XX specific gpios */    
  91. //定义了引脚号的范围,引脚号必须小于这个数,不然就是无效的  
  92. #define S3C64XX_GPIO_END    (S3C64XX_GPQ(S3C64XX_GPIO_Q_NR) + 1)     
  93. #define S3C_GPIO_END        S3C64XX_GPIO_END    
  94.      
  95. /* define the number of gpios we need to the one after the GPQ() range */   
  96. //与上面一样,定义了引脚的总个数,引脚号不能超过这个数,我们可以利用它判断某个引脚编号的有效性。   
  97. #define ARCH_NR_GPIOS   (S3C64XX_GPQ(S3C64XX_GPIO_Q_NR) + 1)    
  98.                                                                   
  99. //由上面的分析可知,这个头文件对s3c64xx系列的芯片的引脚进行了统一的编号,按GPA-->GPQ的顺序对给每个引脚编了个号。  
  100.   
  101. #include <asm-generic/gpio.h> //这个头文件是包含在此文件中的,它里面包含了许多gpio的操作函数,而这些函数可以直接使用上述宏定义对具体的单个引脚进行操作,如下:  
[cpp] view plaincopy
  1. #ifndef _ASM_GENERIC_GPIO_H  
  2. #define _ASM_GENERIC_GPIO_H  
  3.   
  4. #include <linux/types.h>  
  5. #include <linux/errno.h>  
  6.   
  7. #ifdef CONFIG_GPIOLIB  
  8.   
  9. #include <linux/compiler.h>  
  10.   
  11. /* Platforms may implement their GPIO interface with library code, 
  12.  * at a small performance cost for non-inlined operations and some 
  13.  * extra memory (for code and for per-GPIO table entries). 
  14.  * 
  15.  * While the GPIO programming interface defines valid GPIO numbers 
  16.  * to be in the range 0..MAX_INT, this library restricts them to the 
  17.  * smaller range 0..ARCH_NR_GPIOS-1. 
  18.  */  
  19.   
  20. #ifndef ARCH_NR_GPIOS  
  21. #define ARCH_NR_GPIOS       256  
  22. #endif  
  23.   
  24. static inline int gpio_is_valid(int number)  
  25. {  
  26.     /* only some non-negative numbers are valid */  
  27.     return ((unsigned)number) < ARCH_NR_GPIOS;  
  28. }  
  29.   
  30. struct seq_file;  
  31. struct module;  
  32.   
  33. /** 
  34.  * struct gpio_chip - abstract a GPIO controller 
  35.  * @label: for diagnostics 
  36.  * @dev: optional device providing the GPIOs 
  37.  * @owner: helps prevent removal of modules exporting active GPIOs 
  38.  * @request: optional hook for chip-specific activation, such as 
  39.  *  enabling module power and clock; may sleep 
  40.  * @free: optional hook for chip-specific deactivation, such as 
  41.  *  disabling module power and clock; may sleep 
  42.  * @direction_input: configures signal "offset" as input, or returns error 
  43.  * @get: returns value for signal "offset"; for output signals this 
  44.  *  returns either the value actually sensed, or zero 
  45.  * @direction_output: configures signal "offset" as output, or returns error 
  46.  * @set: assigns output value for signal "offset" 
  47.  * @to_irq: optional hook supporting non-static gpio_to_irq() mappings; 
  48.  *  implementation may not sleep 
  49.  * @dbg_show: optional routine to show contents in debugfs; default code 
  50.  *  will be used when this is omitted, but custom code can show extra 
  51.  *  state (such as pullup/pulldown configuration). 
  52.  * @base: identifies the first GPIO number handled by this chip; or, if 
  53.  *  negative during registration, requests dynamic ID allocation. 
  54.  * @ngpio: the number of GPIOs handled by this controller; the last GPIO 
  55.  *  handled is (base + ngpio - 1). 
  56.  * @can_sleep: flag must be set iff get()/set() methods sleep, as they 
  57.  *  must while accessing GPIO expander chips over I2C or SPI 
  58.  * 
  59.  * A gpio_chip can help platforms abstract various sources of GPIOs so 
  60.  * they can all be accessed through a common programing interface. 
  61.  * Example sources would be SOC controllers, FPGAs, multifunction 
  62.  * chips, dedicated GPIO expanders, and so on. 
  63.  * 
  64.  * Each chip controls a number of signals, identified in method calls 
  65.  * by "offset" values in the range 0..(@ngpio - 1).  When those signals 
  66.  * are referenced through calls like gpio_get_value(gpio), the offset 
  67.  * is calculated by subtracting @base from the gpio number. 
  68.  */  
  69. struct gpio_chip {  
  70.     const char      *label;  
  71.     struct device       *dev;  
  72.     struct module       *owner;  
  73.   
  74.     int         (*request)(struct gpio_chip *chip,  
  75.                         unsigned offset);  
  76.     void            (*free)(struct gpio_chip *chip,  
  77.                         unsigned offset);  
  78.   
  79.     int         (*direction_input)(struct gpio_chip *chip,  
  80.                         unsigned offset);  
  81.     int         (*get)(struct gpio_chip *chip,  
  82.                         unsigned offset);  
  83.     int         (*direction_output)(struct gpio_chip *chip,  
  84.                         unsigned offset, int value);  
  85.     void            (*set)(struct gpio_chip *chip,  
  86.                         unsigned offset, int value);  
  87.   
  88.     int         (*to_irq)(struct gpio_chip *chip,  
  89.                         unsigned offset);  
  90.   
  91.     void            (*dbg_show)(struct seq_file *s,  
  92.                         struct gpio_chip *chip);  
  93.     int         base;  
  94.     u16         ngpio;  
  95.     unsigned        can_sleep:1;  
  96.     unsigned        exported:1;  
  97. };  
  98.   
  99. extern const char *gpiochip_is_requested(struct gpio_chip *chip,  
  100.             unsigned offset);  
  101. extern int __must_check gpiochip_reserve(int start, int ngpio);  
  102.   
  103. /* add/remove chips */  
  104. extern int gpiochip_add(struct gpio_chip *chip);  
  105. extern int __must_check gpiochip_remove(struct gpio_chip *chip);  
  106.   
  107.   
  108. /* Always use the library code for GPIO management calls, 
  109.  * or when sleeping may be involved. 
  110.  */  
  111. extern int gpio_request(unsigned gpio, const char *label);  
  112. //通过查看该gpio保存的记录标志是否为NULL来判断GPIO是否被占用,并为它去个*lable   
  113. //例如:if(gpio_request(S3C64XX_GPB(0), "GPB"))  
  114.   
  115. extern void gpio_free(unsigned gpio);  
  116. //释放gpio,就是把对应GPIO口的控制标志FLAG_REQUESTED清掉,成NULL,之后可以再被其他调用。  
  117.   
  118. extern int gpio_direction_input(unsigned gpio);  
  119. //将gpio配置成输入模式  
  120. extern int gpio_direction_output(unsigned gpio, int value);  
  121. //将gpio配置成输出模式,并且将gpio置为value,  
  122. //例如:gpio_direction_output (S3C64XX_GPB(0), 1)  
  123.   
  124. extern int gpio_get_value_cansleep(unsigned gpio);//???  
  125. extern void gpio_set_value_cansleep(unsigned gpio, int value);//???  
  126.   
  127.   
  128. /* A platform's <asm/gpio.h> code may want to inline the I/O calls when 
  129.  * the GPIO is constant and refers to some always-present controller, 
  130.  * giving direct access to chip registers and tight bitbanging loops. 
  131.  */  
  132. extern int __gpio_get_value(unsigned gpio);  
  133. //读取gpio的值  
  134. extern void __gpio_set_value(unsigned gpio, int value);  
  135. //设置gpio的值为value  
  136.   
  137. extern int __gpio_cansleep(unsigned gpio);//???  
  138.   
  139. extern int __gpio_to_irq(unsigned gpio);///???  
  140.   
  141. #ifdef CONFIG_GPIO_SYSFS  
  142.   
  143. /* 
  144.  * A sysfs interface can be exported by individual drivers if they want, 
  145.  * but more typically is configured entirely from userspace. 
  146.  */  
  147. extern int gpio_export(unsigned gpio, bool direction_may_change);  
  148. extern void gpio_unexport(unsigned gpio);  
  149.   
  150. #endif  /* CONFIG_GPIO_SYSFS */  
  151.   
  152. #else   /* !CONFIG_HAVE_GPIO_LIB */  
  153.   
  154. static inline int gpio_is_valid(int number)  
  155. {  
  156.     /* only non-negative numbers are valid */  
  157.     return number >= 0;  
  158. }  
  159.   
  160. /* platforms that don't directly support access to GPIOs through I2C, SPI, 
  161.  * or other blocking infrastructure can use these wrappers. 
  162.  */  
  163.   
  164. static inline int gpio_cansleep(unsigned gpio)  
  165. {  
  166.     return 0;  
  167. }  
  168.   
  169. static inline int gpio_get_value_cansleep(unsigned gpio)  
  170. {  
  171.     might_sleep();  
  172.     return gpio_get_value(gpio);  
  173. }  
  174.   
  175. static inline void gpio_set_value_cansleep(unsigned gpio, int value)  
  176. {  
  177.     might_sleep();  
  178.     gpio_set_value(gpio, value);  
  179. }  
  180.   
  181. #endif /* !CONFIG_HAVE_GPIO_LIB */  
  182.   
  183. #ifndef CONFIG_GPIO_SYSFS  
  184.   
  185. /* sysfs support is only available with gpiolib, where it's optional */  
  186.   
  187. static inline int gpio_export(unsigned gpio, bool direction_may_change)  
  188. {  
  189.     return -ENOSYS;  
  190. }  
  191.   
  192. static inline void gpio_unexport(unsigned gpio)  
  193. {  
  194. }  
  195. #endif  /* CONFIG_GPIO_SYSFS */  
  196.   
  197. #endif /* _ASM_GENERIC_GPIO_H */  
[cpp] view plaincopy
  1. 二、<plat/regs-gpio.h>头文件:  
[cpp] view plaincopy
  1. /* linux/arch/arm/plat-s3c64xx/include/plat/regs-gpio.h  
  2.  *  
  3.  * Copyright 2008 Openmoko, Inc.  
  4.  * Copyright 2008 Simtec Electronics  
  5.  *      Ben Dooks <ben@simtec.co.uk>  
  6.  *      http://armlinux.simtec.co.uk/  
  7.  *  
  8.  * S3C64XX - GPIO register definitions  
  9.  */    
  10.     
  11. #ifndef __ASM_PLAT_S3C64XX_REGS_GPIO_H     
  12. #define __ASM_PLAT_S3C64XX_REGS_GPIO_H __FILE__     
  13. //这里包含了从a-q的相关头文件,这些头文件里分别是gpa-gpq相关的宏,  
  14. //以下只列出<plat/gpio-bank-m.h>中的内容   
  15. #include <plat/gpio-bank-a.h>     
  16. #include <plat/gpio-bank-b.h>     
  17. #include <plat/gpio-bank-c.h>     
  18. #include <plat/gpio-bank-d.h>     
  19. #include <plat/gpio-bank-e.h>     
  20. #include <plat/gpio-bank-f.h>     
  21. #include <plat/gpio-bank-g.h>     
  22. #include <plat/gpio-bank-h.h>     
  23. #include <plat/gpio-bank-i.h>     
  24. #include <plat/gpio-bank-j.h>     
  25. #include <plat/gpio-bank-k.h>     
  26. #include <plat/gpio-bank-l.h>  
  27. #include <plat/gpio-bank-m.h>     
  28. #include <plat/gpio-bank-n.h>     
  29. #include <plat/gpio-bank-q.h>     
  30. #include <plat/gpio-bank-o.h>     
  31. #include <plat/gpio-bank-p.h>     
  32. #include <plat/gpio-bank-q.h>     
  33. #include <mach/map.h>     
  34.     
  35. /* Base addresses for each of the banks */    
  36.   
  37. //由虚拟地址加偏移地址计算基地址。以GPM的基地址计算为例:  
  38. //gpm的虚拟地址是S3C64XX_VA_GPIO,定义在mach/map.h中:  
  39.   
  40. //#define S3C64XX_VA_GPIO S3C_ADDR(0x00500000)  
  41. //S3C_ADDR(0x00500000)是定义在plat/map.h中的:  
  42.   
  43. //#define S3C_ADDR(x) ((void __iomem __force *)S3C_ADDR_BASE+ (x))  
  44. //S3C_ADDR_BASE是全局虚拟地址,它的定义是:#define S3C_ADDR_BASE (0xF4000000)  
  45. //void __iomem __force *作用是强制转化为地址  
  46. //综合以上,GPM的宏S3C64XX_GPM_BASE展开的情形是:  
  47. //(0xF4000000+0x00500000)+ 0x0820 = 0xf4500820,括号里面的是虚拟地址,后面的是  
  48. //偏移量,查S3C6410的手册会发现这个地址刚好是GPMCON寄存器的地址!!!!!  
[cpp] view plaincopy
  1. #define S3C64XX_GPA_BASE    (S3C64XX_VA_GPIO + 0x0000)     
  2. #define S3C64XX_GPB_BASE    (S3C64XX_VA_GPIO + 0x0020)     
  3. #define S3C64XX_GPC_BASE    (S3C64XX_VA_GPIO + 0x0040)     
  4. #define S3C64XX_GPD_BASE    (S3C64XX_VA_GPIO + 0x0060)     
  5. #define S3C64XX_GPE_BASE    (S3C64XX_VA_GPIO + 0x0080)     
  6. #define S3C64XX_GPF_BASE    (S3C64XX_VA_GPIO + 0x00A0)     
  7. #define S3C64XX_GPG_BASE    (S3C64XX_VA_GPIO + 0x00C0)     
  8. #define S3C64XX_GPH_BASE    (S3C64XX_VA_GPIO + 0x00E0)     
  9. #define S3C64XX_GPI_BASE    (S3C64XX_VA_GPIO + 0x0100)     
  10. #define S3C64XX_GPJ_BASE    (S3C64XX_VA_GPIO + 0x0120)     
  11. #define S3C64XX_GPK_BASE    (S3C64XX_VA_GPIO + 0x0800)     
  12. #define S3C64XX_GPL_BASE    (S3C64XX_VA_GPIO + 0x0810)     
  13. #define S3C64XX_GPM_BASE    (S3C64XX_VA_GPIO + 0x0820)     
  14. #define S3C64XX_GPN_BASE    (S3C64XX_VA_GPIO + 0x0830)     
  15. #define S3C64XX_GPO_BASE    (S3C64XX_VA_GPIO + 0x0140)     
  16. #define S3C64XX_GPP_BASE    (S3C64XX_VA_GPIO + 0x0160)     
  17. #define S3C64XX_GPQ_BASE    (S3C64XX_VA_GPIO + 0x0180)     
  18. #define S3C64XX_SPC_BASE    (S3C64XX_VA_GPIO + 0x01A0)     
  19. #define S3C64XX_MEM0CONSTOP (S3C64XX_VA_GPIO + 0x01B0)     
  20. #define S3C64XX_MEM1CONSTOP (S3C64XX_VA_GPIO + 0x01B4)     
  21. #define S3C64XX_MEM0CONSLP0 (S3C64XX_VA_GPIO + 0x01C0)     
  22. #define S3C64XX_MEM0CONSLP1 (S3C64XX_VA_GPIO + 0x01C4)     
  23. #define S3C64XX_MEM1CONSLP  (S3C64XX_VA_GPIO + 0x01C8)     
  24. #define S3C64XX_MEM0DRVCON  (S3C64XX_VA_GPIO + 0x01D0)     
  25. #define S3C64XX_MEM1DRVCON  (S3C64XX_VA_GPIO + 0x01D4)     
  26. #define S3C64XX_EINT0CON0   (S3C64XX_VA_GPIO + 0x0900)     
  27. #define S3C64XX_EINT0CON1   (S3C64XX_VA_GPIO + 0x0904)     
  28. #define S3C64XX_EINT0FLTCON0    (S3C64XX_VA_GPIO + 0x0910)     
  29. #define S3C64XX_EINT0FLTCON1    (S3C64XX_VA_GPIO + 0x0914)     
  30. #define S3C64XX_EINT0FLTCON2    (S3C64XX_VA_GPIO + 0x0918)     
  31. #define S3C64XX_EINT0FLTCON3    (S3C64XX_VA_GPIO + 0x091C)     
  32. #define S3C64XX_EINT0MASK   (S3C64XX_VA_GPIO + 0x0920)     
  33. #define S3C64XX_EINT0PEND   (S3C64XX_VA_GPIO + 0x0924)     
  34. #define S3C64XX_SPCONSLP    (S3C64XX_VA_GPIO + 0x0880)     
  35. #define S3C64XX_SLPEN       (S3C64XX_VA_GPIO + 0x0930)     
  36. #define S3C64XX_EINT12CON   (S3C64XX_VA_GPIO + 0x0200)     
  37. #define S3C64XX_EINT34CON   (S3C64XX_VA_GPIO + 0x0204)     
  38. #define S3C64XX_EINT56CON   (S3C64XX_VA_GPIO + 0x0208)     
  39. #define S3C64XX_EINT78CON   (S3C64XX_VA_GPIO + 0x020C)     
  40. #define S3C64XX_EINT9CON    (S3C64XX_VA_GPIO + 0x0210)     
  41. #define S3C64XX_EINT12FLTCON    (S3C64XX_VA_GPIO + 0x0220)     
  42. #define S3C64XX_EINT34FLTCON    (S3C64XX_VA_GPIO + 0x0224)     
  43. #define S3C64XX_EINT56FLTCON    (S3C64XX_VA_GPIO + 0x0228)     
  44. #define S3C64XX_EINT78FLTCON    (S3C64XX_VA_GPIO + 0x022C)     
  45. #define S3C64XX_EINT9FLTCON (S3C64XX_VA_GPIO + 0x0230)     
  46. #define S3C64XX_EINT12MASK  (S3C64XX_VA_GPIO + 0x0240)     
  47. #define S3C64XX_EINT34MASK  (S3C64XX_VA_GPIO + 0x0244)     
  48. #define S3C64XX_EINT56MASK  (S3C64XX_VA_GPIO + 0x0248)     
  49. #define S3C64XX_EINT78MASK  (S3C64XX_VA_GPIO + 0x024C)     
  50. #define S3C64XX_EINT9MASK   (S3C64XX_VA_GPIO + 0x0250)     
  51. #define S3C64XX_EINT12PEND  (S3C64XX_VA_GPIO + 0x0260)     
  52. #define S3C64XX_EINT34PEND  (S3C64XX_VA_GPIO + 0x0264)     
  53. #define S3C64XX_EINT56PEND  (S3C64XX_VA_GPIO + 0x0268)     
  54. #define S3C64XX_EINT78PEND  (S3C64XX_VA_GPIO + 0x026C)     
  55. #define S3C64XX_EINT9PEND   (S3C64XX_VA_GPIO + 0x0270)     
  56. #define S3C64XX_PRIORITY    (S3C64XX_VA_GPIO + 0x0280)     
  57. #define S3C64XX_SERVICE     (S3C64XX_VA_GPIO + 0x0284)     
  58. #define S3C64XX_SERVICEPEND (S3C64XX_VA_GPIO + 0x0288)     
  59.     
  60. /* values for S3C_EXTINT0 */    
  61. #define S3C64XX_EXTINT_LOWLEV    (0x00)     
  62. #define S3C64XX_EXTINT_HILEV     (0x01)     
  63. #define S3C64XX_EXTINT_FALLEDGE  (0x02)     
  64. #define S3C64XX_EXTINT_RISEEDGE  (0x04)     
  65. #define S3C64XX_EXTINT_BOTHEDGE  (0x06)     
  66.     
  67. #endif /* __ASM_PLAT_S3C64XX_REGS_GPIO_H */    
[cpp] view plaincopy
  1. 以下仅列出<plat/gpio-bank-m.h>中的内容:  
[cpp] view plaincopy
  1. /* linux/arch/arm/plat-s3c64xx/include/plat/gpio-bank-m.h  
  2.  *  
  3.  * Copyright 2008 Openmoko, Inc.  
  4.  * Copyright 2008 Simtec Electronics  
  5.  *  Ben Dooks <ben@simtec.co.uk>  
  6.  *  http://armlinux.simtec.co.uk/  
  7.  *  
  8.  * GPIO Bank M register and configuration definitions  
  9.  *  
  10.  * This program is free software; you can redistribute it and/or modify  
  11.  * it under the terms of the GNU General Public License version 2 as  
  12.  * published by the Free Software Foundation.  
  13. */    
  14.     
  15. #define S3C64XX_GPMCON          (S3C64XX_GPM_BASE + 0x00)     
  16. //经过上面的计算容易知道,这个宏就是GPMCON的地址  
  17. #define S3C64XX_GPMDAT          (S3C64XX_GPM_BASE + 0x04)     
  18. //GPMDAT的地址  
  19. #define S3C64XX_GPMPUD          (S3C64XX_GPM_BASE + 0x08)     
  20. //GPMPUD的地址  
  21.     
  22. #define S3C64XX_GPM_CONMASK(__gpio) (0x3 << ((__gpio) * 2))     
  23. #define S3C64XX_GPM_INPUT(__gpio)   (0x0 << ((__gpio) * 2))    
  24. //输入的配置数据宏,将GPMCON与之按位与就能将gpio位配置为输入  
  25. #define S3C64XX_GPM_OUTPUT(__gpio)  (0x1 << ((__gpio) * 2))   
  26. //输出的配置数据宏,将GPMCON与之按位或就能将gpio位配置为输出   
  27.     
  28. #define S3C64XX_GPM0_HOSTIF_CS      (0x02 << 0)     
  29. #define S3C64XX_GPM0_EINT23      (0x03 << 0)     
  30. #define S3C64XX_GPM0_RESERVED1      (0x04 << 0)     
  31. #define S3C64XX_GPM0_DATA_CF10      (0x05 << 0)     
  32. #define S3C64XX_GPM0_CE_CF0      (0x06 << 0)     
  33. #define S3C64XX_GPM0_RESERVED2      (0x07 << 0)     
  34.     
  35. #define S3C64XX_GPM1_HOSTIF_CS_M      (0x02 << 0)     
  36. #define S3C64XX_GPM1_EINT24      (0x03 << 0)     
  37. #define S3C64XX_GPM1_RESERVED1      (0x04 << 0)     
  38. #define S3C64XX_GPM1_DATA_CF11      (0x05 << 0)     
  39. #define S3C64XX_GPM1_CE_CF1      (0x06 << 0)     
  40. #define S3C64XX_GPM1_RESERVED2      (0x07 << 0)     
  41.     
  42. #define S3C64XX_GPM2_HOSTIF_IF_CS_S      (0x02 << 0)     
  43. #define S3C64XX_GPM2_EINT25      (0x03 << 0)     
  44. #define S3C64XX_GPM2_HOSTIF_MDP_VSYNC      (0x04 << 0)     
  45. #define S3C64XX_GPM2_DATA_CF12      (0x05 << 0)     
  46. #define S3C64XX_GPM2_IORD_CF      (0x06 << 0)     
  47. #define S3C64XX_GPM2_RESERVED2      (0x07 << 0)     
  48.     
  49. #define S3C64XX_GPM3_HOSTIF_WE      (0x02 << 0)     
  50. #define S3C64XX_GPM3_EINT26      (0x03 << 0)     
  51. #define S3C64XX_GPM3_RESERVED1      (0x04 << 0)     
  52. #define S3C64XX_GPM3_DATA_CF13      (0x05 << 0)     
  53. #define S3C64XX_GPM3_IOWR_CF      (0x06 << 0)     
  54. #define S3C64XX_GPM3_RESERVED2      (0x07 << 0)     
  55.     
  56. #define S3C64XX_GPM4_HOSTIF_OE      (0x02 << 0)     
  57. #define S3C64XX_GPM4_EINT27      (0x03 << 0)     
  58. #define S3C64XX_GPM4_RESERVED1      (0x04 << 0)     
  59. #define S3C64XX_GPM4_DATA_CF14      (0x05 << 0)     
  60. #define S3C64XX_GPM4_IORDY_CF      (0x06 << 0)     
  61. #define S3C64XX_GPM4_RESERVED2      (0x07 << 0)     
  62.     
  63. #define S3C64XX_GPM5_HOSTIF_INTR      (0x02 << 0)     
  64. #define S3C64XX_GPM5_CF_DATA_DIR      (0x03 << 0)     
  65. #define S3C64XX_GPM5_RESERVED1      (0x04 << 0)     
  66. #define S3C64XX_GPM5_DATA_CF15      (0x05 << 0)     
  67. #define S3C64XX_GPM5_RESERVED2      (0x06 << 0)     
  68. #define S3C64XX_GPM5_RESERVED3      (0x07 << 0)  
[cpp] view plaincopy
  1.    
[cpp] view plaincopy
  1. 三、<plat/gpio-cfg.h>头文件:  
  2. <pre class="cpp" name="code">/* linux/arch/arm/plat-s3c/include/plat/gpio-cfg.h  
  3.  *  
  4.  * Copyright 2008 Openmoko, Inc.  
  5.  * Copyright 2008 Simtec Electronics  
  6.  *  http://armlinux.simtec.co.uk/  
  7.  *  Ben Dooks <ben@simtec.co.uk>  
  8.  *  
  9.  * S3C Platform - GPIO pin configuration  
  10.  *  
  11.  * This program is free software; you can redistribute it and/or modify  
  12.  * it under the terms of the GNU General Public License version 2 as  
  13.  * published by the Free Software Foundation.  
  14. */    
  15.     
  16. /* This file contains the necessary definitions to get the basic gpio  
  17.  * pin configuration done such as setting a pin to input or output or  
  18.  * changing the pull-{up,down} configurations.  
  19.  */    
  20.     
  21. /* Note, this interface is being added to the s3c64xx arch first and will  
  22.  * be added to the s3c24xx systems later.  
  23.  */    
  24.     
  25. #ifndef __PLAT_GPIO_CFG_H     
  26. #define __PLAT_GPIO_CFG_H __FILE__     
  27.     
  28. typedef unsigned int __bitwise__ s3c_gpio_pull_t;    
  29.     
  30. /* forward declaration if gpio-core.h hasn't been included */    
  31. struct s3c_gpio_chip;    
  32.     
  33. /**  
  34.  * struct s3c_gpio_cfg GPIO configuration  
  35.  * @cfg_eint: Configuration setting when used for external interrupt source  
  36.  * @get_pull: Read the current pull configuration for the GPIO  
  37.  * @set_pull: Set the current pull configuraiton for the GPIO  
  38.  * @set_config: Set the current configuration for the GPIO  
  39.  * @get_config: Read the current configuration for the GPIO  
  40.  *  
  41.  * Each chip can have more than one type of GPIO bank available and some  
  42.  * have different capabilites even when they have the same control register  
  43.  * layouts. Provide an point to vector control routine and provide any  
  44.  * per-bank configuration information that other systems such as the  
  45.  * external interrupt code will need.  
  46.  */    
  47. struct s3c_gpio_cfg {    
  48.     unsigned int    cfg_eint;    
  49.     
  50.     s3c_gpio_pull_t (*get_pull)(struct s3c_gpio_chip *chip, unsigned offs);    
  51.     int     (*set_pull)(struct s3c_gpio_chip *chip, unsigned offs,    
  52.                     s3c_gpio_pull_t pull);    
  53.     
  54.     unsigned (*get_config)(struct s3c_gpio_chip *chip, unsigned offs);    
  55.     int  (*set_config)(struct s3c_gpio_chip *chip, unsigned offs,    
  56.                    unsigned config);    
  57. };    
  58.     
  59. #define S3C_GPIO_SPECIAL_MARK   (0xfffffff0)     
  60. #define S3C_GPIO_SPECIAL(x) (S3C_GPIO_SPECIAL_MARK | (x))     
  61.     
  62. /* Defines for generic pin configurations */    
  63. #define S3C_GPIO_INPUT  (S3C_GPIO_SPECIAL(0))     
  64. #define S3C_GPIO_OUTPUT (S3C_GPIO_SPECIAL(1))     
  65. #define S3C_GPIO_SFN(x) (S3C_GPIO_SPECIAL(x))     
  66.     
  67. #define s3c_gpio_is_cfg_special(_cfg) \     
  68.     (((_cfg) & S3C_GPIO_SPECIAL_MARK) == S3C_GPIO_SPECIAL_MARK)    
  69.     
  70. /**  
  71.  * s3c_gpio_cfgpin() - Change the GPIO function of a pin.  
  72.  * @pin The pin number to configure.  
  73.  * @to The configuration for the pin's function.  
  74.  *  
  75.  * Configure which function is actually connected to the external  
  76.  * pin, such as an gpio input, output or some form of special function  
  77.  * connected to an internal peripheral block.  
  78.  */    
  79. extern int s3c_gpio_cfgpin(unsigned int pin, unsigned int to);    
  80. //此宏函数将pin引脚配置成“to”功能,to可以取/* Defines for generic pin configurations */ 中定义的值    
  81. /* Define values for the pull-{up,down} available for each gpio pin.  
  82.  *  
  83.  * These values control the state of the weak pull-{up,down} resistors  
  84.  * available on most pins on the S3C series. Not all chips support both  
  85.  * up or down settings, and it may be dependant on the chip that is being  
  86.  * used to whether the particular mode is available.  
  87.  */    
  88. #define S3C_GPIO_PULL_NONE  ((__force s3c_gpio_pull_t)0x00)     
  89. #define S3C_GPIO_PULL_DOWN  ((__force s3c_gpio_pull_t)0x01)     
  90. #define S3C_GPIO_PULL_UP    ((__force s3c_gpio_pull_t)0x02)     
  91.     
  92. /**  
  93.  * s3c_gpio_setpull() - set the state of a gpio pin pull resistor  
  94.  * @pin: The pin number to configure the pull resistor.  
  95.  * @pull: The configuration for the pull resistor.  
  96.  *  
  97.  * This function sets the state of the pull-{up,down} resistor for the  
  98.  * specified pin. It will return 0 if successfull, or a negative error  
  99.  * code if the pin cannot support the requested pull setting.  
  100. */    
  101. extern int s3c_gpio_setpull(unsigned int pin, s3c_gpio_pull_t pull);  
  102. //将pin引脚的上拉电阻设置成“pull”状态,pull可以去上面宏定义的那些值  
  103.     
  104. /**  
  105.  * s3c_gpio_getpull() - get the pull resistor state of a gpio pin  
  106.  * @pin: The pin number to get the settings for  
  107.  *  
  108.  * Read the pull resistor value for the specified pin.  
  109. */    
  110. extern s3c_gpio_pull_t s3c_gpio_getpull(unsigned int pin);  
  111. //读取pin引脚上拉电阻的状态    
  112.     
  113. #endif /* __PLAT_GPIO_CFG_H */