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