io.h 2.5 KB

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