John Stultz | 453bbea | 2015-04-09 16:01:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 3 | * redistributing this file, you may do so under either license. |
| 4 | * |
| 5 | * GPL LICENSE SUMMARY |
| 6 | * |
| 7 | * Copyright(c) 2014 - 2015 Google Inc. All rights reserved. |
| 8 | * Copyright(c) 2014 - 2015 Linaro Ltd. All rights reserved. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of version 2 of the GNU General Public License as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License version 2 for more details. |
| 18 | * |
| 19 | * BSD LICENSE |
| 20 | * |
| 21 | * Copyright(c) 2014 - 2015 Google Inc. All rights reserved. |
| 22 | * Copyright(c) 2014 - 2015 Linaro Ltd. All rights reserved. |
| 23 | * |
| 24 | * Redistribution and use in source and binary forms, with or without |
| 25 | * modification, are permitted provided that the following conditions |
| 26 | * are met: |
| 27 | * |
| 28 | * * Redistributions of source code must retain the above copyright |
| 29 | * notice, this list of conditions and the following disclaimer. |
| 30 | * * Redistributions in binary form must reproduce the above copyright |
| 31 | * notice, this list of conditions and the following disclaimer in |
| 32 | * the documentation and/or other materials provided with the |
| 33 | * distribution. |
| 34 | * * Neither the name of Google Inc. or Linaro Ltd. nor the names of |
| 35 | * its contributors may be used to endorse or promote products |
| 36 | * derived from this software without specific prior written |
| 37 | * permission. |
| 38 | * |
| 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 40 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 41 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 42 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR |
| 43 | * LINARO LTD. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 44 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 45 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 46 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 47 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 48 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 49 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 50 | */ |
| 51 | |
Greg Kroah-Hartman | 67c920b | 2015-04-10 11:18:49 +0200 | [diff] [blame] | 52 | #ifndef __GB_GPBRIDGE_H__ |
| 53 | #define __GB_GPBRIDGE_H__ |
John Stultz | 453bbea | 2015-04-09 16:01:31 -0700 | [diff] [blame] | 54 | |
| 55 | /* I2C */ |
| 56 | |
| 57 | /* Version of the Greybus i2c protocol we support */ |
Greg Kroah-Hartman | 67c920b | 2015-04-10 11:18:49 +0200 | [diff] [blame] | 58 | #define GB_I2C_VERSION_MAJOR 0x00 |
| 59 | #define GB_I2C_VERSION_MINOR 0x01 |
John Stultz | 453bbea | 2015-04-09 16:01:31 -0700 | [diff] [blame] | 60 | |
| 61 | /* Greybus i2c request types */ |
Greg Kroah-Hartman | 67c920b | 2015-04-10 11:18:49 +0200 | [diff] [blame] | 62 | #define GB_I2C_TYPE_INVALID 0x00 |
| 63 | #define GB_I2C_TYPE_PROTOCOL_VERSION 0x01 |
| 64 | #define GB_I2C_TYPE_FUNCTIONALITY 0x02 |
| 65 | #define GB_I2C_TYPE_TIMEOUT 0x03 |
| 66 | #define GB_I2C_TYPE_RETRIES 0x04 |
| 67 | #define GB_I2C_TYPE_TRANSFER 0x05 |
John Stultz | 453bbea | 2015-04-09 16:01:31 -0700 | [diff] [blame] | 68 | |
Greg Kroah-Hartman | 67c920b | 2015-04-10 11:18:49 +0200 | [diff] [blame] | 69 | #define GB_I2C_RETRIES_DEFAULT 3 |
| 70 | #define GB_I2C_TIMEOUT_DEFAULT 1000 /* milliseconds */ |
John Stultz | 453bbea | 2015-04-09 16:01:31 -0700 | [diff] [blame] | 71 | |
| 72 | /* functionality request has no payload */ |
| 73 | struct gb_i2c_functionality_response { |
| 74 | __le32 functionality; |
| 75 | }; |
| 76 | |
| 77 | struct gb_i2c_timeout_request { |
| 78 | __le16 msec; |
| 79 | }; |
| 80 | /* timeout response has no payload */ |
| 81 | |
| 82 | struct gb_i2c_retries_request { |
| 83 | __u8 retries; |
| 84 | }; |
| 85 | /* retries response has no payload */ |
| 86 | |
| 87 | /* |
| 88 | * Outgoing data immediately follows the op count and ops array. |
| 89 | * The data for each write (master -> slave) op in the array is sent |
| 90 | * in order, with no (e.g. pad) bytes separating them. |
| 91 | * |
| 92 | * Short reads cause the entire transfer request to fail So response |
| 93 | * payload consists only of bytes read, and the number of bytes is |
| 94 | * exactly what was specified in the corresponding op. Like |
| 95 | * outgoing data, the incoming data is in order and contiguous. |
| 96 | */ |
| 97 | struct gb_i2c_transfer_op { |
| 98 | __le16 addr; |
| 99 | __le16 flags; |
| 100 | __le16 size; |
| 101 | }; |
| 102 | |
| 103 | struct gb_i2c_transfer_request { |
| 104 | __le16 op_count; |
| 105 | struct gb_i2c_transfer_op ops[0]; /* op_count of these */ |
| 106 | }; |
| 107 | struct gb_i2c_transfer_response { |
| 108 | __u8 data[0]; /* inbound data */ |
| 109 | }; |
| 110 | |
| 111 | |
| 112 | /* GPIO */ |
| 113 | |
| 114 | /* Version of the Greybus GPIO protocol we support */ |
Greg Kroah-Hartman | 67c920b | 2015-04-10 11:18:49 +0200 | [diff] [blame] | 115 | #define GB_GPIO_VERSION_MAJOR 0x00 |
| 116 | #define GB_GPIO_VERSION_MINOR 0x01 |
John Stultz | 453bbea | 2015-04-09 16:01:31 -0700 | [diff] [blame] | 117 | |
| 118 | /* Greybus GPIO request types */ |
Greg Kroah-Hartman | 67c920b | 2015-04-10 11:18:49 +0200 | [diff] [blame] | 119 | #define GB_GPIO_TYPE_INVALID 0x00 |
| 120 | #define GB_GPIO_TYPE_PROTOCOL_VERSION 0x01 |
| 121 | #define GB_GPIO_TYPE_LINE_COUNT 0x02 |
| 122 | #define GB_GPIO_TYPE_ACTIVATE 0x03 |
| 123 | #define GB_GPIO_TYPE_DEACTIVATE 0x04 |
| 124 | #define GB_GPIO_TYPE_GET_DIRECTION 0x05 |
| 125 | #define GB_GPIO_TYPE_DIRECTION_IN 0x06 |
| 126 | #define GB_GPIO_TYPE_DIRECTION_OUT 0x07 |
| 127 | #define GB_GPIO_TYPE_GET_VALUE 0x08 |
| 128 | #define GB_GPIO_TYPE_SET_VALUE 0x09 |
| 129 | #define GB_GPIO_TYPE_SET_DEBOUNCE 0x0a |
John Stultz | 453bbea | 2015-04-09 16:01:31 -0700 | [diff] [blame] | 130 | #define GB_GPIO_TYPE_IRQ_TYPE 0x0b |
| 131 | #define GB_GPIO_TYPE_IRQ_ACK 0x0c |
| 132 | #define GB_GPIO_TYPE_IRQ_MASK 0x0d |
| 133 | #define GB_GPIO_TYPE_IRQ_UNMASK 0x0e |
| 134 | #define GB_GPIO_TYPE_IRQ_EVENT 0x0f |
John Stultz | 453bbea | 2015-04-09 16:01:31 -0700 | [diff] [blame] | 135 | |
Greg Kroah-Hartman | 67c920b | 2015-04-10 11:18:49 +0200 | [diff] [blame] | 136 | #define GB_GPIO_DEBOUNCE_USEC_DEFAULT 0 /* microseconds */ |
John Stultz | 453bbea | 2015-04-09 16:01:31 -0700 | [diff] [blame] | 137 | |
| 138 | /* line count request has no payload */ |
| 139 | struct gb_gpio_line_count_response { |
| 140 | __u8 count; |
| 141 | }; |
| 142 | |
| 143 | struct gb_gpio_activate_request { |
| 144 | __u8 which; |
| 145 | }; |
| 146 | /* activate response has no payload */ |
| 147 | |
| 148 | struct gb_gpio_deactivate_request { |
| 149 | __u8 which; |
| 150 | }; |
| 151 | /* deactivate response has no payload */ |
| 152 | |
| 153 | struct gb_gpio_get_direction_request { |
| 154 | __u8 which; |
| 155 | }; |
| 156 | struct gb_gpio_get_direction_response { |
| 157 | __u8 direction; |
| 158 | }; |
| 159 | |
| 160 | struct gb_gpio_direction_in_request { |
| 161 | __u8 which; |
| 162 | }; |
| 163 | /* direction in response has no payload */ |
| 164 | |
| 165 | struct gb_gpio_direction_out_request { |
| 166 | __u8 which; |
| 167 | __u8 value; |
| 168 | }; |
| 169 | /* direction out response has no payload */ |
| 170 | |
| 171 | struct gb_gpio_get_value_request { |
| 172 | __u8 which; |
| 173 | }; |
| 174 | struct gb_gpio_get_value_response { |
| 175 | __u8 value; |
| 176 | }; |
| 177 | |
| 178 | struct gb_gpio_set_value_request { |
| 179 | __u8 which; |
| 180 | __u8 value; |
| 181 | }; |
| 182 | /* set value response has no payload */ |
| 183 | |
| 184 | struct gb_gpio_set_debounce_request { |
| 185 | __u8 which; |
| 186 | __le16 usec __packed; |
| 187 | }; |
| 188 | /* debounce response has no payload */ |
| 189 | |
| 190 | struct gb_gpio_irq_type_request { |
| 191 | __u8 which; |
| 192 | __u8 type; |
| 193 | }; |
| 194 | /* irq type response has no payload */ |
| 195 | |
| 196 | struct gb_gpio_irq_mask_request { |
| 197 | __u8 which; |
| 198 | }; |
| 199 | /* irq mask response has no payload */ |
| 200 | |
| 201 | struct gb_gpio_irq_unmask_request { |
| 202 | __u8 which; |
| 203 | }; |
| 204 | /* irq unmask response has no payload */ |
| 205 | |
| 206 | struct gb_gpio_irq_ack_request { |
| 207 | __u8 which; |
| 208 | }; |
| 209 | /* irq ack response has no payload */ |
| 210 | |
| 211 | /* irq event requests originate on another module and are handled on the AP */ |
| 212 | struct gb_gpio_irq_event_request { |
| 213 | __u8 which; |
| 214 | }; |
| 215 | /* irq event response has no payload */ |
| 216 | |
| 217 | |
| 218 | /* PWM */ |
| 219 | |
| 220 | /* Version of the Greybus PWM protocol we support */ |
Greg Kroah-Hartman | 67c920b | 2015-04-10 11:18:49 +0200 | [diff] [blame] | 221 | #define GB_PWM_VERSION_MAJOR 0x00 |
| 222 | #define GB_PWM_VERSION_MINOR 0x01 |
John Stultz | 453bbea | 2015-04-09 16:01:31 -0700 | [diff] [blame] | 223 | |
Alex Elder | 6d65337 | 2015-05-07 13:03:52 -0500 | [diff] [blame] | 224 | /* Greybus PWM operation types */ |
Greg Kroah-Hartman | 67c920b | 2015-04-10 11:18:49 +0200 | [diff] [blame] | 225 | #define GB_PWM_TYPE_INVALID 0x00 |
| 226 | #define GB_PWM_TYPE_PROTOCOL_VERSION 0x01 |
| 227 | #define GB_PWM_TYPE_PWM_COUNT 0x02 |
| 228 | #define GB_PWM_TYPE_ACTIVATE 0x03 |
| 229 | #define GB_PWM_TYPE_DEACTIVATE 0x04 |
| 230 | #define GB_PWM_TYPE_CONFIG 0x05 |
| 231 | #define GB_PWM_TYPE_POLARITY 0x06 |
| 232 | #define GB_PWM_TYPE_ENABLE 0x07 |
| 233 | #define GB_PWM_TYPE_DISABLE 0x08 |
John Stultz | 453bbea | 2015-04-09 16:01:31 -0700 | [diff] [blame] | 234 | |
| 235 | /* pwm count request has no payload */ |
| 236 | struct gb_pwm_count_response { |
| 237 | __u8 count; |
| 238 | }; |
| 239 | |
| 240 | struct gb_pwm_activate_request { |
| 241 | __u8 which; |
| 242 | }; |
| 243 | |
| 244 | struct gb_pwm_deactivate_request { |
| 245 | __u8 which; |
| 246 | }; |
| 247 | |
| 248 | struct gb_pwm_config_request { |
| 249 | __u8 which; |
| 250 | __le32 duty __packed; |
| 251 | __le32 period __packed; |
| 252 | }; |
| 253 | |
| 254 | struct gb_pwm_polarity_request { |
| 255 | __u8 which; |
| 256 | __u8 polarity; |
| 257 | }; |
| 258 | |
| 259 | struct gb_pwm_enable_request { |
| 260 | __u8 which; |
| 261 | }; |
| 262 | |
| 263 | struct gb_pwm_disable_request { |
| 264 | __u8 which; |
| 265 | }; |
| 266 | |
| 267 | /* I2S */ |
John Stultz | 453bbea | 2015-04-09 16:01:31 -0700 | [diff] [blame] | 268 | |
| 269 | #define GB_I2S_MGMT_TYPE_PROTOCOL_VERSION 0x01 |
| 270 | #define GB_I2S_MGMT_TYPE_GET_SUPPORTED_CONFIGURATIONS 0x02 |
| 271 | #define GB_I2S_MGMT_TYPE_SET_CONFIGURATION 0x03 |
| 272 | #define GB_I2S_MGMT_TYPE_SET_SAMPLES_PER_MESSAGE 0x04 |
| 273 | #define GB_I2S_MGMT_TYPE_GET_PROCESSING_DELAY 0x05 |
| 274 | #define GB_I2S_MGMT_TYPE_SET_START_DELAY 0x06 |
| 275 | #define GB_I2S_MGMT_TYPE_ACTIVATE_CPORT 0x07 |
| 276 | #define GB_I2S_MGMT_TYPE_DEACTIVATE_CPORT 0x08 |
| 277 | #define GB_I2S_MGMT_TYPE_REPORT_EVENT 0x09 |
| 278 | |
| 279 | #define GB_I2S_MGMT_BYTE_ORDER_NA BIT(0) |
| 280 | #define GB_I2S_MGMT_BYTE_ORDER_BE BIT(1) |
| 281 | #define GB_I2S_MGMT_BYTE_ORDER_LE BIT(2) |
| 282 | |
| 283 | #define GB_I2S_MGMT_SPATIAL_LOCATION_FL BIT(0) |
| 284 | #define GB_I2S_MGMT_SPATIAL_LOCATION_FR BIT(1) |
| 285 | #define GB_I2S_MGMT_SPATIAL_LOCATION_FC BIT(2) |
| 286 | #define GB_I2S_MGMT_SPATIAL_LOCATION_LFE BIT(3) |
| 287 | #define GB_I2S_MGMT_SPATIAL_LOCATION_BL BIT(4) |
| 288 | #define GB_I2S_MGMT_SPATIAL_LOCATION_BR BIT(5) |
| 289 | #define GB_I2S_MGMT_SPATIAL_LOCATION_FLC BIT(6) |
| 290 | #define GB_I2S_MGMT_SPATIAL_LOCATION_FRC BIT(7) |
| 291 | #define GB_I2S_MGMT_SPATIAL_LOCATION_C BIT(8) /* BC in USB */ |
| 292 | #define GB_I2S_MGMT_SPATIAL_LOCATION_SL BIT(9) |
| 293 | #define GB_I2S_MGMT_SPATIAL_LOCATION_SR BIT(10) |
| 294 | #define GB_I2S_MGMT_SPATIAL_LOCATION_TC BIT(11) |
| 295 | #define GB_I2S_MGMT_SPATIAL_LOCATION_TFL BIT(12) |
| 296 | #define GB_I2S_MGMT_SPATIAL_LOCATION_TFC BIT(13) |
| 297 | #define GB_I2S_MGMT_SPATIAL_LOCATION_TFR BIT(14) |
| 298 | #define GB_I2S_MGMT_SPATIAL_LOCATION_TBL BIT(15) |
| 299 | #define GB_I2S_MGMT_SPATIAL_LOCATION_TBC BIT(16) |
| 300 | #define GB_I2S_MGMT_SPATIAL_LOCATION_TBR BIT(17) |
| 301 | #define GB_I2S_MGMT_SPATIAL_LOCATION_TFLC BIT(18) |
| 302 | #define GB_I2S_MGMT_SPATIAL_LOCATION_TFRC BIT(19) |
| 303 | #define GB_I2S_MGMT_SPATIAL_LOCATION_LLFE BIT(20) |
| 304 | #define GB_I2S_MGMT_SPATIAL_LOCATION_RLFE BIT(21) |
| 305 | #define GB_I2S_MGMT_SPATIAL_LOCATION_TSL BIT(22) |
| 306 | #define GB_I2S_MGMT_SPATIAL_LOCATION_TSR BIT(23) |
| 307 | #define GB_I2S_MGMT_SPATIAL_LOCATION_BC BIT(24) |
| 308 | #define GB_I2S_MGMT_SPATIAL_LOCATION_BLC BIT(25) |
| 309 | #define GB_I2S_MGMT_SPATIAL_LOCATION_BRC BIT(26) |
| 310 | #define GB_I2S_MGMT_SPATIAL_LOCATION_RD BIT(31) |
| 311 | |
| 312 | #define GB_I2S_MGMT_PROTOCOL_PCM BIT(0) |
| 313 | #define GB_I2S_MGMT_PROTOCOL_I2S BIT(1) |
| 314 | #define GB_I2S_MGMT_PROTOCOL_LR_STEREO BIT(2) |
| 315 | |
| 316 | #define GB_I2S_MGMT_ROLE_MASTER BIT(0) |
| 317 | #define GB_I2S_MGMT_ROLE_SLAVE BIT(1) |
| 318 | |
| 319 | #define GB_I2S_MGMT_POLARITY_NORMAL BIT(0) |
| 320 | #define GB_I2S_MGMT_POLARITY_REVERSED BIT(1) |
| 321 | |
| 322 | #define GB_I2S_MGMT_EDGE_RISING BIT(0) |
| 323 | #define GB_I2S_MGMT_EDGE_FALLING BIT(1) |
| 324 | |
| 325 | #define GB_I2S_MGMT_EVENT_UNSPECIFIED 0x1 |
| 326 | #define GB_I2S_MGMT_EVENT_HALT 0x2 |
| 327 | #define GB_I2S_MGMT_EVENT_INTERNAL_ERROR 0x3 |
| 328 | #define GB_I2S_MGMT_EVENT_PROTOCOL_ERROR 0x4 |
| 329 | #define GB_I2S_MGMT_EVENT_FAILURE 0x5 |
| 330 | #define GB_I2S_MGMT_EVENT_OUT_OF_SEQUENCE 0x6 |
| 331 | #define GB_I2S_MGMT_EVENT_UNDERRUN 0x7 |
| 332 | #define GB_I2S_MGMT_EVENT_OVERRUN 0x8 |
| 333 | #define GB_I2S_MGMT_EVENT_CLOCKING 0x9 |
| 334 | #define GB_I2S_MGMT_EVENT_DATA_LEN 0xa |
| 335 | |
| 336 | struct gb_i2s_mgmt_configuration { |
| 337 | __le32 sample_frequency; |
| 338 | __u8 num_channels; |
| 339 | __u8 bytes_per_channel; |
| 340 | __u8 byte_order; |
| 341 | __u8 pad; |
| 342 | __le32 spatial_locations; |
| 343 | __le32 ll_protocol; |
John Stultz | a4749bb | 2015-05-08 12:57:36 -0700 | [diff] [blame] | 344 | __u8 ll_mclk_role; |
John Stultz | 453bbea | 2015-04-09 16:01:31 -0700 | [diff] [blame] | 345 | __u8 ll_bclk_role; |
| 346 | __u8 ll_wclk_role; |
| 347 | __u8 ll_wclk_polarity; |
| 348 | __u8 ll_wclk_change_edge; |
| 349 | __u8 ll_wclk_tx_edge; |
| 350 | __u8 ll_wclk_rx_edge; |
| 351 | __u8 ll_data_offset; |
John Stultz | 453bbea | 2015-04-09 16:01:31 -0700 | [diff] [blame] | 352 | }; |
| 353 | |
| 354 | /* get supported configurations request has no payload */ |
| 355 | struct gb_i2s_mgmt_get_supported_configurations_response { |
| 356 | __u8 config_count; |
| 357 | __u8 pad[3]; |
| 358 | struct gb_i2s_mgmt_configuration config[0]; |
| 359 | }; |
| 360 | |
| 361 | struct gb_i2s_mgmt_set_configuration_request { |
| 362 | struct gb_i2s_mgmt_configuration config; |
| 363 | }; |
| 364 | /* set configuration response has no payload */ |
| 365 | |
| 366 | struct gb_i2s_mgmt_set_samples_per_message_request { |
| 367 | __le16 samples_per_message; |
| 368 | }; |
| 369 | /* set samples per message response has no payload */ |
| 370 | |
| 371 | /* get processing request delay has no payload */ |
| 372 | struct gb_i2s_mgmt_get_processing_delay_response { |
| 373 | __le32 microseconds; |
| 374 | }; |
| 375 | |
| 376 | struct gb_i2s_mgmt_set_start_delay_request { |
| 377 | __le32 microseconds; |
| 378 | }; |
| 379 | /* set start delay response has no payload */ |
| 380 | |
| 381 | struct gb_i2s_mgmt_activate_cport_request { |
| 382 | __le16 cport; |
| 383 | }; |
| 384 | /* activate cport response has no payload */ |
| 385 | |
| 386 | struct gb_i2s_mgmt_deactivate_cport_request { |
| 387 | __le16 cport; |
| 388 | }; |
| 389 | /* deactivate cport response has no payload */ |
| 390 | |
| 391 | struct gb_i2s_mgmt_report_event_request { |
| 392 | __u8 event; |
| 393 | }; |
| 394 | /* report event response has no payload */ |
| 395 | |
| 396 | #define GB_I2S_DATA_TYPE_PROTOCOL_VERSION 0x01 |
| 397 | #define GB_I2S_DATA_TYPE_SEND_DATA 0x02 |
| 398 | |
| 399 | struct gb_i2s_send_data_request { |
| 400 | __le32 sample_number; |
| 401 | __le32 size; |
| 402 | __u8 data[0]; |
| 403 | }; |
| 404 | /* send data has no response at all */ |
| 405 | |
Viresh Kumar | 4890f31 | 2015-05-20 16:33:57 +0530 | [diff] [blame] | 406 | |
| 407 | /* SPI */ |
| 408 | |
| 409 | /* Version of the Greybus spi protocol we support */ |
| 410 | #define GB_SPI_VERSION_MAJOR 0x00 |
| 411 | #define GB_SPI_VERSION_MINOR 0x01 |
| 412 | |
| 413 | /* Should match up with modes in linux/spi/spi.h */ |
| 414 | #define GB_SPI_MODE_CPHA 0x01 /* clock phase */ |
| 415 | #define GB_SPI_MODE_CPOL 0x02 /* clock polarity */ |
| 416 | #define GB_SPI_MODE_MODE_0 (0|0) /* (original MicroWire) */ |
| 417 | #define GB_SPI_MODE_MODE_1 (0|GB_SPI_MODE_CPHA) |
| 418 | #define GB_SPI_MODE_MODE_2 (GB_SPI_MODE_CPOL|0) |
| 419 | #define GB_SPI_MODE_MODE_3 (GB_SPI_MODE_CPOL|GB_SPI_MODE_CPHA) |
| 420 | #define GB_SPI_MODE_CS_HIGH 0x04 /* chipselect active high? */ |
| 421 | #define GB_SPI_MODE_LSB_FIRST 0x08 /* per-word bits-on-wire */ |
| 422 | #define GB_SPI_MODE_3WIRE 0x10 /* SI/SO signals shared */ |
| 423 | #define GB_SPI_MODE_LOOP 0x20 /* loopback mode */ |
| 424 | #define GB_SPI_MODE_NO_CS 0x40 /* 1 dev/bus, no chipselect */ |
| 425 | #define GB_SPI_MODE_READY 0x80 /* slave pulls low to pause */ |
| 426 | |
| 427 | /* Should match up with flags in linux/spi/spi.h */ |
| 428 | #define GB_SPI_FLAG_HALF_DUPLEX BIT(0) /* can't do full duplex */ |
| 429 | #define GB_SPI_FLAG_NO_RX BIT(1) /* can't do buffer read */ |
| 430 | #define GB_SPI_FLAG_NO_TX BIT(2) /* can't do buffer write */ |
| 431 | |
| 432 | /* Greybus spi operation types */ |
| 433 | #define GB_SPI_TYPE_INVALID 0x00 |
| 434 | #define GB_SPI_TYPE_PROTOCOL_VERSION 0x01 |
| 435 | #define GB_SPI_TYPE_MODE 0x02 |
| 436 | #define GB_SPI_TYPE_FLAGS 0x03 |
| 437 | #define GB_SPI_TYPE_BITS_PER_WORD_MASK 0x04 |
| 438 | #define GB_SPI_TYPE_NUM_CHIPSELECT 0x05 |
| 439 | #define GB_SPI_TYPE_TRANSFER 0x06 |
| 440 | |
| 441 | /* mode request has no payload */ |
| 442 | struct gb_spi_mode_response { |
| 443 | __le16 mode; |
| 444 | }; |
| 445 | |
| 446 | /* flags request has no payload */ |
| 447 | struct gb_spi_flags_response { |
| 448 | __le16 flags; |
| 449 | }; |
| 450 | |
| 451 | /* bits-per-word request has no payload */ |
| 452 | struct gb_spi_bpw_response { |
| 453 | __le32 bits_per_word_mask; |
| 454 | }; |
| 455 | |
| 456 | /* num-chipselects request has no payload */ |
| 457 | struct gb_spi_chipselect_response { |
| 458 | __le16 num_chipselect; |
| 459 | }; |
| 460 | |
| 461 | /** |
| 462 | * struct gb_spi_transfer - a read/write buffer pair |
| 463 | * @speed_hz: Select a speed other than the device default for this transfer. If |
| 464 | * 0 the default (from @spi_device) is used. |
| 465 | * @len: size of rx and tx buffers (in bytes) |
| 466 | * @delay_usecs: microseconds to delay after this transfer before (optionally) |
| 467 | * changing the chipselect status, then starting the next transfer or |
| 468 | * completing this spi_message. |
| 469 | * @cs_change: affects chipselect after this transfer completes |
| 470 | * @bits_per_word: select a bits_per_word other than the device default for this |
| 471 | * transfer. If 0 the default (from @spi_device) is used. |
| 472 | */ |
| 473 | struct gb_spi_transfer { |
| 474 | __le32 speed_hz; |
| 475 | __le32 len; |
| 476 | __le16 delay_usecs; |
| 477 | __u8 cs_change; |
| 478 | __u8 bits_per_word; |
| 479 | }; |
| 480 | |
| 481 | struct gb_spi_transfer_request { |
| 482 | __u8 chip_select; /* of the spi device */ |
| 483 | __u8 mode; /* of the spi device */ |
| 484 | __le16 count; |
| 485 | struct gb_spi_transfer transfers[0]; /* trnasfer_count of these */ |
| 486 | }; |
| 487 | |
| 488 | struct gb_spi_transfer_response { |
| 489 | __u8 data[0]; /* inbound data */ |
| 490 | }; |
| 491 | |
John Stultz | 453bbea | 2015-04-09 16:01:31 -0700 | [diff] [blame] | 492 | #endif /* __GB_GPBRIDGE_H__ */ |