io.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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, int val)
  37. {
  38. unsigned long flags;
  39. spin_lock_irqsave(&iopin->port->lock, flags);
  40. if (iopin->port->data) {
  41. if (val)
  42. *iopin->port->data |= iopin->bit;
  43. else
  44. *iopin->port->data &= ~iopin->bit;
  45. }
  46. spin_unlock_irqrestore(&iopin->port->lock, flags);
  47. }
  48. static inline void crisv32_io_set_dir(struct crisv32_iopin* iopin,
  49. enum crisv32_io_dir dir)
  50. {
  51. unsigned long flags;
  52. spin_lock_irqsave(&iopin->port->lock, flags);
  53. if (iopin->port->oe) {
  54. if (dir == crisv32_io_dir_in)
  55. *iopin->port->oe &= ~iopin->bit;
  56. else
  57. *iopin->port->oe |= iopin->bit;
  58. }
  59. spin_unlock_irqrestore(&iopin->port->lock, flags);
  60. }
  61. static inline int crisv32_io_rd(struct crisv32_iopin* iopin)
  62. {
  63. return ((*iopin->port->data_in & iopin->bit) ? 1 : 0);
  64. }
  65. int crisv32_io_get(struct crisv32_iopin* iopin,
  66. unsigned int port, unsigned int pin);
  67. int crisv32_io_get_name(struct crisv32_iopin* iopin,
  68. const char *name);
  69. #define CRIS_LED_OFF 0x00
  70. #define CRIS_LED_GREEN 0x01
  71. #define CRIS_LED_RED 0x02
  72. #define CRIS_LED_ORANGE (CRIS_LED_GREEN | CRIS_LED_RED)
  73. #if (defined(CONFIG_ETRAX_NBR_LED_GRP_ONE) || defined(CONFIG_ETRAX_NBR_LED_GRP_TWO))
  74. #define CRIS_LED_NETWORK_GRP0_SET(x) \
  75. do { \
  76. CRIS_LED_NETWORK_GRP0_SET_G((x) & CRIS_LED_GREEN); \
  77. CRIS_LED_NETWORK_GRP0_SET_R((x) & CRIS_LED_RED); \
  78. } while (0)
  79. #else
  80. #define CRIS_LED_NETWORK_GRP0_SET(x) while (0) {}
  81. #endif
  82. #define CRIS_LED_NETWORK_GRP0_SET_G(x) \
  83. crisv32_io_set(&crisv32_led_net0_green, !(x));
  84. #define CRIS_LED_NETWORK_GRP0_SET_R(x) \
  85. crisv32_io_set(&crisv32_led_net0_red, !(x));
  86. #if defined(CONFIG_ETRAX_NBR_LED_GRP_TWO)
  87. #define CRIS_LED_NETWORK_GRP1_SET(x) \
  88. do { \
  89. CRIS_LED_NETWORK_GRP1_SET_G((x) & CRIS_LED_GREEN); \
  90. CRIS_LED_NETWORK_GRP1_SET_R((x) & CRIS_LED_RED); \
  91. } while (0)
  92. #else
  93. #define CRIS_LED_NETWORK_GRP1_SET(x) while (0) {}
  94. #endif
  95. #define CRIS_LED_NETWORK_GRP1_SET_G(x) \
  96. crisv32_io_set(&crisv32_led_net1_green, !(x));
  97. #define CRIS_LED_NETWORK_GRP1_SET_R(x) \
  98. crisv32_io_set(&crisv32_led_net1_red, !(x));
  99. #define CRIS_LED_ACTIVE_SET(x) \
  100. do { \
  101. CRIS_LED_ACTIVE_SET_G((x) & CRIS_LED_GREEN); \
  102. CRIS_LED_ACTIVE_SET_R((x) & CRIS_LED_RED); \
  103. } while (0)
  104. #define CRIS_LED_ACTIVE_SET_G(x) \
  105. crisv32_io_set(&crisv32_led2_green, !(x));
  106. #define CRIS_LED_ACTIVE_SET_R(x) \
  107. crisv32_io_set(&crisv32_led2_red, !(x));
  108. #define CRIS_LED_DISK_WRITE(x) \
  109. do{\
  110. crisv32_io_set(&crisv32_led3_green, !(x)); \
  111. crisv32_io_set(&crisv32_led3_red, !(x)); \
  112. }while(0)
  113. #define CRIS_LED_DISK_READ(x) \
  114. crisv32_io_set(&crisv32_led3_green, !(x));
  115. #endif