ipaq-micro.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Header file for the compaq Micro MFD
  3. */
  4. #ifndef _MFD_IPAQ_MICRO_H_
  5. #define _MFD_IPAQ_MICRO_H_
  6. #include <linux/spinlock.h>
  7. #include <linux/completion.h>
  8. #include <linux/list.h>
  9. #define TX_BUF_SIZE 32
  10. #define RX_BUF_SIZE 16
  11. #define CHAR_SOF 0x02
  12. /*
  13. * These are the different messages that can be sent to the microcontroller
  14. * to control various aspects.
  15. */
  16. #define MSG_VERSION 0x0
  17. #define MSG_KEYBOARD 0x2
  18. #define MSG_TOUCHSCREEN 0x3
  19. #define MSG_EEPROM_READ 0x4
  20. #define MSG_EEPROM_WRITE 0x5
  21. #define MSG_THERMAL_SENSOR 0x6
  22. #define MSG_NOTIFY_LED 0x8
  23. #define MSG_BATTERY 0x9
  24. #define MSG_SPI_READ 0xb
  25. #define MSG_SPI_WRITE 0xc
  26. #define MSG_BACKLIGHT 0xd /* H3600 only */
  27. #define MSG_CODEC_CTRL 0xe /* H3100 only */
  28. #define MSG_DISPLAY_CTRL 0xf /* H3100 only */
  29. /* state of receiver parser */
  30. enum rx_state {
  31. STATE_SOF = 0, /* Next byte should be start of frame */
  32. STATE_ID, /* Next byte is ID & message length */
  33. STATE_DATA, /* Next byte is a data byte */
  34. STATE_CHKSUM /* Next byte should be checksum */
  35. };
  36. /**
  37. * struct ipaq_micro_txdev - TX state
  38. * @len: length of message in TX buffer
  39. * @index: current index into TX buffer
  40. * @buf: TX buffer
  41. */
  42. struct ipaq_micro_txdev {
  43. u8 len;
  44. u8 index;
  45. u8 buf[TX_BUF_SIZE];
  46. };
  47. /**
  48. * struct ipaq_micro_rxdev - RX state
  49. * @state: context of RX state machine
  50. * @chksum: calculated checksum
  51. * @id: message ID from packet
  52. * @len: RX buffer length
  53. * @index: RX buffer index
  54. * @buf: RX buffer
  55. */
  56. struct ipaq_micro_rxdev {
  57. enum rx_state state;
  58. unsigned char chksum;
  59. u8 id;
  60. unsigned int len;
  61. unsigned int index;
  62. u8 buf[RX_BUF_SIZE];
  63. };
  64. /**
  65. * struct ipaq_micro_msg - message to the iPAQ microcontroller
  66. * @id: 4-bit ID of the message
  67. * @tx_len: length of TX data
  68. * @tx_data: TX data to send
  69. * @rx_len: length of receieved RX data
  70. * @rx_data: RX data to recieve
  71. * @ack: a completion that will be completed when RX is complete
  72. * @node: list node if message gets queued
  73. */
  74. struct ipaq_micro_msg {
  75. u8 id;
  76. u8 tx_len;
  77. u8 tx_data[TX_BUF_SIZE];
  78. u8 rx_len;
  79. u8 rx_data[RX_BUF_SIZE];
  80. struct completion ack;
  81. struct list_head node;
  82. };
  83. /**
  84. * struct ipaq_micro - iPAQ microcontroller state
  85. * @dev: corresponding platform device
  86. * @base: virtual memory base for underlying serial device
  87. * @sdlc: virtual memory base for Synchronous Data Link Controller
  88. * @version: version string
  89. * @tx: TX state
  90. * @rx: RX state
  91. * @lock: lock for this state container
  92. * @msg: current message
  93. * @queue: message queue
  94. * @key: callback for asynchronous key events
  95. * @key_data: data to pass along with key events
  96. * @ts: callback for asynchronous touchscreen events
  97. * @ts_data: data to pass along with key events
  98. */
  99. struct ipaq_micro {
  100. struct device *dev;
  101. void __iomem *base;
  102. void __iomem *sdlc;
  103. char version[5];
  104. struct ipaq_micro_txdev tx; /* transmit ISR state */
  105. struct ipaq_micro_rxdev rx; /* receive ISR state */
  106. spinlock_t lock;
  107. struct ipaq_micro_msg *msg;
  108. struct list_head queue;
  109. void (*key) (void *data, int len, unsigned char *rxdata);
  110. void *key_data;
  111. void (*ts) (void *data, int len, unsigned char *rxdata);
  112. void *ts_data;
  113. };
  114. extern int
  115. ipaq_micro_tx_msg(struct ipaq_micro *micro, struct ipaq_micro_msg *msg);
  116. static inline int
  117. ipaq_micro_tx_msg_sync(struct ipaq_micro *micro,
  118. struct ipaq_micro_msg *msg)
  119. {
  120. int ret;
  121. init_completion(&msg->ack);
  122. ret = ipaq_micro_tx_msg(micro, msg);
  123. wait_for_completion(&msg->ack);
  124. return ret;
  125. }
  126. static inline int
  127. ipaq_micro_tx_msg_async(struct ipaq_micro *micro,
  128. struct ipaq_micro_msg *msg)
  129. {
  130. init_completion(&msg->ack);
  131. return ipaq_micro_tx_msg(micro, msg);
  132. }
  133. #endif /* _MFD_IPAQ_MICRO_H_ */