io.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef _ASM_ARCH_CRIS_IO_H
  2. #define _ASM_ARCH_CRIS_IO_H
  3. #include <asm/arch/hwregs/reg_map.h>
  4. #include <asm/arch/hwregs/reg_rdwr.h>
  5. #include <asm/arch/hwregs/gio_defs.h>
  6. enum crisv32_io_dir
  7. {
  8. crisv32_io_dir_in = 0,
  9. crisv32_io_dir_out = 1
  10. };
  11. struct crisv32_ioport
  12. {
  13. unsigned long* oe;
  14. unsigned long* data;
  15. unsigned long* data_in;
  16. unsigned int pin_count;
  17. };
  18. struct crisv32_iopin
  19. {
  20. struct crisv32_ioport* port;
  21. int bit;
  22. };
  23. extern struct crisv32_ioport crisv32_ioports[];
  24. extern struct crisv32_iopin crisv32_led1_green;
  25. extern struct crisv32_iopin crisv32_led1_red;
  26. extern struct crisv32_iopin crisv32_led2_green;
  27. extern struct crisv32_iopin crisv32_led2_red;
  28. extern struct crisv32_iopin crisv32_led3_green;
  29. extern struct crisv32_iopin crisv32_led3_red;
  30. static inline void crisv32_io_set(struct crisv32_iopin* iopin,
  31. int val)
  32. {
  33. if (val)
  34. *iopin->port->data |= iopin->bit;
  35. else
  36. *iopin->port->data &= ~iopin->bit;
  37. }
  38. static inline void crisv32_io_set_dir(struct crisv32_iopin* iopin,
  39. enum crisv32_io_dir dir)
  40. {
  41. if (dir == crisv32_io_dir_in)
  42. *iopin->port->oe &= ~iopin->bit;
  43. else
  44. *iopin->port->oe |= iopin->bit;
  45. }
  46. static inline int crisv32_io_rd(struct crisv32_iopin* iopin)
  47. {
  48. return ((*iopin->port->data_in & iopin->bit) ? 1 : 0);
  49. }
  50. int crisv32_io_get(struct crisv32_iopin* iopin,
  51. unsigned int port, unsigned int pin);
  52. int crisv32_io_get_name(struct crisv32_iopin* iopin,
  53. char* name);
  54. #define LED_OFF 0x00
  55. #define LED_GREEN 0x01
  56. #define LED_RED 0x02
  57. #define LED_ORANGE (LED_GREEN | LED_RED)
  58. #define LED_NETWORK_SET(x) \
  59. do { \
  60. LED_NETWORK_SET_G((x) & LED_GREEN); \
  61. LED_NETWORK_SET_R((x) & LED_RED); \
  62. } while (0)
  63. #define LED_ACTIVE_SET(x) \
  64. do { \
  65. LED_ACTIVE_SET_G((x) & LED_GREEN); \
  66. LED_ACTIVE_SET_R((x) & LED_RED); \
  67. } while (0)
  68. #define LED_NETWORK_SET_G(x) \
  69. crisv32_io_set(&crisv32_led1_green, !(x));
  70. #define LED_NETWORK_SET_R(x) \
  71. crisv32_io_set(&crisv32_led1_red, !(x));
  72. #define LED_ACTIVE_SET_G(x) \
  73. crisv32_io_set(&crisv32_led2_green, !(x));
  74. #define LED_ACTIVE_SET_R(x) \
  75. crisv32_io_set(&crisv32_led2_red, !(x));
  76. #define LED_DISK_WRITE(x) \
  77. do{\
  78. crisv32_io_set(&crisv32_led3_green, !(x)); \
  79. crisv32_io_set(&crisv32_led3_red, !(x)); \
  80. }while(0)
  81. #define LED_DISK_READ(x) \
  82. crisv32_io_set(&crisv32_led3_green, !(x));
  83. #endif