io.h 3.7 KB

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