io.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #ifndef _ASM_ARCH_CRIS_IO_H
  2. #define _ASM_ARCH_CRIS_IO_H
  3. #include <linux/spinlock.h>
  4. #include <hwregs/reg_map.h>
  5. #include <hwregs/reg_rdwr.h>
  6. #include <hwregs/gio_defs.h>
  7. enum crisv32_io_dir
  8. {
  9. crisv32_io_dir_in = 0,
  10. crisv32_io_dir_out = 1
  11. };
  12. struct crisv32_ioport
  13. {
  14. volatile unsigned long *oe;
  15. volatile unsigned long *data;
  16. volatile unsigned long *data_in;
  17. unsigned int pin_count;
  18. spinlock_t lock;
  19. };
  20. struct crisv32_iopin
  21. {
  22. struct crisv32_ioport* port;
  23. int bit;
  24. };
  25. extern struct crisv32_ioport crisv32_ioports[];
  26. extern struct crisv32_iopin crisv32_led1_green;
  27. extern struct crisv32_iopin crisv32_led1_red;
  28. extern struct crisv32_iopin crisv32_led2_green;
  29. extern struct crisv32_iopin crisv32_led2_red;
  30. extern struct crisv32_iopin crisv32_led3_green;
  31. extern struct crisv32_iopin crisv32_led3_red;
  32. extern struct crisv32_iopin crisv32_led_net0_green;
  33. extern struct crisv32_iopin crisv32_led_net0_red;
  34. extern struct crisv32_iopin crisv32_led_net1_green;
  35. extern struct crisv32_iopin crisv32_led_net1_red;
  36. static inline void crisv32_io_set(struct crisv32_iopin* iopin,
  37. int val)
  38. {
  39. long flags;
  40. spin_lock_irqsave(&iopin->port->lock, flags);
  41. if (val)
  42. *iopin->port->data |= iopin->bit;
  43. else
  44. *iopin->port->data &= ~iopin->bit;
  45. spin_unlock_irqrestore(&iopin->port->lock, flags);
  46. }
  47. static inline void crisv32_io_set_dir(struct crisv32_iopin* iopin,
  48. enum crisv32_io_dir dir)
  49. {
  50. long flags;
  51. spin_lock_irqsave(&iopin->port->lock, flags);
  52. if (dir == crisv32_io_dir_in)
  53. *iopin->port->oe &= ~iopin->bit;
  54. else
  55. *iopin->port->oe |= iopin->bit;
  56. spin_unlock_irqrestore(&iopin->port->lock, flags);
  57. }
  58. static inline int crisv32_io_rd(struct crisv32_iopin* iopin)
  59. {
  60. return ((*iopin->port->data_in & iopin->bit) ? 1 : 0);
  61. }
  62. int crisv32_io_get(struct crisv32_iopin* iopin,
  63. unsigned int port, unsigned int pin);
  64. int crisv32_io_get_name(struct crisv32_iopin* iopin,
  65. const char *name);
  66. #define LED_OFF 0x00
  67. #define LED_GREEN 0x01
  68. #define LED_RED 0x02
  69. #define LED_ORANGE (LED_GREEN | LED_RED)
  70. #if (defined(CONFIG_ETRAX_NBR_LED_GRP_ONE) || defined(CONFIG_ETRAX_NBR_LED_GRP_TWO))
  71. #define LED_NETWORK_GRP0_SET(x) \
  72. do { \
  73. LED_NETWORK_GRP0_SET_G((x) & LED_GREEN); \
  74. LED_NETWORK_GRP0_SET_R((x) & LED_RED); \
  75. } while (0)
  76. #else
  77. #define LED_NETWORK_GRP0_SET(x) while (0) {}
  78. #endif
  79. #define LED_NETWORK_GRP0_SET_G(x) \
  80. crisv32_io_set(&crisv32_led_net0_green, !(x));
  81. #define LED_NETWORK_GRP0_SET_R(x) \
  82. crisv32_io_set(&crisv32_led_net0_red, !(x));
  83. #if defined(CONFIG_ETRAX_NBR_LED_GRP_TWO)
  84. #define LED_NETWORK_GRP1_SET(x) \
  85. do { \
  86. LED_NETWORK_GRP1_SET_G((x) & LED_GREEN); \
  87. LED_NETWORK_GRP1_SET_R((x) & LED_RED); \
  88. } while (0)
  89. #else
  90. #define LED_NETWORK_GRP1_SET(x) while (0) {}
  91. #endif
  92. #define LED_NETWORK_GRP1_SET_G(x) \
  93. crisv32_io_set(&crisv32_led_net1_green, !(x));
  94. #define LED_NETWORK_GRP1_SET_R(x) \
  95. crisv32_io_set(&crisv32_led_net1_red, !(x));
  96. #define LED_ACTIVE_SET(x) \
  97. do { \
  98. LED_ACTIVE_SET_G((x) & LED_GREEN); \
  99. LED_ACTIVE_SET_R((x) & LED_RED); \
  100. } while (0)
  101. #define LED_ACTIVE_SET_G(x) \
  102. crisv32_io_set(&crisv32_led2_green, !(x));
  103. #define LED_ACTIVE_SET_R(x) \
  104. crisv32_io_set(&crisv32_led2_red, !(x));
  105. #define LED_DISK_WRITE(x) \
  106. do{\
  107. crisv32_io_set(&crisv32_led3_green, !(x)); \
  108. crisv32_io_set(&crisv32_led3_red, !(x)); \
  109. }while(0)
  110. #define LED_DISK_READ(x) \
  111. crisv32_io_set(&crisv32_led3_green, !(x));
  112. #endif