天天看點

LED驅動GPIO相關頭檔案簡要分析

在簡要介紹了led驅動相關頭檔案的基礎上(參考:點選打開連結),可以發現這些頭檔案裡面包含了很多gpio的宏定義和gpio的操作函數。利用這些宏定義和操作函數,我們就能夠很好地控制gpio以達到我們的目的。GPIO相關的的頭檔案包括<mach/gpio.h>、<plat/regs-gpio.h>和<plat/gpio-cfg.h>。下面是對這些頭檔案進行簡單的分析,如有不正确,希望留言指正:

一、<mach/gpio.h>頭檔案:

[cpp]  view plain copy

  1. #define gpio_get_value  __gpio_get_value   //對gpio單個引腳的讀函數進行了宏定義  
  2. #define gpio_set_value  __gpio_set_value   //對gpio單個引腳的寫函數進行了宏定義  
  3. #define gpio_cansleep   __gpio_cansleep   //???  
  4. #define gpio_to_irq __gpio_to_irq   //???  
  5. //這裡對每個端口(gpioa--gpioq)的引腳個數進行了宏定義  
  6. #define S3C64XX_GPIO_A_NR   (8)     
  7. #define S3C64XX_GPIO_B_NR   (7)     
  8. #define S3C64XX_GPIO_C_NR   (8)     
  9. #define S3C64XX_GPIO_D_NR   (5)     
  10. #define S3C64XX_GPIO_E_NR   (5)     
  11. #define S3C64XX_GPIO_F_NR   (16)     
  12. #define S3C64XX_GPIO_G_NR   (7)     
  13. #define S3C64XX_GPIO_H_NR   (10)     
  14. #define S3C64XX_GPIO_I_NR   (16)     
  15. #define S3C64XX_GPIO_J_NR   (12)     
  16. #define S3C64XX_GPIO_K_NR   (16)     
  17. #define S3C64XX_GPIO_L_NR   (15)     
  18. #define S3C64XX_GPIO_M_NR   (6)     
  19. #define S3C64XX_GPIO_N_NR   (16)     
  20. #define S3C64XX_GPIO_O_NR   (16)     
  21. #define S3C64XX_GPIO_P_NR   (15)     
  22. #define S3C64XX_GPIO_Q_NR   (9)     
  23. #define S3C64XX_GPIO_NEXT(__gpio) \     
  24.     ((__gpio##_START) + (__gpio##_NR) + CONFIG_S3C_GPIO_SPACE + 1)    
  25. //用黏貼符号(雙#号)來運算的,以A組的0起始,依次加每組的GPIO個數    
  26. enum s3c_gpio_number {    
  27.     S3C64XX_GPIO_A_START = 0,                                            
  28.     S3C64XX_GPIO_B_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_A),    
  29.     S3C64XX_GPIO_C_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_B),    
  30.     S3C64XX_GPIO_D_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_C),    
  31.     S3C64XX_GPIO_E_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_D),    
  32.     S3C64XX_GPIO_F_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_E),    
  33.     S3C64XX_GPIO_G_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_F),    
  34.     S3C64XX_GPIO_H_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_G),    
  35.     S3C64XX_GPIO_I_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_H),    
  36.     S3C64XX_GPIO_J_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_I),    
  37.     S3C64XX_GPIO_K_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_J),    
  38.     S3C64XX_GPIO_L_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_K),    
  39.     S3C64XX_GPIO_M_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_L),    
  40.     S3C64XX_GPIO_N_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_M),    
  41.     S3C64XX_GPIO_O_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_N),    
  42.     S3C64XX_GPIO_P_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_O),    
  43.     S3C64XX_GPIO_Q_START = S3C64XX_GPIO_NEXT(S3C64XX_GPIO_P),    
  44. };    
  45.  //以下定義了單個引腳的号碼,在某些函數中我們可以直接這些宏定義通路單個引腳   
  46. #define S3C64XX_GPA(_nr)  (S3C64XX_GPIO_A_START + (_nr))     
  47. #define S3C64XX_GPB(_nr)    (S3C64XX_GPIO_B_START + (_nr))     
  48. #define S3C64XX_GPC(_nr)    (S3C64XX_GPIO_C_START + (_nr))     
  49. #define S3C64XX_GPD(_nr)    (S3C64XX_GPIO_D_START + (_nr))     
  50. #define S3C64XX_GPE(_nr)    (S3C64XX_GPIO_E_START + (_nr))     
  51. #define S3C64XX_GPF(_nr)    (S3C64XX_GPIO_F_START + (_nr))     
  52. #define S3C64XX_GPG(_nr)    (S3C64XX_GPIO_G_START + (_nr))     
  53. #define S3C64XX_GPH(_nr)    (S3C64XX_GPIO_H_START + (_nr))     
  54. #define S3C64XX_GPI(_nr)    (S3C64XX_GPIO_I_START + (_nr))     
  55. #define S3C64XX_GPJ(_nr)    (S3C64XX_GPIO_J_START + (_nr))     
  56. #define S3C64XX_GPK(_nr)    (S3C64XX_GPIO_K_START + (_nr))     
  57. #define S3C64XX_GPL(_nr)    (S3C64XX_GPIO_L_START + (_nr))     
  58. #define S3C64XX_GPM(_nr)    (S3C64XX_GPIO_M_START + (_nr))     
  59. #define S3C64XX_GPN(_nr)    (S3C64XX_GPIO_N_START + (_nr))     
  60. #define S3C64XX_GPO(_nr)    (S3C64XX_GPIO_O_START + (_nr))     
  61. #define S3C64XX_GPP(_nr)    (S3C64XX_GPIO_P_START + (_nr))     
  62. #define S3C64XX_GPQ(_nr)    (S3C64XX_GPIO_Q_START + (_nr))     
  63. //定義了引腳号的範圍,引腳号必須小于這個數,不然就是無效的  
  64. #define S3C64XX_GPIO_END    (S3C64XX_GPQ(S3C64XX_GPIO_Q_NR) + 1)     
  65. #define S3C_GPIO_END        S3C64XX_GPIO_END    
  66. //與上面一樣,定義了引腳的總個數,引腳号不能超過這個數,我們可以利用它判斷某個引腳編号的有效性。   
  67. #define ARCH_NR_GPIOS   (S3C64XX_GPQ(S3C64XX_GPIO_Q_NR) + 1)    
  68. //由上面的分析可知,這個頭檔案對s3c64xx系列的晶片的引腳進行了統一的編号,按GPA-->GPQ的順序對給每個引腳編了個号。  
  69. #include <asm-generic/gpio.h> //這個頭檔案是包含在此檔案中的,它裡面包含了許多gpio的操作函數,而這些函數可以直接使用上述宏定義對具體的單個引腳進行操作,如下:  

[cpp]  view plain copy

  1. #ifndef _ASM_GENERIC_GPIO_H  
  2. #define _ASM_GENERIC_GPIO_H  
  3. #include <linux/types.h>  
  4. #include <linux/errno.h>  
  5. #ifdef CONFIG_GPIOLIB  
  6. #include <linux/compiler.h>  
  7. #ifndef ARCH_NR_GPIOS  
  8. #define ARCH_NR_GPIOS       256  
  9. #endif  
  10. static inline int gpio_is_valid(int number)  
  11. {  
  12.     return ((unsigned)number) < ARCH_NR_GPIOS;  
  13. }  
  14. struct seq_file;  
  15. struct module;  
  16. struct gpio_chip {  
  17.     const char      *label;  
  18.     struct device       *dev;  
  19.     struct module       *owner;  
  20.     int         (*request)(struct gpio_chip *chip,  
  21.                         unsigned offset);  
  22.     void            (*free)(struct gpio_chip *chip,  
  23.                         unsigned offset);  
  24.     int         (*direction_input)(struct gpio_chip *chip,  
  25.                         unsigned offset);  
  26.     int         (*get)(struct gpio_chip *chip,  
  27.                         unsigned offset);  
  28.     int         (*direction_output)(struct gpio_chip *chip,  
  29.                         unsigned offset, int value);  
  30.     void            (*set)(struct gpio_chip *chip,  
  31.                         unsigned offset, int value);  
  32.     int         (*to_irq)(struct gpio_chip *chip,  
  33.                         unsigned offset);  
  34.     void            (*dbg_show)(struct seq_file *s,  
  35.                         struct gpio_chip *chip);  
  36.     int         base;  
  37.     u16         ngpio;  
  38.     unsigned        can_sleep:1;  
  39.     unsigned        exported:1;  
  40. };  
  41. extern const char *gpiochip_is_requested(struct gpio_chip *chip,  
  42.             unsigned offset);  
  43. extern int __must_check gpiochip_reserve(int start, int ngpio);  
  44. extern int gpiochip_add(struct gpio_chip *chip);  
  45. extern int __must_check gpiochip_remove(struct gpio_chip *chip);  
  46. extern int gpio_request(unsigned gpio, const char *label);  
  47. //通過檢視該gpio儲存的記錄标志是否為NULL來判斷GPIO是否被占用,并為它去個*lable   
  48. //例如:if(gpio_request(S3C64XX_GPB(0), "GPB"))  
  49. extern void gpio_free(unsigned gpio);  
  50. //釋放gpio,就是把對應GPIO口的控制标志FLAG_REQUESTED清掉,成NULL,之後可以再被其他調用。  
  51. extern int gpio_direction_input(unsigned gpio);  
  52. //将gpio配置成輸入模式  
  53. extern int gpio_direction_output(unsigned gpio, int value);  
  54. //将gpio配置成輸出模式,并且将gpio置為value,  
  55. //例如:gpio_direction_output (S3C64XX_GPB(0), 1)  
  56. extern int gpio_get_value_cansleep(unsigned gpio);//???  
  57. extern void gpio_set_value_cansleep(unsigned gpio, int value);//???  
  58. extern int __gpio_get_value(unsigned gpio);  
  59. //讀取gpio的值  
  60. extern void __gpio_set_value(unsigned gpio, int value);  
  61. //設定gpio的值為value  
  62. extern int __gpio_cansleep(unsigned gpio);//???  
  63. extern int __gpio_to_irq(unsigned gpio);///???  
  64. #ifdef CONFIG_GPIO_SYSFS  
  65. extern int gpio_export(unsigned gpio, bool direction_may_change);  
  66. extern void gpio_unexport(unsigned gpio);  
  67. #endif    
  68. #else     
  69. static inline int gpio_is_valid(int number)  
  70. {  
  71.     return number >= 0;  
  72. }  
  73. static inline int gpio_cansleep(unsigned gpio)  
  74. {  
  75.     return 0;  
  76. }  
  77. static inline int gpio_get_value_cansleep(unsigned gpio)  
  78. {  
  79.     might_sleep();  
  80.     return gpio_get_value(gpio);  
  81. }  
  82. static inline void gpio_set_value_cansleep(unsigned gpio, int value)  
  83. {  
  84.     might_sleep();  
  85.     gpio_set_value(gpio, value);  
  86. }  
  87. #endif   
  88. #ifndef CONFIG_GPIO_SYSFS  
  89. static inline int gpio_export(unsigned gpio, bool direction_may_change)  
  90. {  
  91.     return -ENOSYS;  
  92. }  
  93. static inline void gpio_unexport(unsigned gpio)  
  94. {  
  95. }  
  96. #endif    
  97. #endif   

[cpp]  view plain copy

  1. 二、<plat/regs-gpio.h>頭檔案:  

[cpp]  view plain copy

  1. #ifndef __ASM_PLAT_S3C64XX_REGS_GPIO_H     
  2. #define __ASM_PLAT_S3C64XX_REGS_GPIO_H __FILE__     
  3. //這裡包含了從a-q的相關頭檔案,這些頭檔案裡分别是gpa-gpq相關的宏,  
  4. //以下隻列出<plat/gpio-bank-m.h>中的内容   
  5. #include <plat/gpio-bank-a.h>     
  6. #include <plat/gpio-bank-b.h>     
  7. #include <plat/gpio-bank-c.h>     
  8. #include <plat/gpio-bank-d.h>     
  9. #include <plat/gpio-bank-e.h>     
  10. #include <plat/gpio-bank-f.h>     
  11. #include <plat/gpio-bank-g.h>     
  12. #include <plat/gpio-bank-h.h>     
  13. #include <plat/gpio-bank-i.h>     
  14. #include <plat/gpio-bank-j.h>     
  15. #include <plat/gpio-bank-k.h>     
  16. #include <plat/gpio-bank-l.h>  
  17. #include <plat/gpio-bank-m.h>     
  18. #include <plat/gpio-bank-n.h>     
  19. #include <plat/gpio-bank-q.h>     
  20. #include <plat/gpio-bank-o.h>     
  21. #include <plat/gpio-bank-p.h>     
  22. #include <plat/gpio-bank-q.h>     
  23. #include <mach/map.h>     
  24. //由虛拟位址加偏移位址計算基位址。以GPM的基位址計算為例:  
  25. //gpm的虛拟位址是S3C64XX_VA_GPIO,定義在mach/map.h中:  
  26. //#define S3C64XX_VA_GPIO S3C_ADDR(0x00500000)  
  27. //S3C_ADDR(0x00500000)是定義在plat/map.h中的:  
  28. //#define S3C_ADDR(x) ((void __iomem __force *)S3C_ADDR_BASE+ (x))  
  29. //S3C_ADDR_BASE是全局虛拟位址,它的定義是:#define S3C_ADDR_BASE (0xF4000000)  
  30. //void __iomem __force *作用是強制轉化為位址  
  31. //綜合以上,GPM的宏S3C64XX_GPM_BASE展開的情形是:  
  32. //(0xF4000000+0x00500000)+ 0x0820 = 0xf4500820,括号裡面的是虛拟位址,後面的是  
  33. //偏移量,查S3C6410的手冊會發現這個位址剛好是GPMCON寄存器的位址!!!!!  

[cpp]  view plain copy

  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. #define S3C64XX_EXTINT_LOWLEV    (0x00)     
  60. #define S3C64XX_EXTINT_HILEV     (0x01)     
  61. #define S3C64XX_EXTINT_FALLEDGE  (0x02)     
  62. #define S3C64XX_EXTINT_RISEEDGE  (0x04)     
  63. #define S3C64XX_EXTINT_BOTHEDGE  (0x06)     
  64. #endif     

[cpp]  view plain copy

  1. 以下僅列出<plat/gpio-bank-m.h>中的内容:  

[cpp]  view plain copy

  1. #define S3C64XX_GPMCON          (S3C64XX_GPM_BASE + 0x00)     
  2. //經過上面的計算容易知道,這個宏就是GPMCON的位址  
  3. #define S3C64XX_GPMDAT          (S3C64XX_GPM_BASE + 0x04)     
  4. //GPMDAT的位址  
  5. #define S3C64XX_GPMPUD          (S3C64XX_GPM_BASE + 0x08)     
  6. //GPMPUD的位址  
  7. #define S3C64XX_GPM_CONMASK(__gpio) (0x3 << ((__gpio) * 2))     
  8. #define S3C64XX_GPM_INPUT(__gpio)   (0x0 << ((__gpio) * 2))    
  9. //輸入的配置資料宏,将GPMCON與之按位與就能将gpio位配置為輸入  
  10. #define S3C64XX_GPM_OUTPUT(__gpio)  (0x1 << ((__gpio) * 2))   
  11. //輸出的配置資料宏,将GPMCON與之按位或就能将gpio位配置為輸出   
  12. #define S3C64XX_GPM0_HOSTIF_CS      (0x02 << 0)     
  13. #define S3C64XX_GPM0_EINT23      (0x03 << 0)     
  14. #define S3C64XX_GPM0_RESERVED1      (0x04 << 0)     
  15. #define S3C64XX_GPM0_DATA_CF10      (0x05 << 0)     
  16. #define S3C64XX_GPM0_CE_CF0      (0x06 << 0)     
  17. #define S3C64XX_GPM0_RESERVED2      (0x07 << 0)     
  18. #define S3C64XX_GPM1_HOSTIF_CS_M      (0x02 << 0)     
  19. #define S3C64XX_GPM1_EINT24      (0x03 << 0)     
  20. #define S3C64XX_GPM1_RESERVED1      (0x04 << 0)     
  21. #define S3C64XX_GPM1_DATA_CF11      (0x05 << 0)     
  22. #define S3C64XX_GPM1_CE_CF1      (0x06 << 0)     
  23. #define S3C64XX_GPM1_RESERVED2      (0x07 << 0)     
  24. #define S3C64XX_GPM2_HOSTIF_IF_CS_S      (0x02 << 0)     
  25. #define S3C64XX_GPM2_EINT25      (0x03 << 0)     
  26. #define S3C64XX_GPM2_HOSTIF_MDP_VSYNC      (0x04 << 0)     
  27. #define S3C64XX_GPM2_DATA_CF12      (0x05 << 0)     
  28. #define S3C64XX_GPM2_IORD_CF      (0x06 << 0)     
  29. #define S3C64XX_GPM2_RESERVED2      (0x07 << 0)     
  30. #define S3C64XX_GPM3_HOSTIF_WE      (0x02 << 0)     
  31. #define S3C64XX_GPM3_EINT26      (0x03 << 0)     
  32. #define S3C64XX_GPM3_RESERVED1      (0x04 << 0)     
  33. #define S3C64XX_GPM3_DATA_CF13      (0x05 << 0)     
  34. #define S3C64XX_GPM3_IOWR_CF      (0x06 << 0)     
  35. #define S3C64XX_GPM3_RESERVED2      (0x07 << 0)     
  36. #define S3C64XX_GPM4_HOSTIF_OE      (0x02 << 0)     
  37. #define S3C64XX_GPM4_EINT27      (0x03 << 0)     
  38. #define S3C64XX_GPM4_RESERVED1      (0x04 << 0)     
  39. #define S3C64XX_GPM4_DATA_CF14      (0x05 << 0)     
  40. #define S3C64XX_GPM4_IORDY_CF      (0x06 << 0)     
  41. #define S3C64XX_GPM4_RESERVED2      (0x07 << 0)     
  42. #define S3C64XX_GPM5_HOSTIF_INTR      (0x02 << 0)     
  43. #define S3C64XX_GPM5_CF_DATA_DIR      (0x03 << 0)     
  44. #define S3C64XX_GPM5_RESERVED1      (0x04 << 0)     
  45. #define S3C64XX_GPM5_DATA_CF15      (0x05 << 0)     
  46. #define S3C64XX_GPM5_RESERVED2      (0x06 << 0)     
  47. #define S3C64XX_GPM5_RESERVED3      (0x07 << 0)  

[cpp]  view plain copy

[cpp]  view plain copy

  1. 三、<plat/gpio-cfg.h>頭檔案:  
  2. <pre class="cpp" name="code">    
  3. #ifndef __PLAT_GPIO_CFG_H     
  4. #define __PLAT_GPIO_CFG_H __FILE__     
  5. typedef unsigned int __bitwise__ s3c_gpio_pull_t;    
  6. struct s3c_gpio_chip;    
  7. struct s3c_gpio_cfg {    
  8.     unsigned int    cfg_eint;    
  9.     s3c_gpio_pull_t (*get_pull)(struct s3c_gpio_chip *chip, unsigned offs);    
  10.     int     (*set_pull)(struct s3c_gpio_chip *chip, unsigned offs,    
  11.                     s3c_gpio_pull_t pull);    
  12.     unsigned (*get_config)(struct s3c_gpio_chip *chip, unsigned offs);    
  13.     int  (*set_config)(struct s3c_gpio_chip *chip, unsigned offs,    
  14.                    unsigned config);    
  15. };    
  16. #define S3C_GPIO_SPECIAL_MARK   (0xfffffff0)     
  17. #define S3C_GPIO_SPECIAL(x) (S3C_GPIO_SPECIAL_MARK | (x))     
  18. #define S3C_GPIO_INPUT  (S3C_GPIO_SPECIAL(0))     
  19. #define S3C_GPIO_OUTPUT (S3C_GPIO_SPECIAL(1))     
  20. #define S3C_GPIO_SFN(x) (S3C_GPIO_SPECIAL(x))     
  21. #define s3c_gpio_is_cfg_special(_cfg) \     
  22.     (((_cfg) & S3C_GPIO_SPECIAL_MARK) == S3C_GPIO_SPECIAL_MARK)    
  23. extern int s3c_gpio_cfgpin(unsigned int pin, unsigned int to);    
  24. //此宏函數将pin引腳配置成“to”功能,to可以取 中定義的值    
  25. #define S3C_GPIO_PULL_NONE  ((__force s3c_gpio_pull_t)0x00)     
  26. #define S3C_GPIO_PULL_DOWN  ((__force s3c_gpio_pull_t)0x01)     
  27. #define S3C_GPIO_PULL_UP    ((__force s3c_gpio_pull_t)0x02)     
  28. extern int s3c_gpio_setpull(unsigned int pin, s3c_gpio_pull_t pull);  
  29. //将pin引腳的上拉電阻設定成“pull”狀态,pull可以去上面宏定義的那些值  
  30. extern s3c_gpio_pull_t s3c_gpio_getpull(unsigned int pin);  
  31. //讀取pin引腳上拉電阻的狀态    
  32. #endif