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