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.
7 * Copyright(c) 2014 - 2015 Google Inc. All rights reserved.
8 * Copyright(c) 2014 - 2015 Linaro Ltd. All rights reserved.
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.
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.
21 * Copyright(c) 2014 - 2015 Google Inc. All rights reserved.
22 * Copyright(c) 2014 - 2015 Linaro Ltd. All rights reserved.
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
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
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
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.
52 #ifndef __GREYBUS_PROTOCOLS_H
53 #define __GREYBUS_PROTOCOLS_H
57 /* Version of the Greybus i2c protocol we support */
58 #define GB_I2C_VERSION_MAJOR 0x00
59 #define GB_I2C_VERSION_MINOR 0x01
61 /* Greybus i2c request types */
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
69 #define GB_I2C_RETRIES_DEFAULT 3
70 #define GB_I2C_TIMEOUT_DEFAULT 1000 /* milliseconds */
72 /* functionality request has no payload */
73 struct gb_i2c_functionality_response {
77 struct gb_i2c_timeout_request {
80 /* timeout response has no payload */
82 struct gb_i2c_retries_request {
85 /* retries response has no payload */
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.
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.
97 struct gb_i2c_transfer_op {
103 struct gb_i2c_transfer_request {
105 struct gb_i2c_transfer_op ops[0]; /* op_count of these */
107 struct gb_i2c_transfer_response {
108 __u8 data[0]; /* inbound data */
114 /* Version of the Greybus GPIO protocol we support */
115 #define GB_GPIO_VERSION_MAJOR 0x00
116 #define GB_GPIO_VERSION_MINOR 0x01
118 /* Greybus GPIO request types */
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
130 #define GB_GPIO_TYPE_IRQ_TYPE 0x0b
131 #define GB_GPIO_TYPE_IRQ_MASK 0x0c
132 #define GB_GPIO_TYPE_IRQ_UNMASK 0x0d
133 #define GB_GPIO_TYPE_IRQ_EVENT 0x0e
135 #define GB_GPIO_IRQ_TYPE_NONE 0x00
136 #define GB_GPIO_IRQ_TYPE_EDGE_RISING 0x01
137 #define GB_GPIO_IRQ_TYPE_EDGE_FALLING 0x02
138 #define GB_GPIO_IRQ_TYPE_EDGE_BOTH 0x03
139 #define GB_GPIO_IRQ_TYPE_LEVEL_HIGH 0x04
140 #define GB_GPIO_IRQ_TYPE_LEVEL_LOW 0x08
142 /* line count request has no payload */
143 struct gb_gpio_line_count_response {
147 struct gb_gpio_activate_request {
150 /* activate response has no payload */
152 struct gb_gpio_deactivate_request {
155 /* deactivate response has no payload */
157 struct gb_gpio_get_direction_request {
160 struct gb_gpio_get_direction_response {
164 struct gb_gpio_direction_in_request {
167 /* direction in response has no payload */
169 struct gb_gpio_direction_out_request {
173 /* direction out response has no payload */
175 struct gb_gpio_get_value_request {
178 struct gb_gpio_get_value_response {
182 struct gb_gpio_set_value_request {
186 /* set value response has no payload */
188 struct gb_gpio_set_debounce_request {
190 __le16 usec __packed;
192 /* debounce response has no payload */
194 struct gb_gpio_irq_type_request {
198 /* irq type response has no payload */
200 struct gb_gpio_irq_mask_request {
203 /* irq mask response has no payload */
205 struct gb_gpio_irq_unmask_request {
208 /* irq unmask response has no payload */
210 /* irq event requests originate on another module and are handled on the AP */
211 struct gb_gpio_irq_event_request {
214 /* irq event has no response */
219 /* Version of the Greybus PWM protocol we support */
220 #define GB_PWM_VERSION_MAJOR 0x00
221 #define GB_PWM_VERSION_MINOR 0x01
223 /* Greybus PWM operation types */
224 #define GB_PWM_TYPE_INVALID 0x00
225 #define GB_PWM_TYPE_PROTOCOL_VERSION 0x01
226 #define GB_PWM_TYPE_PWM_COUNT 0x02
227 #define GB_PWM_TYPE_ACTIVATE 0x03
228 #define GB_PWM_TYPE_DEACTIVATE 0x04
229 #define GB_PWM_TYPE_CONFIG 0x05
230 #define GB_PWM_TYPE_POLARITY 0x06
231 #define GB_PWM_TYPE_ENABLE 0x07
232 #define GB_PWM_TYPE_DISABLE 0x08
234 /* pwm count request has no payload */
235 struct gb_pwm_count_response {
239 struct gb_pwm_activate_request {
243 struct gb_pwm_deactivate_request {
247 struct gb_pwm_config_request {
249 __le32 duty __packed;
250 __le32 period __packed;
253 struct gb_pwm_polarity_request {
258 struct gb_pwm_enable_request {
262 struct gb_pwm_disable_request {
268 #define GB_I2S_MGMT_TYPE_PROTOCOL_VERSION 0x01
269 #define GB_I2S_MGMT_TYPE_GET_SUPPORTED_CONFIGURATIONS 0x02
270 #define GB_I2S_MGMT_TYPE_SET_CONFIGURATION 0x03
271 #define GB_I2S_MGMT_TYPE_SET_SAMPLES_PER_MESSAGE 0x04
272 #define GB_I2S_MGMT_TYPE_GET_PROCESSING_DELAY 0x05
273 #define GB_I2S_MGMT_TYPE_SET_START_DELAY 0x06
274 #define GB_I2S_MGMT_TYPE_ACTIVATE_CPORT 0x07
275 #define GB_I2S_MGMT_TYPE_DEACTIVATE_CPORT 0x08
276 #define GB_I2S_MGMT_TYPE_REPORT_EVENT 0x09
278 #define GB_I2S_MGMT_BYTE_ORDER_NA BIT(0)
279 #define GB_I2S_MGMT_BYTE_ORDER_BE BIT(1)
280 #define GB_I2S_MGMT_BYTE_ORDER_LE BIT(2)
282 #define GB_I2S_MGMT_SPATIAL_LOCATION_FL BIT(0)
283 #define GB_I2S_MGMT_SPATIAL_LOCATION_FR BIT(1)
284 #define GB_I2S_MGMT_SPATIAL_LOCATION_FC BIT(2)
285 #define GB_I2S_MGMT_SPATIAL_LOCATION_LFE BIT(3)
286 #define GB_I2S_MGMT_SPATIAL_LOCATION_BL BIT(4)
287 #define GB_I2S_MGMT_SPATIAL_LOCATION_BR BIT(5)
288 #define GB_I2S_MGMT_SPATIAL_LOCATION_FLC BIT(6)
289 #define GB_I2S_MGMT_SPATIAL_LOCATION_FRC BIT(7)
290 #define GB_I2S_MGMT_SPATIAL_LOCATION_C BIT(8) /* BC in USB */
291 #define GB_I2S_MGMT_SPATIAL_LOCATION_SL BIT(9)
292 #define GB_I2S_MGMT_SPATIAL_LOCATION_SR BIT(10)
293 #define GB_I2S_MGMT_SPATIAL_LOCATION_TC BIT(11)
294 #define GB_I2S_MGMT_SPATIAL_LOCATION_TFL BIT(12)
295 #define GB_I2S_MGMT_SPATIAL_LOCATION_TFC BIT(13)
296 #define GB_I2S_MGMT_SPATIAL_LOCATION_TFR BIT(14)
297 #define GB_I2S_MGMT_SPATIAL_LOCATION_TBL BIT(15)
298 #define GB_I2S_MGMT_SPATIAL_LOCATION_TBC BIT(16)
299 #define GB_I2S_MGMT_SPATIAL_LOCATION_TBR BIT(17)
300 #define GB_I2S_MGMT_SPATIAL_LOCATION_TFLC BIT(18)
301 #define GB_I2S_MGMT_SPATIAL_LOCATION_TFRC BIT(19)
302 #define GB_I2S_MGMT_SPATIAL_LOCATION_LLFE BIT(20)
303 #define GB_I2S_MGMT_SPATIAL_LOCATION_RLFE BIT(21)
304 #define GB_I2S_MGMT_SPATIAL_LOCATION_TSL BIT(22)
305 #define GB_I2S_MGMT_SPATIAL_LOCATION_TSR BIT(23)
306 #define GB_I2S_MGMT_SPATIAL_LOCATION_BC BIT(24)
307 #define GB_I2S_MGMT_SPATIAL_LOCATION_BLC BIT(25)
308 #define GB_I2S_MGMT_SPATIAL_LOCATION_BRC BIT(26)
309 #define GB_I2S_MGMT_SPATIAL_LOCATION_RD BIT(31)
311 #define GB_I2S_MGMT_PROTOCOL_PCM BIT(0)
312 #define GB_I2S_MGMT_PROTOCOL_I2S BIT(1)
313 #define GB_I2S_MGMT_PROTOCOL_LR_STEREO BIT(2)
315 #define GB_I2S_MGMT_ROLE_MASTER BIT(0)
316 #define GB_I2S_MGMT_ROLE_SLAVE BIT(1)
318 #define GB_I2S_MGMT_POLARITY_NORMAL BIT(0)
319 #define GB_I2S_MGMT_POLARITY_REVERSED BIT(1)
321 #define GB_I2S_MGMT_EDGE_RISING BIT(0)
322 #define GB_I2S_MGMT_EDGE_FALLING BIT(1)
324 #define GB_I2S_MGMT_EVENT_UNSPECIFIED 0x1
325 #define GB_I2S_MGMT_EVENT_HALT 0x2
326 #define GB_I2S_MGMT_EVENT_INTERNAL_ERROR 0x3
327 #define GB_I2S_MGMT_EVENT_PROTOCOL_ERROR 0x4
328 #define GB_I2S_MGMT_EVENT_FAILURE 0x5
329 #define GB_I2S_MGMT_EVENT_OUT_OF_SEQUENCE 0x6
330 #define GB_I2S_MGMT_EVENT_UNDERRUN 0x7
331 #define GB_I2S_MGMT_EVENT_OVERRUN 0x8
332 #define GB_I2S_MGMT_EVENT_CLOCKING 0x9
333 #define GB_I2S_MGMT_EVENT_DATA_LEN 0xa
335 struct gb_i2s_mgmt_configuration {
336 __le32 sample_frequency;
338 __u8 bytes_per_channel;
341 __le32 spatial_locations;
346 __u8 ll_wclk_polarity;
347 __u8 ll_wclk_change_edge;
348 __u8 ll_wclk_tx_edge;
349 __u8 ll_wclk_rx_edge;
353 /* get supported configurations request has no payload */
354 struct gb_i2s_mgmt_get_supported_configurations_response {
357 struct gb_i2s_mgmt_configuration config[0];
360 struct gb_i2s_mgmt_set_configuration_request {
361 struct gb_i2s_mgmt_configuration config;
363 /* set configuration response has no payload */
365 struct gb_i2s_mgmt_set_samples_per_message_request {
366 __le16 samples_per_message;
368 /* set samples per message response has no payload */
370 /* get processing request delay has no payload */
371 struct gb_i2s_mgmt_get_processing_delay_response {
375 struct gb_i2s_mgmt_set_start_delay_request {
378 /* set start delay response has no payload */
380 struct gb_i2s_mgmt_activate_cport_request {
383 /* activate cport response has no payload */
385 struct gb_i2s_mgmt_deactivate_cport_request {
388 /* deactivate cport response has no payload */
390 struct gb_i2s_mgmt_report_event_request {
393 /* report event response has no payload */
395 #define GB_I2S_DATA_TYPE_PROTOCOL_VERSION 0x01
396 #define GB_I2S_DATA_TYPE_SEND_DATA 0x02
398 struct gb_i2s_send_data_request {
399 __le32 sample_number;
403 /* send data has no response at all */
408 /* Version of the Greybus spi protocol we support */
409 #define GB_SPI_VERSION_MAJOR 0x00
410 #define GB_SPI_VERSION_MINOR 0x01
412 /* Should match up with modes in linux/spi/spi.h */
413 #define GB_SPI_MODE_CPHA 0x01 /* clock phase */
414 #define GB_SPI_MODE_CPOL 0x02 /* clock polarity */
415 #define GB_SPI_MODE_MODE_0 (0|0) /* (original MicroWire) */
416 #define GB_SPI_MODE_MODE_1 (0|GB_SPI_MODE_CPHA)
417 #define GB_SPI_MODE_MODE_2 (GB_SPI_MODE_CPOL|0)
418 #define GB_SPI_MODE_MODE_3 (GB_SPI_MODE_CPOL|GB_SPI_MODE_CPHA)
419 #define GB_SPI_MODE_CS_HIGH 0x04 /* chipselect active high? */
420 #define GB_SPI_MODE_LSB_FIRST 0x08 /* per-word bits-on-wire */
421 #define GB_SPI_MODE_3WIRE 0x10 /* SI/SO signals shared */
422 #define GB_SPI_MODE_LOOP 0x20 /* loopback mode */
423 #define GB_SPI_MODE_NO_CS 0x40 /* 1 dev/bus, no chipselect */
424 #define GB_SPI_MODE_READY 0x80 /* slave pulls low to pause */
426 /* Should match up with flags in linux/spi/spi.h */
427 #define GB_SPI_FLAG_HALF_DUPLEX BIT(0) /* can't do full duplex */
428 #define GB_SPI_FLAG_NO_RX BIT(1) /* can't do buffer read */
429 #define GB_SPI_FLAG_NO_TX BIT(2) /* can't do buffer write */
431 /* Greybus spi operation types */
432 #define GB_SPI_TYPE_INVALID 0x00
433 #define GB_SPI_TYPE_PROTOCOL_VERSION 0x01
434 #define GB_SPI_TYPE_MODE 0x02
435 #define GB_SPI_TYPE_FLAGS 0x03
436 #define GB_SPI_TYPE_BITS_PER_WORD_MASK 0x04
437 #define GB_SPI_TYPE_NUM_CHIPSELECT 0x05
438 #define GB_SPI_TYPE_TRANSFER 0x06
440 /* mode request has no payload */
441 struct gb_spi_mode_response {
445 /* flags request has no payload */
446 struct gb_spi_flags_response {
450 /* bits-per-word request has no payload */
451 struct gb_spi_bpw_response {
452 __le32 bits_per_word_mask;
455 /* num-chipselects request has no payload */
456 struct gb_spi_chipselect_response {
457 __le16 num_chipselect;
461 * struct gb_spi_transfer - a read/write buffer pair
462 * @speed_hz: Select a speed other than the device default for this transfer. If
463 * 0 the default (from @spi_device) is used.
464 * @len: size of rx and tx buffers (in bytes)
465 * @delay_usecs: microseconds to delay after this transfer before (optionally)
466 * changing the chipselect status, then starting the next transfer or
467 * completing this spi_message.
468 * @cs_change: affects chipselect after this transfer completes
469 * @bits_per_word: select a bits_per_word other than the device default for this
470 * transfer. If 0 the default (from @spi_device) is used.
472 struct gb_spi_transfer {
480 struct gb_spi_transfer_request {
481 __u8 chip_select; /* of the spi device */
482 __u8 mode; /* of the spi device */
484 struct gb_spi_transfer transfers[0]; /* trnasfer_count of these */
487 struct gb_spi_transfer_response {
488 __u8 data[0]; /* inbound data */
491 /* Version of the Greybus SVC protocol we support */
492 #define GB_SVC_VERSION_MAJOR 0x00
493 #define GB_SVC_VERSION_MINOR 0x01
495 /* Greybus SVC request types */
496 #define GB_SVC_TYPE_INVALID 0x00
497 #define GB_SVC_TYPE_PROTOCOL_VERSION 0x01
498 #define GB_SVC_TYPE_INTF_DEVICE_ID 0x02
499 #define GB_SVC_TYPE_INTF_HOTPLUG 0x03
500 #define GB_SVC_TYPE_INTF_HOT_UNPLUG 0x04
501 #define GB_SVC_TYPE_INTF_RESET 0x05
502 #define GB_SVC_TYPE_CONN_CREATE 0x06
503 #define GB_SVC_TYPE_CONN_DESTROY 0x07
505 struct gb_svc_intf_device_id_request {
509 /* device id response has no payload */
511 struct gb_svc_intf_hotplug_request {
514 __le32 unipro_mfg_id;
515 __le32 unipro_prod_id;
520 /* hotplug response has no payload */
522 struct gb_svc_intf_hot_unplug_request {
525 /* hot unplug response has no payload */
527 struct gb_svc_intf_reset_request {
530 /* interface reset response has no payload */
532 struct gb_svc_conn_create_request {
538 /* connection create response has no payload */
540 struct gb_svc_conn_destroy_request {
546 /* connection destroy response has no payload */
550 /* Version of the Greybus UART protocol we support */
551 #define GB_UART_VERSION_MAJOR 0x00
552 #define GB_UART_VERSION_MINOR 0x01
554 /* Greybus UART operation types */
555 #define GB_UART_TYPE_INVALID 0x00
556 #define GB_UART_TYPE_PROTOCOL_VERSION 0x01
557 #define GB_UART_TYPE_SEND_DATA 0x02
558 #define GB_UART_TYPE_RECEIVE_DATA 0x03 /* Unsolicited data */
559 #define GB_UART_TYPE_SET_LINE_CODING 0x04
560 #define GB_UART_TYPE_SET_CONTROL_LINE_STATE 0x05
561 #define GB_UART_TYPE_SET_BREAK 0x06
562 #define GB_UART_TYPE_SERIAL_STATE 0x07 /* Unsolicited data */
564 /* Represents data from AP -> Module */
565 struct gb_uart_send_data_request {
570 /* Represents data from Module -> AP */
571 struct gb_uart_recv_data_request {
576 struct gb_uart_set_line_coding_request {
579 #define GB_SERIAL_1_STOP_BITS 0
580 #define GB_SERIAL_1_5_STOP_BITS 1
581 #define GB_SERIAL_2_STOP_BITS 2
584 #define GB_SERIAL_NO_PARITY 0
585 #define GB_SERIAL_ODD_PARITY 1
586 #define GB_SERIAL_EVEN_PARITY 2
587 #define GB_SERIAL_MARK_PARITY 3
588 #define GB_SERIAL_SPACE_PARITY 4
593 /* output control lines */
594 #define GB_UART_CTRL_DTR 0x01
595 #define GB_UART_CTRL_RTS 0x02
597 struct gb_uart_set_control_line_state_request {
601 struct gb_uart_set_break_request {
605 /* input control lines and line errors */
606 #define GB_UART_CTRL_DCD 0x01
607 #define GB_UART_CTRL_DSR 0x02
608 #define GB_UART_CTRL_BRK 0x04
609 #define GB_UART_CTRL_RI 0x08
611 #define GB_UART_CTRL_FRAMING 0x10
612 #define GB_UART_CTRL_PARITY 0x20
613 #define GB_UART_CTRL_OVERRUN 0x40
615 struct gb_uart_serial_state_request {
619 #endif /* __GREYBUS_PROTOCOLS_H */