ipaq-micro.h 3.7 KB

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