]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/greybus/greybus_protocols.h
greybus: Merge branch 'master' into branch 'svc'.
[karo-tx-linux.git] / drivers / staging / greybus / greybus_protocols.h
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
52 #ifndef __GREYBUS_PROTOCOLS_H
53 #define __GREYBUS_PROTOCOLS_H
54
55 /* Fixed IDs for control/svc protocols */
56
57 /* Device ID of SVC and AP */
58 #define GB_DEVICE_ID_SVC                        0
59 #define GB_DEVICE_ID_AP                         1
60 #define GB_DEVICE_ID_MODULES_START              2
61
62 /*
63  * Bundle/cport for control/svc cport: The same bundle/cport is shared by both
64  * CONTROL and SVC protocols for communication between AP and SVC.
65  */
66 #define GB_SVC_BUNDLE_ID                        0
67 #define GB_SVC_CPORT_ID                         0
68 #define GB_CONTROL_BUNDLE_ID                    0
69 #define GB_CONTROL_CPORT_ID                     0
70
71
72 /*
73  * All operation messages (both requests and responses) begin with
74  * a header that encodes the size of the message (header included).
75  * This header also contains a unique identifier, that associates a
76  * response message with its operation.  The header contains an
77  * operation type field, whose interpretation is dependent on what
78  * type of protocol is used over the connection.  The high bit
79  * (0x80) of the operation type field is used to indicate whether
80  * the message is a request (clear) or a response (set).
81  *
82  * Response messages include an additional result byte, which
83  * communicates the result of the corresponding request.  A zero
84  * result value means the operation completed successfully.  Any
85  * other value indicates an error; in this case, the payload of the
86  * response message (if any) is ignored.  The result byte must be
87  * zero in the header for a request message.
88  *
89  * The wire format for all numeric fields in the header is little
90  * endian.  Any operation-specific data begins immediately after the
91  * header.
92  */
93 struct gb_operation_msg_hdr {
94         __le16  size;           /* Size in bytes of header + payload */
95         __le16  operation_id;   /* Operation unique id */
96         __u8    type;           /* E.g GB_I2C_TYPE_* or GB_GPIO_TYPE_* */
97         __u8    result;         /* Result of request (in responses only) */
98         __u8    pad[2];         /* must be zero (ignore when read) */
99 };
100
101
102 /* Generic request numbers supported by all modules */
103 #define GB_REQUEST_TYPE_INVALID                 0x00
104 #define GB_REQUEST_TYPE_PROTOCOL_VERSION        0x01
105
106 /* Control Protocol */
107
108 /* version request has no payload */
109 struct gb_protocol_version_response {
110         __u8    major;
111         __u8    minor;
112 };
113
114 /* Control Protocol */
115
116 /* Version of the Greybus control protocol we support */
117 #define GB_CONTROL_VERSION_MAJOR                0x00
118 #define GB_CONTROL_VERSION_MINOR                0x01
119
120 /* Greybus control request types */
121 #define GB_CONTROL_TYPE_INVALID                 0x00
122 #define GB_CONTROL_TYPE_PROTOCOL_VERSION        0x01
123 #define GB_CONTROL_TYPE_PROBE_AP                0x02
124 #define GB_CONTROL_TYPE_GET_MANIFEST_SIZE       0x03
125 #define GB_CONTROL_TYPE_GET_MANIFEST            0x04
126 #define GB_CONTROL_TYPE_CONNECTED               0x05
127 #define GB_CONTROL_TYPE_DISCONNECTED            0x06
128
129 /* Control protocol manifest get size request has no payload*/
130 struct gb_control_get_manifest_size_response {
131         __le16                  size;
132 };
133
134 /* Control protocol manifest get request has no payload */
135 struct gb_control_get_manifest_response {
136         __u8                    data[0];
137 };
138
139 /* Control protocol [dis]connected request */
140 struct gb_control_connected_request {
141         __le16                  cport_id;
142 };
143
144 struct gb_control_disconnected_request {
145         __le16                  cport_id;
146 };
147 /* Control protocol [dis]connected response has no payload */
148
149 /* I2C */
150
151 /* Version of the Greybus i2c protocol we support */
152 #define GB_I2C_VERSION_MAJOR            0x00
153 #define GB_I2C_VERSION_MINOR            0x01
154
155 /* Greybus i2c request types */
156 #define GB_I2C_TYPE_INVALID             0x00
157 #define GB_I2C_TYPE_PROTOCOL_VERSION    0x01
158 #define GB_I2C_TYPE_FUNCTIONALITY       0x02
159 #define GB_I2C_TYPE_TIMEOUT             0x03
160 #define GB_I2C_TYPE_RETRIES             0x04
161 #define GB_I2C_TYPE_TRANSFER            0x05
162
163 #define GB_I2C_RETRIES_DEFAULT          3
164 #define GB_I2C_TIMEOUT_DEFAULT          1000    /* milliseconds */
165
166 /* functionality request has no payload */
167 struct gb_i2c_functionality_response {
168         __le32  functionality;
169 };
170
171 struct gb_i2c_timeout_request {
172         __le16  msec;
173 };
174 /* timeout response has no payload */
175
176 struct gb_i2c_retries_request {
177         __u8    retries;
178 };
179 /* retries response has no payload */
180
181 /*
182  * Outgoing data immediately follows the op count and ops array.
183  * The data for each write (master -> slave) op in the array is sent
184  * in order, with no (e.g. pad) bytes separating them.
185  *
186  * Short reads cause the entire transfer request to fail So response
187  * payload consists only of bytes read, and the number of bytes is
188  * exactly what was specified in the corresponding op.  Like
189  * outgoing data, the incoming data is in order and contiguous.
190  */
191 struct gb_i2c_transfer_op {
192         __le16  addr;
193         __le16  flags;
194         __le16  size;
195 };
196
197 struct gb_i2c_transfer_request {
198         __le16                          op_count;
199         struct gb_i2c_transfer_op       ops[0];         /* op_count of these */
200 };
201 struct gb_i2c_transfer_response {
202         __u8                            data[0];        /* inbound data */
203 };
204
205
206 /* GPIO */
207
208 /* Version of the Greybus GPIO protocol we support */
209 #define GB_GPIO_VERSION_MAJOR           0x00
210 #define GB_GPIO_VERSION_MINOR           0x01
211
212 /* Greybus GPIO request types */
213 #define GB_GPIO_TYPE_INVALID            0x00
214 #define GB_GPIO_TYPE_PROTOCOL_VERSION   0x01
215 #define GB_GPIO_TYPE_LINE_COUNT         0x02
216 #define GB_GPIO_TYPE_ACTIVATE           0x03
217 #define GB_GPIO_TYPE_DEACTIVATE         0x04
218 #define GB_GPIO_TYPE_GET_DIRECTION      0x05
219 #define GB_GPIO_TYPE_DIRECTION_IN       0x06
220 #define GB_GPIO_TYPE_DIRECTION_OUT      0x07
221 #define GB_GPIO_TYPE_GET_VALUE          0x08
222 #define GB_GPIO_TYPE_SET_VALUE          0x09
223 #define GB_GPIO_TYPE_SET_DEBOUNCE       0x0a
224 #define GB_GPIO_TYPE_IRQ_TYPE           0x0b
225 #define GB_GPIO_TYPE_IRQ_MASK           0x0c
226 #define GB_GPIO_TYPE_IRQ_UNMASK         0x0d
227 #define GB_GPIO_TYPE_IRQ_EVENT          0x0e
228
229 #define GB_GPIO_IRQ_TYPE_NONE           0x00
230 #define GB_GPIO_IRQ_TYPE_EDGE_RISING    0x01
231 #define GB_GPIO_IRQ_TYPE_EDGE_FALLING   0x02
232 #define GB_GPIO_IRQ_TYPE_EDGE_BOTH      0x03
233 #define GB_GPIO_IRQ_TYPE_LEVEL_HIGH     0x04
234 #define GB_GPIO_IRQ_TYPE_LEVEL_LOW      0x08
235
236 /* line count request has no payload */
237 struct gb_gpio_line_count_response {
238         __u8    count;
239 };
240
241 struct gb_gpio_activate_request {
242         __u8    which;
243 };
244 /* activate response has no payload */
245
246 struct gb_gpio_deactivate_request {
247         __u8    which;
248 };
249 /* deactivate response has no payload */
250
251 struct gb_gpio_get_direction_request {
252         __u8    which;
253 };
254 struct gb_gpio_get_direction_response {
255         __u8    direction;
256 };
257
258 struct gb_gpio_direction_in_request {
259         __u8    which;
260 };
261 /* direction in response has no payload */
262
263 struct gb_gpio_direction_out_request {
264         __u8    which;
265         __u8    value;
266 };
267 /* direction out response has no payload */
268
269 struct gb_gpio_get_value_request {
270         __u8    which;
271 };
272 struct gb_gpio_get_value_response {
273         __u8    value;
274 };
275
276 struct gb_gpio_set_value_request {
277         __u8    which;
278         __u8    value;
279 };
280 /* set value response has no payload */
281
282 struct gb_gpio_set_debounce_request {
283         __u8    which;
284         __le16  usec;
285 } __packed;
286 /* debounce response has no payload */
287
288 struct gb_gpio_irq_type_request {
289         __u8    which;
290         __u8    type;
291 };
292 /* irq type response has no payload */
293
294 struct gb_gpio_irq_mask_request {
295         __u8    which;
296 };
297 /* irq mask response has no payload */
298
299 struct gb_gpio_irq_unmask_request {
300         __u8    which;
301 };
302 /* irq unmask response has no payload */
303
304 /* irq event requests originate on another module and are handled on the AP */
305 struct gb_gpio_irq_event_request {
306         __u8    which;
307 };
308 /* irq event has no response */
309
310
311 /* PWM */
312
313 /* Version of the Greybus PWM protocol we support */
314 #define GB_PWM_VERSION_MAJOR            0x00
315 #define GB_PWM_VERSION_MINOR            0x01
316
317 /* Greybus PWM operation types */
318 #define GB_PWM_TYPE_INVALID             0x00
319 #define GB_PWM_TYPE_PROTOCOL_VERSION    0x01
320 #define GB_PWM_TYPE_PWM_COUNT           0x02
321 #define GB_PWM_TYPE_ACTIVATE            0x03
322 #define GB_PWM_TYPE_DEACTIVATE          0x04
323 #define GB_PWM_TYPE_CONFIG              0x05
324 #define GB_PWM_TYPE_POLARITY            0x06
325 #define GB_PWM_TYPE_ENABLE              0x07
326 #define GB_PWM_TYPE_DISABLE             0x08
327
328 /* pwm count request has no payload */
329 struct gb_pwm_count_response {
330         __u8    count;
331 };
332
333 struct gb_pwm_activate_request {
334         __u8    which;
335 };
336
337 struct gb_pwm_deactivate_request {
338         __u8    which;
339 };
340
341 struct gb_pwm_config_request {
342         __u8    which;
343         __le32  duty;
344         __le32  period;
345 } __packed;
346
347 struct gb_pwm_polarity_request {
348         __u8    which;
349         __u8    polarity;
350 };
351
352 struct gb_pwm_enable_request {
353         __u8    which;
354 };
355
356 struct gb_pwm_disable_request {
357         __u8    which;
358 };
359
360 /* I2S */
361
362 #define GB_I2S_MGMT_TYPE_PROTOCOL_VERSION               0x01
363 #define GB_I2S_MGMT_TYPE_GET_SUPPORTED_CONFIGURATIONS   0x02
364 #define GB_I2S_MGMT_TYPE_SET_CONFIGURATION              0x03
365 #define GB_I2S_MGMT_TYPE_SET_SAMPLES_PER_MESSAGE        0x04
366 #define GB_I2S_MGMT_TYPE_GET_PROCESSING_DELAY           0x05
367 #define GB_I2S_MGMT_TYPE_SET_START_DELAY                0x06
368 #define GB_I2S_MGMT_TYPE_ACTIVATE_CPORT                 0x07
369 #define GB_I2S_MGMT_TYPE_DEACTIVATE_CPORT               0x08
370 #define GB_I2S_MGMT_TYPE_REPORT_EVENT                   0x09
371
372 #define GB_I2S_MGMT_BYTE_ORDER_NA                       BIT(0)
373 #define GB_I2S_MGMT_BYTE_ORDER_BE                       BIT(1)
374 #define GB_I2S_MGMT_BYTE_ORDER_LE                       BIT(2)
375
376 #define GB_I2S_MGMT_SPATIAL_LOCATION_FL                 BIT(0)
377 #define GB_I2S_MGMT_SPATIAL_LOCATION_FR                 BIT(1)
378 #define GB_I2S_MGMT_SPATIAL_LOCATION_FC                 BIT(2)
379 #define GB_I2S_MGMT_SPATIAL_LOCATION_LFE                BIT(3)
380 #define GB_I2S_MGMT_SPATIAL_LOCATION_BL                 BIT(4)
381 #define GB_I2S_MGMT_SPATIAL_LOCATION_BR                 BIT(5)
382 #define GB_I2S_MGMT_SPATIAL_LOCATION_FLC                BIT(6)
383 #define GB_I2S_MGMT_SPATIAL_LOCATION_FRC                BIT(7)
384 #define GB_I2S_MGMT_SPATIAL_LOCATION_C                  BIT(8) /* BC in USB */
385 #define GB_I2S_MGMT_SPATIAL_LOCATION_SL                 BIT(9)
386 #define GB_I2S_MGMT_SPATIAL_LOCATION_SR                 BIT(10)
387 #define GB_I2S_MGMT_SPATIAL_LOCATION_TC                 BIT(11)
388 #define GB_I2S_MGMT_SPATIAL_LOCATION_TFL                BIT(12)
389 #define GB_I2S_MGMT_SPATIAL_LOCATION_TFC                BIT(13)
390 #define GB_I2S_MGMT_SPATIAL_LOCATION_TFR                BIT(14)
391 #define GB_I2S_MGMT_SPATIAL_LOCATION_TBL                BIT(15)
392 #define GB_I2S_MGMT_SPATIAL_LOCATION_TBC                BIT(16)
393 #define GB_I2S_MGMT_SPATIAL_LOCATION_TBR                BIT(17)
394 #define GB_I2S_MGMT_SPATIAL_LOCATION_TFLC               BIT(18)
395 #define GB_I2S_MGMT_SPATIAL_LOCATION_TFRC               BIT(19)
396 #define GB_I2S_MGMT_SPATIAL_LOCATION_LLFE               BIT(20)
397 #define GB_I2S_MGMT_SPATIAL_LOCATION_RLFE               BIT(21)
398 #define GB_I2S_MGMT_SPATIAL_LOCATION_TSL                BIT(22)
399 #define GB_I2S_MGMT_SPATIAL_LOCATION_TSR                BIT(23)
400 #define GB_I2S_MGMT_SPATIAL_LOCATION_BC                 BIT(24)
401 #define GB_I2S_MGMT_SPATIAL_LOCATION_BLC                BIT(25)
402 #define GB_I2S_MGMT_SPATIAL_LOCATION_BRC                BIT(26)
403 #define GB_I2S_MGMT_SPATIAL_LOCATION_RD                 BIT(31)
404
405 #define GB_I2S_MGMT_PROTOCOL_PCM                        BIT(0)
406 #define GB_I2S_MGMT_PROTOCOL_I2S                        BIT(1)
407 #define GB_I2S_MGMT_PROTOCOL_LR_STEREO                  BIT(2)
408
409 #define GB_I2S_MGMT_ROLE_MASTER                         BIT(0)
410 #define GB_I2S_MGMT_ROLE_SLAVE                          BIT(1)
411
412 #define GB_I2S_MGMT_POLARITY_NORMAL                     BIT(0)
413 #define GB_I2S_MGMT_POLARITY_REVERSED                   BIT(1)
414
415 #define GB_I2S_MGMT_EDGE_RISING                         BIT(0)
416 #define GB_I2S_MGMT_EDGE_FALLING                        BIT(1)
417
418 #define GB_I2S_MGMT_EVENT_UNSPECIFIED                   0x1
419 #define GB_I2S_MGMT_EVENT_HALT                          0x2
420 #define GB_I2S_MGMT_EVENT_INTERNAL_ERROR                0x3
421 #define GB_I2S_MGMT_EVENT_PROTOCOL_ERROR                0x4
422 #define GB_I2S_MGMT_EVENT_FAILURE                       0x5
423 #define GB_I2S_MGMT_EVENT_OUT_OF_SEQUENCE               0x6
424 #define GB_I2S_MGMT_EVENT_UNDERRUN                      0x7
425 #define GB_I2S_MGMT_EVENT_OVERRUN                       0x8
426 #define GB_I2S_MGMT_EVENT_CLOCKING                      0x9
427 #define GB_I2S_MGMT_EVENT_DATA_LEN                      0xa
428
429 struct gb_i2s_mgmt_configuration {
430         __le32  sample_frequency;
431         __u8    num_channels;
432         __u8    bytes_per_channel;
433         __u8    byte_order;
434         __u8    pad;
435         __le32  spatial_locations;
436         __le32  ll_protocol;
437         __u8    ll_mclk_role;
438         __u8    ll_bclk_role;
439         __u8    ll_wclk_role;
440         __u8    ll_wclk_polarity;
441         __u8    ll_wclk_change_edge;
442         __u8    ll_wclk_tx_edge;
443         __u8    ll_wclk_rx_edge;
444         __u8    ll_data_offset;
445 };
446
447 /* get supported configurations request has no payload */
448 struct gb_i2s_mgmt_get_supported_configurations_response {
449         __u8                                    config_count;
450         __u8                                    pad[3];
451         struct gb_i2s_mgmt_configuration        config[0];
452 };
453
454 struct gb_i2s_mgmt_set_configuration_request {
455         struct gb_i2s_mgmt_configuration        config;
456 };
457 /* set configuration response has no payload */
458
459 struct gb_i2s_mgmt_set_samples_per_message_request {
460         __le16  samples_per_message;
461 };
462 /* set samples per message response has no payload */
463
464 /* get processing request delay has no payload */
465 struct gb_i2s_mgmt_get_processing_delay_response {
466         __le32  microseconds;
467 };
468
469 struct gb_i2s_mgmt_set_start_delay_request {
470         __le32  microseconds;
471 };
472 /* set start delay response has no payload */
473
474 struct gb_i2s_mgmt_activate_cport_request {
475         __le16  cport;
476 };
477 /* activate cport response has no payload */
478
479 struct gb_i2s_mgmt_deactivate_cport_request {
480         __le16  cport;
481 };
482 /* deactivate cport response has no payload */
483
484 struct gb_i2s_mgmt_report_event_request {
485         __u8    event;
486 };
487 /* report event response has no payload */
488
489 #define GB_I2S_DATA_TYPE_PROTOCOL_VERSION               0x01
490 #define GB_I2S_DATA_TYPE_SEND_DATA                      0x02
491
492 struct gb_i2s_send_data_request {
493         __le32  sample_number;
494         __le32  size;
495         __u8    data[0];
496 };
497 /* send data has no response at all */
498
499
500 /* SPI */
501
502 /* Version of the Greybus spi protocol we support */
503 #define GB_SPI_VERSION_MAJOR            0x00
504 #define GB_SPI_VERSION_MINOR            0x01
505
506 /* Should match up with modes in linux/spi/spi.h */
507 #define GB_SPI_MODE_CPHA                0x01            /* clock phase */
508 #define GB_SPI_MODE_CPOL                0x02            /* clock polarity */
509 #define GB_SPI_MODE_MODE_0              (0|0)           /* (original MicroWire) */
510 #define GB_SPI_MODE_MODE_1              (0|GB_SPI_MODE_CPHA)
511 #define GB_SPI_MODE_MODE_2              (GB_SPI_MODE_CPOL|0)
512 #define GB_SPI_MODE_MODE_3              (GB_SPI_MODE_CPOL|GB_SPI_MODE_CPHA)
513 #define GB_SPI_MODE_CS_HIGH             0x04            /* chipselect active high? */
514 #define GB_SPI_MODE_LSB_FIRST           0x08            /* per-word bits-on-wire */
515 #define GB_SPI_MODE_3WIRE               0x10            /* SI/SO signals shared */
516 #define GB_SPI_MODE_LOOP                0x20            /* loopback mode */
517 #define GB_SPI_MODE_NO_CS               0x40            /* 1 dev/bus, no chipselect */
518 #define GB_SPI_MODE_READY               0x80            /* slave pulls low to pause */
519
520 /* Should match up with flags in linux/spi/spi.h */
521 #define GB_SPI_FLAG_HALF_DUPLEX         BIT(0)          /* can't do full duplex */
522 #define GB_SPI_FLAG_NO_RX               BIT(1)          /* can't do buffer read */
523 #define GB_SPI_FLAG_NO_TX               BIT(2)          /* can't do buffer write */
524
525 /* Greybus spi operation types */
526 #define GB_SPI_TYPE_INVALID             0x00
527 #define GB_SPI_TYPE_PROTOCOL_VERSION    0x01
528 #define GB_SPI_TYPE_MODE                0x02
529 #define GB_SPI_TYPE_FLAGS               0x03
530 #define GB_SPI_TYPE_BITS_PER_WORD_MASK  0x04
531 #define GB_SPI_TYPE_NUM_CHIPSELECT      0x05
532 #define GB_SPI_TYPE_TRANSFER            0x06
533
534 /* mode request has no payload */
535 struct gb_spi_mode_response {
536         __le16  mode;
537 };
538
539 /* flags request has no payload */
540 struct gb_spi_flags_response {
541         __le16  flags;
542 };
543
544 /* bits-per-word request has no payload */
545 struct gb_spi_bpw_response {
546         __le32  bits_per_word_mask;
547 };
548
549 /* num-chipselects request has no payload */
550 struct gb_spi_chipselect_response {
551         __le16  num_chipselect;
552 };
553
554 /**
555  * struct gb_spi_transfer - a read/write buffer pair
556  * @speed_hz: Select a speed other than the device default for this transfer. If
557  *      0 the default (from @spi_device) is used.
558  * @len: size of rx and tx buffers (in bytes)
559  * @delay_usecs: microseconds to delay after this transfer before (optionally)
560  *      changing the chipselect status, then starting the next transfer or
561  *      completing this spi_message.
562  * @cs_change: affects chipselect after this transfer completes
563  * @bits_per_word: select a bits_per_word other than the device default for this
564  *      transfer. If 0 the default (from @spi_device) is used.
565  */
566 struct gb_spi_transfer {
567         __le32          speed_hz;
568         __le32          len;
569         __le16          delay_usecs;
570         __u8            cs_change;
571         __u8            bits_per_word;
572 };
573
574 struct gb_spi_transfer_request {
575         __u8                    chip_select;    /* of the spi device */
576         __u8                    mode;           /* of the spi device */
577         __le16                  count;
578         struct gb_spi_transfer  transfers[0];   /* count of these */
579 };
580
581 struct gb_spi_transfer_response {
582         __u8                    data[0];        /* inbound data */
583 };
584
585 /* Version of the Greybus SVC protocol we support */
586 #define GB_SVC_VERSION_MAJOR            0x00
587 #define GB_SVC_VERSION_MINOR            0x01
588
589 /* Greybus SVC request types */
590 #define GB_SVC_TYPE_INVALID             0x00
591 #define GB_SVC_TYPE_PROTOCOL_VERSION    0x01
592 #define GB_SVC_TYPE_SVC_HELLO           0x02
593 #define GB_SVC_TYPE_INTF_DEVICE_ID      0x03
594 #define GB_SVC_TYPE_INTF_HOTPLUG        0x04
595 #define GB_SVC_TYPE_INTF_HOT_UNPLUG     0x05
596 #define GB_SVC_TYPE_INTF_RESET          0x06
597 #define GB_SVC_TYPE_CONN_CREATE         0x07
598 #define GB_SVC_TYPE_CONN_DESTROY        0x08
599 #define GB_SVC_TYPE_ROUTE_CREATE        0x0b
600
601 /* SVC version request/response have same payload as gb_protocol_version_response */
602
603 /* SVC protocol hello request */
604 struct gb_svc_hello_request {
605         __le16                  endo_id;
606         __u8                    interface_id;
607 } __packed;
608 /* hello response has no payload */
609
610 struct gb_svc_intf_device_id_request {
611         __u8    intf_id;
612         __u8    device_id;
613 };
614 /* device id response has no payload */
615
616 struct gb_svc_intf_hotplug_request {
617         __u8    intf_id;
618         struct {
619                 __le32  unipro_mfg_id;
620                 __le32  unipro_prod_id;
621                 __le32  ara_vend_id;
622                 __le32  ara_prod_id;
623         } data;
624 } __packed;
625 /* hotplug response has no payload */
626
627 struct gb_svc_intf_hot_unplug_request {
628         __u8    intf_id;
629 };
630 /* hot unplug response has no payload */
631
632 struct gb_svc_intf_reset_request {
633         __u8    intf_id;
634 };
635 /* interface reset response has no payload */
636
637 struct gb_svc_conn_create_request {
638         __u8    intf1_id;
639         __u16   cport1_id;
640         __u8    intf2_id;
641         __u16   cport2_id;
642         __u8    tc;
643         __u8    flags;
644 } __packed;
645 /* connection create response has no payload */
646
647 struct gb_svc_conn_destroy_request {
648         __u8    intf1_id;
649         __u16   cport1_id;
650         __u8    intf2_id;
651         __u16   cport2_id;
652 } __packed;
653 /* connection destroy response has no payload */
654
655 struct gb_svc_route_create_request {
656         __u8    intf1_id;
657         __u8    dev1_id;
658         __u8    intf2_id;
659         __u8    dev2_id;
660 };
661
662 /* UART */
663
664 /* Version of the Greybus UART protocol we support */
665 #define GB_UART_VERSION_MAJOR           0x00
666 #define GB_UART_VERSION_MINOR           0x01
667
668 /* Greybus UART operation types */
669 #define GB_UART_TYPE_INVALID                    0x00
670 #define GB_UART_TYPE_PROTOCOL_VERSION           0x01
671 #define GB_UART_TYPE_SEND_DATA                  0x02
672 #define GB_UART_TYPE_RECEIVE_DATA               0x03    /* Unsolicited data */
673 #define GB_UART_TYPE_SET_LINE_CODING            0x04
674 #define GB_UART_TYPE_SET_CONTROL_LINE_STATE     0x05
675 #define GB_UART_TYPE_SEND_BREAK                 0x06
676 #define GB_UART_TYPE_SERIAL_STATE               0x07    /* Unsolicited data */
677
678 /* Represents data from AP -> Module */
679 struct gb_uart_send_data_request {
680         __le16  size;
681         __u8    data[0];
682 };
683
684 /* recv-data-request flags */
685 #define GB_UART_RECV_FLAG_FRAMING               0x01    /* Framing error */
686 #define GB_UART_RECV_FLAG_PARITY                0x02    /* Parity error */
687 #define GB_UART_RECV_FLAG_OVERRUN               0x04    /* Overrun error */
688 #define GB_UART_RECV_FLAG_BREAK                 0x08    /* Break */
689
690 /* Represents data from Module -> AP */
691 struct gb_uart_recv_data_request {
692         __le16  size;
693         __u8    flags;
694         __u8    data[0];
695 } __packed;
696
697 struct gb_uart_set_line_coding_request {
698         __le32  rate;
699         __u8    format;
700 #define GB_SERIAL_1_STOP_BITS                   0
701 #define GB_SERIAL_1_5_STOP_BITS                 1
702 #define GB_SERIAL_2_STOP_BITS                   2
703
704         __u8    parity;
705 #define GB_SERIAL_NO_PARITY                     0
706 #define GB_SERIAL_ODD_PARITY                    1
707 #define GB_SERIAL_EVEN_PARITY                   2
708 #define GB_SERIAL_MARK_PARITY                   3
709 #define GB_SERIAL_SPACE_PARITY                  4
710
711         __u8    data_bits;
712 } __packed;
713
714 /* output control lines */
715 #define GB_UART_CTRL_DTR                        0x01
716 #define GB_UART_CTRL_RTS                        0x02
717
718 struct gb_uart_set_control_line_state_request {
719         __u8    control;
720 };
721
722 struct gb_uart_set_break_request {
723         __u8    state;
724 };
725
726 /* input control lines and line errors */
727 #define GB_UART_CTRL_DCD                        0x01
728 #define GB_UART_CTRL_DSR                        0x02
729 #define GB_UART_CTRL_RI                         0x04
730
731 struct gb_uart_serial_state_request {
732         __u8    control;
733 };
734
735 /* Loopback */
736
737 /* Version of the Greybus loopback protocol we support */
738 #define GB_LOOPBACK_VERSION_MAJOR               0x00
739 #define GB_LOOPBACK_VERSION_MINOR               0x01
740
741 /* Greybus loopback request types */
742 #define GB_LOOPBACK_TYPE_INVALID                0x00
743 #define GB_LOOPBACK_TYPE_PROTOCOL_VERSION       0x01
744 #define GB_LOOPBACK_TYPE_PING                   0x02
745 #define GB_LOOPBACK_TYPE_TRANSFER               0x03
746 #define GB_LOOPBACK_TYPE_SINK                   0x04
747
748 struct gb_loopback_transfer_request {
749         __le32  len;
750         __u8    data[0];
751 };
752
753 struct gb_loopback_transfer_response {
754         __u8    data[0];
755 };
756
757 /* SDIO */
758 /* Version of the Greybus sdio protocol we support */
759 #define GB_SDIO_VERSION_MAJOR           0x00
760 #define GB_SDIO_VERSION_MINOR           0x01
761
762 /* Greybus SDIO operation types */
763 #define GB_SDIO_TYPE_INVALID                    0x00
764 #define GB_SDIO_TYPE_PROTOCOL_VERSION           0x01
765 #define GB_SDIO_TYPE_GET_CAPABILITIES           0x02
766 #define GB_SDIO_TYPE_SET_IOS                    0x03
767 #define GB_SDIO_TYPE_COMMAND                    0x04
768 #define GB_SDIO_TYPE_TRANSFER                   0x05
769 #define GB_SDIO_TYPE_EVENT                      0x06
770
771 /* get caps response: request has no payload */
772 struct gb_sdio_get_caps_response {
773         __le32  caps;
774 #define GB_SDIO_CAP_NONREMOVABLE        0x00000001
775 #define GB_SDIO_CAP_4_BIT_DATA          0x00000002
776 #define GB_SDIO_CAP_8_BIT_DATA          0x00000004
777 #define GB_SDIO_CAP_MMC_HS              0x00000008
778 #define GB_SDIO_CAP_SD_HS               0x00000010
779 #define GB_SDIO_CAP_ERASE               0x00000020
780 #define GB_SDIO_CAP_1_2V_DDR            0x00000040
781 #define GB_SDIO_CAP_1_8V_DDR            0x00000080
782 #define GB_SDIO_CAP_POWER_OFF_CARD      0x00000100
783 #define GB_SDIO_CAP_UHS_SDR12           0x00000200
784 #define GB_SDIO_CAP_UHS_SDR25           0x00000400
785 #define GB_SDIO_CAP_UHS_SDR50           0x00000800
786 #define GB_SDIO_CAP_UHS_SDR104          0x00001000
787 #define GB_SDIO_CAP_UHS_DDR50           0x00002000
788 #define GB_SDIO_CAP_DRIVER_TYPE_A       0x00004000
789 #define GB_SDIO_CAP_DRIVER_TYPE_C       0x00008000
790 #define GB_SDIO_CAP_DRIVER_TYPE_D       0x00010000
791 #define GB_SDIO_CAP_HS200_1_2V          0x00020000
792 #define GB_SDIO_CAP_HS200_1_8V          0x00040000
793 #define GB_SDIO_CAP_HS400_1_2V          0x00080000
794 #define GB_SDIO_CAP_HS400_1_8V          0x00100000
795
796         /* see possible values below at vdd */
797         __le32 ocr;
798         __le16 max_blk_count;
799         __le16 max_blk_size;
800 };
801
802 /* set ios request: response has no payload */
803 struct gb_sdio_set_ios_request {
804         __le32  clock;
805         __le32  vdd;
806 #define GB_SDIO_VDD_165_195     0x00000001
807 #define GB_SDIO_VDD_20_21       0x00000002
808 #define GB_SDIO_VDD_21_22       0x00000004
809 #define GB_SDIO_VDD_22_23       0x00000008
810 #define GB_SDIO_VDD_23_24       0x00000010
811 #define GB_SDIO_VDD_24_25       0x00000020
812 #define GB_SDIO_VDD_25_26       0x00000040
813 #define GB_SDIO_VDD_26_27       0x00000080
814 #define GB_SDIO_VDD_27_28       0x00000100
815 #define GB_SDIO_VDD_28_29       0x00000200
816 #define GB_SDIO_VDD_29_30       0x00000400
817 #define GB_SDIO_VDD_30_31       0x00000800
818 #define GB_SDIO_VDD_31_32       0x00001000
819 #define GB_SDIO_VDD_32_33       0x00002000
820 #define GB_SDIO_VDD_33_34       0x00004000
821 #define GB_SDIO_VDD_34_35       0x00008000
822 #define GB_SDIO_VDD_35_36       0x00010000
823
824         __u8    bus_mode;
825 #define GB_SDIO_BUSMODE_OPENDRAIN       0x00
826 #define GB_SDIO_BUSMODE_PUSHPULL        0x01
827
828         __u8    power_mode;
829 #define GB_SDIO_POWER_OFF       0x00
830 #define GB_SDIO_POWER_UP        0x01
831 #define GB_SDIO_POWER_ON        0x02
832 #define GB_SDIO_POWER_UNDEFINED 0x03
833
834         __u8    bus_width;
835 #define GB_SDIO_BUS_WIDTH_1     0x00
836 #define GB_SDIO_BUS_WIDTH_4     0x02
837 #define GB_SDIO_BUS_WIDTH_8     0x03
838
839         __u8    timing;
840 #define GB_SDIO_TIMING_LEGACY           0x00
841 #define GB_SDIO_TIMING_MMC_HS           0x01
842 #define GB_SDIO_TIMING_SD_HS            0x02
843 #define GB_SDIO_TIMING_UHS_SDR12        0x03
844 #define GB_SDIO_TIMING_UHS_SDR25        0x04
845 #define GB_SDIO_TIMING_UHS_SDR50        0x05
846 #define GB_SDIO_TIMING_UHS_SDR104       0x06
847 #define GB_SDIO_TIMING_UHS_DDR50        0x07
848 #define GB_SDIO_TIMING_MMC_DDR52        0x08
849 #define GB_SDIO_TIMING_MMC_HS200        0x09
850 #define GB_SDIO_TIMING_MMC_HS400        0x0A
851
852         __u8    signal_voltage;
853 #define GB_SDIO_SIGNAL_VOLTAGE_330      0x00
854 #define GB_SDIO_SIGNAL_VOLTAGE_180      0x01
855 #define GB_SDIO_SIGNAL_VOLTAGE_120      0x02
856
857         __u8    drv_type;
858 #define GB_SDIO_SET_DRIVER_TYPE_B       0x00
859 #define GB_SDIO_SET_DRIVER_TYPE_A       0x01
860 #define GB_SDIO_SET_DRIVER_TYPE_C       0x02
861 #define GB_SDIO_SET_DRIVER_TYPE_D       0x03
862 } __packed;
863
864 /* command request */
865 struct gb_sdio_command_request {
866         __u8    cmd;
867         __u8    cmd_flags;
868 #define GB_SDIO_RSP_NONE                0x00
869 #define GB_SDIO_RSP_PRESENT             0x01
870 #define GB_SDIO_RSP_136                 0x02
871 #define GB_SDIO_RSP_CRC                 0x04
872 #define GB_SDIO_RSP_BUSY                0x08
873 #define GB_SDIO_RSP_OPCODE              0x10
874
875         __u8    cmd_type;
876 #define GB_SDIO_CMD_AC          0x00
877 #define GB_SDIO_CMD_ADTC        0x01
878 #define GB_SDIO_CMD_BCR         0x02
879 #define GB_SDIO_CMD_BC          0x03
880
881         __le32  cmd_arg;
882 } __packed;
883
884 struct gb_sdio_command_response {
885         __le32  resp[4];
886 };
887
888 /* transfer request */
889 struct gb_sdio_transfer_request {
890         __u8    data_flags;
891 #define GB_SDIO_DATA_WRITE      0x01
892 #define GB_SDIO_DATA_READ       0x02
893 #define GB_SDIO_DATA_STREAM     0x04
894
895         __le16  data_blocks;
896         __le16  data_blksz;
897         __u8    data[0];
898 } __packed;
899
900 struct gb_sdio_transfer_response {
901         __le16  data_blocks;
902         __le16  data_blksz;
903         __u8    data[0];
904 };
905
906 /* event request: generated by module and is defined as unidirectional */
907 struct gb_sdio_event_request {
908         __u8    event;
909 #define GB_SDIO_CARD_INSERTED   0x01
910 #define GB_SDIO_CARD_REMOVED    0x02
911 #define GB_SDIO_WP              0x04
912 };
913
914 #endif /* __GREYBUS_PROTOCOLS_H */
915