diff options
| author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
|---|---|---|
| committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
| commit | fcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch) | |
| tree | a57612d1888735a2ec7972891b68c1ac5ec8faea /include/linux/i2c-slave.h | |
| parent | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff) | |
Diffstat (limited to 'include/linux/i2c-slave.h')
| -rw-r--r-- | include/linux/i2c-slave.h | 259 |
1 files changed, 259 insertions, 0 deletions
diff --git a/include/linux/i2c-slave.h b/include/linux/i2c-slave.h new file mode 100644 index 00000000000..34df64f73f6 --- /dev/null +++ b/include/linux/i2c-slave.h | |||
| @@ -0,0 +1,259 @@ | |||
| 1 | /* | ||
| 2 | * i2c-slave.h - definitions for the i2c-slave-bus interface | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009-2011, NVIDIA Corporation. | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 14 | * more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License along | ||
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 19 | */ | ||
| 20 | |||
| 21 | /* ------------------------------------------------------------------------- */ | ||
| 22 | |||
| 23 | #ifndef _LINUX_I2C_SLAVE_H | ||
| 24 | #define _LINUX_I2C_SLAVE_H | ||
| 25 | |||
| 26 | #include <linux/types.h> | ||
| 27 | #ifdef __KERNEL__ | ||
| 28 | /* --- General options ------------------------------------------------ */ | ||
| 29 | |||
| 30 | struct i2c_client; | ||
| 31 | struct i2c_slave_algorithm; | ||
| 32 | struct i2c_slave_adapter; | ||
| 33 | #if defined(CONFIG_I2C_SLAVE) && defined(CONFIG_I2C) | ||
| 34 | |||
| 35 | /** | ||
| 36 | * i2c_slave_send - Sends data to master. When master issues a read cycle, the | ||
| 37 | * data is sent by the slave. | ||
| 38 | * This function copies the client data into the slave tx buffer and return to | ||
| 39 | * client. This is not a blocking call. Data will be sent to master later once | ||
| 40 | * slave got the master-ready cycle transfer. | ||
| 41 | * if there is no sufficient space to write the client buffer, it will return | ||
| 42 | * error. it will not write partial data. | ||
| 43 | * @client: Handle to i2c-slave client. | ||
| 44 | * @buf: Data that will be written to the master | ||
| 45 | * @count: How many bytes to write. | ||
| 46 | * | ||
| 47 | * Returns negative errno, or else the number of bytes written. | ||
| 48 | */ | ||
| 49 | extern int i2c_slave_send(struct i2c_client *client, const char *buf, | ||
| 50 | int count); | ||
| 51 | |||
| 52 | /** | ||
| 53 | * i2c_slave_get_tx_status - Get amount of data available in tx buffer. If there | ||
| 54 | * is still data in tx buffer then wait for given time to transfer complete | ||
| 55 | * for a give timeout. | ||
| 56 | * @client: Handle to i2c-slave client. | ||
| 57 | * @timeout_ms: Time to wait for transfer to complete. | ||
| 58 | * | ||
| 59 | * Returns negative errno, or else the number of bytes remaining in tx buffer. | ||
| 60 | */ | ||
| 61 | extern int i2c_slave_get_tx_status(struct i2c_client *client, int timeout_ms); | ||
| 62 | |||
| 63 | /** | ||
| 64 | * i2c_slave_recv - Receive data from master. The data received from master is | ||
| 65 | * stored on slave rx buffer. When this api will be called, the data will be | ||
| 66 | * copied from the slave rx buffer to client buffer. If requested amount (count) | ||
| 67 | * of data is not available then it will wait for either min_count to be receive | ||
| 68 | * or timeout whatever first. | ||
| 69 | * | ||
| 70 | * if timeout_ms = 0, then wait for min_count data to be read. | ||
| 71 | * if timoue_ms non zero then wait for the data till timeout happen. | ||
| 72 | * @client: Handle to i2c-slave client. | ||
| 73 | * @buf: Data that will be read from the master | ||
| 74 | * @count: How many bytes to read. | ||
| 75 | * @min_count: Block till read min_count of data. | ||
| 76 | * @timeout_ms: Time to wait for read to be complete. | ||
| 77 | * | ||
| 78 | * Returns negative errno, or else the number of bytes read. | ||
| 79 | */ | ||
| 80 | extern int i2c_slave_recv(struct i2c_client *client, char *buf, int count, | ||
| 81 | int min_count, int timeout_ms); | ||
| 82 | |||
| 83 | /** | ||
| 84 | * i2c_slave_start - Start the i2c slave to receive/transmit data. | ||
| 85 | * After this i2c controller starts responding master. | ||
| 86 | * The dummy-char will send to master if there is no data to send on slave tx | ||
| 87 | * buffer. | ||
| 88 | * @client: Handle to i2c-slave client. | ||
| 89 | * @dummy_char: Data which will be send to master if there is no data to be send | ||
| 90 | * in slave tx buffer. | ||
| 91 | * | ||
| 92 | * Returns negative errno, or else 0 for success. | ||
| 93 | */ | ||
| 94 | extern int i2c_slave_start(struct i2c_client *client, unsigned char dummy_char); | ||
| 95 | |||
| 96 | /** | ||
| 97 | * i2c_slave_stop - Stop slave to receive/transmit data. | ||
| 98 | * After this i2c controller stops responding master. | ||
| 99 | * @client: Handle to i2c-slave client. | ||
| 100 | * @is_buffer_clear: Reset the tx and rx slave buffer or not. | ||
| 101 | */ | ||
| 102 | extern void i2c_slave_stop(struct i2c_client *client, int is_buffer_clear); | ||
| 103 | |||
| 104 | /** | ||
| 105 | * i2c_slave_flush_buffer - Flush the receive and transmit buffer. | ||
| 106 | * @client: Handle to i2c-slave client. | ||
| 107 | * @is_flush_tx_buffer: Reset the tx slave buffer or not. | ||
| 108 | * @is_flush_rx_buffer: Reset the rx slave buffer or not. | ||
| 109 | * | ||
| 110 | * Returns negative errno, or else 0 for success. | ||
| 111 | */ | ||
| 112 | extern int i2c_slave_flush_buffer(struct i2c_client *client, | ||
| 113 | int is_flush_tx_buffer, int is_flush_rx_buffer); | ||
| 114 | |||
| 115 | /** | ||
| 116 | * i2c_slave_get_nack_cycle - Get the number of master read cycle on which | ||
| 117 | * dummy char sent. This is the way to find that how much cycle slave sent the | ||
| 118 | * NACK packet. | ||
| 119 | * | ||
| 120 | * @client: Handle to i2c-slave client. | ||
| 121 | * @is_cout_reset: Reset the nack count or not. | ||
| 122 | * | ||
| 123 | * Returns negative errno, or else 0 for success. | ||
| 124 | */ | ||
| 125 | extern int i2c_slave_get_nack_cycle(struct i2c_client *client, | ||
| 126 | int is_cout_reset); | ||
| 127 | |||
| 128 | |||
| 129 | /** | ||
| 130 | * i2c_add_slave_adapter - Add slave adapter. | ||
| 131 | * | ||
| 132 | * @slv_adap: Slave adapter. | ||
| 133 | * @force_nr: Adapter number. | ||
| 134 | * | ||
| 135 | * Returns negative errno, or else 0 for success. | ||
| 136 | */ | ||
| 137 | extern int i2c_add_slave_adapter(struct i2c_slave_adapter *slv_adap, | ||
| 138 | bool force_nr); | ||
| 139 | |||
| 140 | /** | ||
| 141 | * i2c_del_slave_adapter - Delete slave adapter. | ||
| 142 | * | ||
| 143 | * @slv_adap: Slave adapter. | ||
| 144 | * | ||
| 145 | * Returns negative errno, or else 0 for success. | ||
| 146 | */ | ||
| 147 | extern int i2c_del_slave_adapter(struct i2c_slave_adapter *slv_adap); | ||
| 148 | |||
| 149 | #endif /* I2C_SLAVE */ | ||
| 150 | |||
| 151 | /* | ||
| 152 | * i2c_slave_adapter is the structure used to identify a physical i2c bus along | ||
| 153 | * with the access algorithms necessary to access it. | ||
| 154 | */ | ||
| 155 | struct i2c_slave_adapter { | ||
| 156 | struct module *owner; | ||
| 157 | unsigned int id; | ||
| 158 | unsigned int class; /* classes to allow probing for */ | ||
| 159 | /* the algorithm to access the i2c-slave bus */ | ||
| 160 | const struct i2c_slave_algorithm *slv_algo; | ||
| 161 | void *algo_data; | ||
| 162 | void *parent_data; | ||
| 163 | |||
| 164 | /* data fields that are valid for all devices */ | ||
| 165 | u8 level; /* nesting level for lockdep */ | ||
| 166 | struct mutex bus_lock; | ||
| 167 | |||
| 168 | int timeout; /* in jiffies */ | ||
| 169 | int retries; | ||
| 170 | struct device *dev; /* the adapter device */ | ||
| 171 | struct device *parent_dev; /* the adapter device */ | ||
| 172 | |||
| 173 | int nr; | ||
| 174 | char name[48]; | ||
| 175 | struct completion dev_released; | ||
| 176 | }; | ||
| 177 | |||
| 178 | static inline void *i2c_get_slave_adapdata(const struct i2c_slave_adapter *dev) | ||
| 179 | { | ||
| 180 | return dev_get_drvdata(dev->dev); | ||
| 181 | } | ||
| 182 | |||
| 183 | static inline void i2c_set_slave_adapdata(struct i2c_slave_adapter *dev, | ||
| 184 | void *data) | ||
| 185 | { | ||
| 186 | dev_set_drvdata(dev->dev, data); | ||
| 187 | } | ||
| 188 | |||
| 189 | /* | ||
| 190 | * The following struct are for those who like to implement new i2c slave | ||
| 191 | * bus drivers: | ||
| 192 | * i2c_slave_algorithm is the interface to a class of hardware solutions which | ||
| 193 | * can be addressed using the same bus algorithms. | ||
| 194 | */ | ||
| 195 | struct i2c_slave_algorithm { | ||
| 196 | /* Start the slave to receive/transmit data. | ||
| 197 | * The dummy-char will send to master if there is no data to send on | ||
| 198 | * slave tx buffer. | ||
| 199 | */ | ||
| 200 | int (*slave_start)(struct i2c_slave_adapter *slv_adap, int addr, | ||
| 201 | int is_ten_bit_addr, unsigned char dummy_char); | ||
| 202 | |||
| 203 | /* Stop slave to receive/transmit data. | ||
| 204 | * Required information to reset the slave rx and tx buffer to reset | ||
| 205 | * or not. | ||
| 206 | */ | ||
| 207 | void (*slave_stop)(struct i2c_slave_adapter *slv_adap, | ||
| 208 | int is_buffer_clear); | ||
| 209 | |||
| 210 | /* | ||
| 211 | * Send data to master. The data will be copied on the slave tx buffer | ||
| 212 | * and will send to master once master initiates the master-read cycle. | ||
| 213 | * Function will return immediately once the buffer copied into slave | ||
| 214 | * tx buffer. | ||
| 215 | * Client will not wait till data is sent to master. | ||
| 216 | * This function will not copy data partially. If sufficient space is | ||
| 217 | * not available, it will return error. | ||
| 218 | */ | ||
| 219 | int (*slave_send)(struct i2c_slave_adapter *slv_adap, const char *buf, | ||
| 220 | int count); | ||
| 221 | |||
| 222 | /* | ||
| 223 | * Get amount of data available in tx buffer. If there is still data in | ||
| 224 | * tx buffer wait for given time to get slave tx buffer emptied. | ||
| 225 | * returns number of data available in slave tx buffer. | ||
| 226 | */ | ||
| 227 | int (*slave_get_tx_status)(struct i2c_slave_adapter *slv_adap, | ||
| 228 | int timeout_ms); | ||
| 229 | |||
| 230 | /* | ||
| 231 | * Receive data to master. The data received from master is stored on | ||
| 232 | * slave rx buffer. When this api will be called, the data will be | ||
| 233 | * coped from the slave rx buffer to client buffer. If requested (count) | ||
| 234 | * data is not available then it will wait for either min_count to be | ||
| 235 | * receive or timeout whatever first. | ||
| 236 | * | ||
| 237 | * if timeout_ms = 0, then wait for min_count data to be read. | ||
| 238 | * if timoue_ms non zero then wait for the data till timeout happen. | ||
| 239 | * returns number of bytes read as positive integer otherwise error. | ||
| 240 | */ | ||
| 241 | int (*slave_recv)(struct i2c_slave_adapter *slv_adap, char *buf, | ||
| 242 | int count, int min_count, int timeout_ms); | ||
| 243 | |||
| 244 | /* Flush the receive and transmit buffer. | ||
| 245 | */ | ||
| 246 | int (*slave_flush_buffer)(struct i2c_slave_adapter *slv_adap, | ||
| 247 | int is_flush_tx_buffer, int is_flush_rx_buffer); | ||
| 248 | |||
| 249 | /* Get the number of dummy char cycle. | ||
| 250 | * Get the number of master read cycle on which dummy character has | ||
| 251 | * been sent. | ||
| 252 | * This can be treat as NACK cycle from slave side. | ||
| 253 | * Pass option whether count need to be reset or not. | ||
| 254 | */ | ||
| 255 | int (*slave_get_nack_cycle)(struct i2c_slave_adapter *slv_adap, | ||
| 256 | int is_cout_reset); | ||
| 257 | }; | ||
| 258 | #endif /* __KERNEL__ */ | ||
| 259 | #endif /* _LINUX_I2C_SLAVE_H */ | ||
