scx200_gpio.h 2.3 KB

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