Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Header file for the compaq Micro MFD
0004  */
0005 
0006 #ifndef _MFD_IPAQ_MICRO_H_
0007 #define _MFD_IPAQ_MICRO_H_
0008 
0009 #include <linux/spinlock.h>
0010 #include <linux/completion.h>
0011 #include <linux/list.h>
0012 
0013 #define TX_BUF_SIZE 32
0014 #define RX_BUF_SIZE 16
0015 #define CHAR_SOF    0x02
0016 
0017 /*
0018  * These are the different messages that can be sent to the microcontroller
0019  * to control various aspects.
0020  */
0021 #define MSG_VERSION     0x0
0022 #define MSG_KEYBOARD        0x2
0023 #define MSG_TOUCHSCREEN     0x3
0024 #define MSG_EEPROM_READ     0x4
0025 #define MSG_EEPROM_WRITE    0x5
0026 #define MSG_THERMAL_SENSOR  0x6
0027 #define MSG_NOTIFY_LED      0x8
0028 #define MSG_BATTERY     0x9
0029 #define MSG_SPI_READ        0xb
0030 #define MSG_SPI_WRITE       0xc
0031 #define MSG_BACKLIGHT       0xd /* H3600 only */
0032 #define MSG_CODEC_CTRL      0xe /* H3100 only */
0033 #define MSG_DISPLAY_CTRL    0xf /* H3100 only */
0034 
0035 /* state of receiver parser */
0036 enum rx_state {
0037     STATE_SOF = 0,     /* Next byte should be start of frame */
0038     STATE_ID,          /* Next byte is ID & message length   */
0039     STATE_DATA,        /* Next byte is a data byte           */
0040     STATE_CHKSUM       /* Next byte should be checksum       */
0041 };
0042 
0043 /**
0044  * struct ipaq_micro_txdev - TX state
0045  * @len: length of message in TX buffer
0046  * @index: current index into TX buffer
0047  * @buf: TX buffer
0048  */
0049 struct ipaq_micro_txdev {
0050     u8 len;
0051     u8 index;
0052     u8 buf[TX_BUF_SIZE];
0053 };
0054 
0055 /**
0056  * struct ipaq_micro_rxdev - RX state
0057  * @state: context of RX state machine
0058  * @chksum: calculated checksum
0059  * @id: message ID from packet
0060  * @len: RX buffer length
0061  * @index: RX buffer index
0062  * @buf: RX buffer
0063  */
0064 struct ipaq_micro_rxdev {
0065     enum rx_state state;
0066     unsigned char chksum;
0067     u8            id;
0068     unsigned int  len;
0069     unsigned int  index;
0070     u8            buf[RX_BUF_SIZE];
0071 };
0072 
0073 /**
0074  * struct ipaq_micro_msg - message to the iPAQ microcontroller
0075  * @id: 4-bit ID of the message
0076  * @tx_len: length of TX data
0077  * @tx_data: TX data to send
0078  * @rx_len: length of received RX data
0079  * @rx_data: RX data to receive
0080  * @ack: a completion that will be completed when RX is complete
0081  * @node: list node if message gets queued
0082  */
0083 struct ipaq_micro_msg {
0084     u8 id;
0085     u8 tx_len;
0086     u8 tx_data[TX_BUF_SIZE];
0087     u8 rx_len;
0088     u8 rx_data[RX_BUF_SIZE];
0089     struct completion ack;
0090     struct list_head node;
0091 };
0092 
0093 /**
0094  * struct ipaq_micro - iPAQ microcontroller state
0095  * @dev: corresponding platform device
0096  * @base: virtual memory base for underlying serial device
0097  * @sdlc: virtual memory base for Synchronous Data Link Controller
0098  * @version: version string
0099  * @tx: TX state
0100  * @rx: RX state
0101  * @lock: lock for this state container
0102  * @msg: current message
0103  * @queue: message queue
0104  * @key: callback for asynchronous key events
0105  * @key_data: data to pass along with key events
0106  * @ts: callback for asynchronous touchscreen events
0107  * @ts_data: data to pass along with key events
0108  */
0109 struct ipaq_micro {
0110     struct device *dev;
0111     void __iomem *base;
0112     void __iomem *sdlc;
0113     char version[5];
0114     struct ipaq_micro_txdev tx; /* transmit ISR state */
0115     struct ipaq_micro_rxdev rx; /* receive ISR state */
0116     spinlock_t lock;
0117     struct ipaq_micro_msg *msg;
0118     struct list_head queue;
0119     void (*key) (void *data, int len, unsigned char *rxdata);
0120     void *key_data;
0121     void (*ts) (void *data, int len, unsigned char *rxdata);
0122     void *ts_data;
0123 };
0124 
0125 extern int
0126 ipaq_micro_tx_msg(struct ipaq_micro *micro, struct ipaq_micro_msg *msg);
0127 
0128 static inline int
0129 ipaq_micro_tx_msg_sync(struct ipaq_micro *micro,
0130                struct ipaq_micro_msg *msg)
0131 {
0132     int ret;
0133 
0134     init_completion(&msg->ack);
0135     ret = ipaq_micro_tx_msg(micro, msg);
0136     wait_for_completion(&msg->ack);
0137 
0138     return ret;
0139 }
0140 
0141 static inline int
0142 ipaq_micro_tx_msg_async(struct ipaq_micro *micro,
0143             struct ipaq_micro_msg *msg)
0144 {
0145     init_completion(&msg->ack);
0146     return ipaq_micro_tx_msg(micro, msg);
0147 }
0148 
0149 #endif /* _MFD_IPAQ_MICRO_H_ */