abcio.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #ifndef ABCIO_H
  2. #define ABCIO_H
  3. #include "common.h"
  4. #include "config.h"
  5. #define DEVSEL_NONE 64 /* No device at all selected */
  6. struct abc_dev;
  7. /* Called from an interrupt handler, so hot */
  8. #define ABC_CALLBACK_DECL(func) \
  9. void func(struct abc_dev *dev __unused, \
  10. uint8_t data __unused, \
  11. uint8_t addr __unused)
  12. #define ABC_CALLBACK(func) \
  13. __hot ABC_CALLBACK_DECL(func)
  14. typedef ABC_CALLBACK_DECL((*abc_callback_t));
  15. struct abc_dev {
  16. uint8_t *out_buf;
  17. size_t out_cnt;
  18. const uint8_t *inp_buf;
  19. size_t inp_cnt;
  20. uint16_t callback_mask;
  21. uint16_t event_mask; /* Can be a superset of callback_mask */
  22. uint8_t status_first_out_mask;
  23. uint8_t status_first_inp_mask;
  24. uint8_t out_data[6]; /* [1] is devsel, all 8 bits */
  25. union {
  26. struct {
  27. uint8_t inp_data[2];
  28. uint8_t inp_en;
  29. uint8_t inp_data_def; /* inp_data[0] when no queue active */
  30. };
  31. uint32_t inp_data_w;
  32. };
  33. abc_callback_t callback_out[6];
  34. abc_callback_t callback_inp[2];
  35. abc_callback_t callback_rst;
  36. unsigned int devsel;
  37. const char *name;
  38. };
  39. extern struct abc_dev *_abc_selected_dev;
  40. static inline struct abc_dev *abc_selected_dev(void)
  41. {
  42. return _abc_selected_dev;
  43. }
  44. void abc_setup_out_queue(struct abc_dev *dev, void *buf, size_t len,
  45. uint8_t status);
  46. void abc_setup_inp_queue(struct abc_dev *dev, const void *buf, size_t len,
  47. uint8_t status);
  48. void abc_set_inp_default(struct abc_dev *dev, uint8_t val);
  49. void abc_set_inp_status(struct abc_dev *dev, uint8_t val);
  50. /*
  51. * The _ versions can be used from interrupt handlers or when ABC_IRQ
  52. * is known to be masked already; for the _inp_data() functions this ALSO
  53. * requires that dev->inp_cnt is known to be zero (no currently configured
  54. * queue.)
  55. *
  56. * The __ versions can be used when it is *also* known that the device
  57. * in question is already selected (e.g. inside a callback.)
  58. */
  59. static inline void _abc_set_inp_data(struct abc_dev *dev, uint8_t val)
  60. {
  61. dev->inp_data[0] = dev->inp_data_def = val;
  62. if (dev == abc_selected_dev())
  63. ABC_INP0_DATA = val;
  64. }
  65. static inline void _abc_set_inp_status(struct abc_dev *dev, uint8_t val)
  66. {
  67. dev->inp_data[1] = val;
  68. if (dev == abc_selected_dev())
  69. ABC_INP1_DATA = val;
  70. }
  71. static inline void __abc_set_inp_data(struct abc_dev *dev, uint8_t val)
  72. {
  73. ABC_INP0_DATA = dev->inp_data[0] = dev->inp_data_def = val;
  74. }
  75. static inline void __abc_set_inp_status(struct abc_dev *dev, uint8_t val)
  76. {
  77. ABC_INP1_DATA = dev->inp_data[1] = val;
  78. }
  79. static inline bool is_abc800(void)
  80. {
  81. unsigned long int host = getvar_uint(config_abc_hosttype);
  82. if (host)
  83. return host >= ABC_ABC800CM;
  84. else
  85. return !!(ABC_STATUS & ABC_STATUS_800);
  86. }
  87. void abc_register(struct abc_dev *dev, unsigned int devsel);
  88. void abc_init(void);
  89. void abcdisk_init(void);
  90. void abcdisk_config(void);
  91. void abcdisk_io_poll(void);
  92. void abcdisk_shutdown(void);
  93. void rtc_abc_init(void);
  94. void rtc_abc_config(void);
  95. void rtc_abc_io_poll(void);
  96. void pun80_init(void);
  97. void pun80_config(void);
  98. void abc_init_memmap(void);
  99. #endif /* ABCIO_H */