linux/include/linux/scx200_gpio.h
<<
>>
Prefs
   1u32 scx200_gpio_configure(unsigned index, u32 set, u32 clear);
   2
   3extern unsigned scx200_gpio_base;
   4extern unsigned long scx200_gpio_shadow[2];
   5extern struct nsc_gpio_ops scx200_gpio_ops;
   6
   7#define scx200_gpio_present() (scx200_gpio_base!=0)
   8
   9/* Definitions to make sure I do the same thing in all functions */
  10#define __SCx200_GPIO_BANK unsigned bank = index>>5
  11#define __SCx200_GPIO_IOADDR unsigned short ioaddr = scx200_gpio_base+0x10*bank
  12#define __SCx200_GPIO_SHADOW unsigned long *shadow = scx200_gpio_shadow+bank
  13#define __SCx200_GPIO_INDEX index &= 31
  14
  15#define __SCx200_GPIO_OUT __asm__ __volatile__("outsl":"=mS" (shadow):"d" (ioaddr), "0" (shadow))
  16
  17/* returns the value of the GPIO pin */
  18
  19static inline int scx200_gpio_get(unsigned index) {
  20        __SCx200_GPIO_BANK;
  21        __SCx200_GPIO_IOADDR + 0x04;
  22        __SCx200_GPIO_INDEX;
  23                
  24        return (inl(ioaddr) & (1<<index)) ? 1 : 0;
  25}
  26
  27/* return the value driven on the GPIO signal (the value that will be
  28   driven if the GPIO is configured as an output, it might not be the
  29   state of the GPIO right now if the GPIO is configured as an input) */
  30
  31static inline int scx200_gpio_current(unsigned index) {
  32        __SCx200_GPIO_BANK;
  33        __SCx200_GPIO_INDEX;
  34                
  35        return (scx200_gpio_shadow[bank] & (1<<index)) ? 1 : 0;
  36}
  37
  38/* drive the GPIO signal high */
  39
  40static inline void scx200_gpio_set_high(unsigned index) {
  41        __SCx200_GPIO_BANK;
  42        __SCx200_GPIO_IOADDR;
  43        __SCx200_GPIO_SHADOW;
  44        __SCx200_GPIO_INDEX;
  45        set_bit(index, shadow); /* __set_bit()? */
  46        __SCx200_GPIO_OUT;
  47}
  48
  49/* drive the GPIO signal low */
  50
  51static inline void scx200_gpio_set_low(unsigned index) {
  52        __SCx200_GPIO_BANK;
  53        __SCx200_GPIO_IOADDR;
  54        __SCx200_GPIO_SHADOW;
  55        __SCx200_GPIO_INDEX;
  56        clear_bit(index, shadow); /* __clear_bit()? */
  57        __SCx200_GPIO_OUT;
  58}
  59
  60/* drive the GPIO signal to state */
  61
  62static inline void scx200_gpio_set(unsigned index, int state) {
  63        __SCx200_GPIO_BANK;
  64        __SCx200_GPIO_IOADDR;
  65        __SCx200_GPIO_SHADOW;
  66        __SCx200_GPIO_INDEX;
  67        if (state)
  68                set_bit(index, shadow);
  69        else
  70                clear_bit(index, shadow);
  71        __SCx200_GPIO_OUT;
  72}
  73
  74/* toggle the GPIO signal */
  75static inline void scx200_gpio_change(unsigned index) {
  76        __SCx200_GPIO_BANK;
  77        __SCx200_GPIO_IOADDR;
  78        __SCx200_GPIO_SHADOW;
  79        __SCx200_GPIO_INDEX;
  80        change_bit(index, shadow);
  81        __SCx200_GPIO_OUT;
  82}
  83
  84#undef __SCx200_GPIO_BANK
  85#undef __SCx200_GPIO_IOADDR
  86#undef __SCx200_GPIO_SHADOW
  87#undef __SCx200_GPIO_INDEX
  88#undef __SCx200_GPIO_OUT
  89