]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/greybus/greybus_protocols.h
greybus: hid: Move request/response structure/definitions to greybus_protocols.h
[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
150 /* Firmware Protocol */
151
152 /* Version of the Greybus firmware protocol we support */
153 #define GB_FIRMWARE_VERSION_MAJOR               0x00
154 #define GB_FIRMWARE_VERSION_MINOR               0x01
155
156 /* Greybus firmware request types */
157 #define GB_FIRMWARE_TYPE_INVALID                0x00
158 #define GB_FIRMWARE_TYPE_PROTOCOL_VERSION       0x01
159 #define GB_FIRMWARE_TYPE_FIRMWARE_SIZE          0x02
160 #define GB_FIRMWARE_TYPE_GET_FIRMWARE           0x03
161 #define GB_FIRMWARE_TYPE_READY_TO_BOOT          0x04
162
163 /* Greybus firmware boot stages */
164 #define GB_FIRMWARE_BOOT_STAGE_ONE              0x01 /* Reserved for the boot ROM */
165 #define GB_FIRMWARE_BOOT_STAGE_TWO              0x02 /* Firmware package to be loaded by the boot ROM */
166 #define GB_FIRMWARE_BOOT_STAGE_THREE            0x03 /* Module personality package loaded by Stage 2 firmware */
167
168 /* Greybus firmware ready to boot status */
169 #define GB_FIRMWARE_BOOT_STATUS_INVALID         0x00 /* Firmware blob could not be validated */
170 #define GB_FIRMWARE_BOOT_STATUS_INSECURE        0x01 /* Firmware blob is valid but insecure */
171 #define GB_FIRMWARE_BOOT_STATUS_SECURE          0x02 /* Firmware blob is valid and secure */
172
173 /* Max firmware data fetch size in bytes */
174 #define GB_FIRMWARE_FETCH_MAX                   2000
175
176 /* Firmware protocol firmware size request/response */
177 struct gb_firmware_size_request {
178         __u8                    stage;
179 };
180
181 struct gb_firmware_size_response {
182         __le32                  size;
183 };
184
185 /* Firmware protocol get firmware request/response */
186 struct gb_firmware_get_firmware_request {
187         __le32                  offset;
188         __le32                  size;
189 };
190
191 struct gb_firmware_get_firmware_response {
192         __u8                    data[0];
193 };
194
195 /* Firmware protocol Ready to boot request */
196 struct gb_firmware_ready_to_boot_request {
197         __u8                    stage;
198         __u8                    status;
199 };
200 /* Firmware protocol Ready to boot response has no payload */
201
202
203 /* BATTERY */
204
205 /* Version of the Greybus battery protocol we support */
206 #define GB_BATTERY_VERSION_MAJOR                0x00
207 #define GB_BATTERY_VERSION_MINOR                0x01
208
209 /* Greybus battery request types */
210 #define GB_BATTERY_TYPE_TECHNOLOGY              0x02
211 #define GB_BATTERY_TYPE_STATUS                  0x03
212 #define GB_BATTERY_TYPE_MAX_VOLTAGE             0x04
213 #define GB_BATTERY_TYPE_PERCENT_CAPACITY        0x05
214 #define GB_BATTERY_TYPE_TEMPERATURE             0x06
215 #define GB_BATTERY_TYPE_VOLTAGE                 0x07
216 #define GB_BATTERY_TYPE_CURRENT                 0x08
217 #define GB_BATTERY_TYPE_CAPACITY                0x09    // TODO - POWER_SUPPLY_PROP_CURRENT_MAX
218 #define GB_BATTERY_TYPE_SHUTDOWN_TEMP           0x0a    // TODO - POWER_SUPPLY_PROP_TEMP_ALERT_MAX
219
220 /* Should match up with battery types in linux/power_supply.h */
221 #define GB_BATTERY_TECH_UNKNOWN                 0x0000
222 #define GB_BATTERY_TECH_NiMH                    0x0001
223 #define GB_BATTERY_TECH_LION                    0x0002
224 #define GB_BATTERY_TECH_LIPO                    0x0003
225 #define GB_BATTERY_TECH_LiFe                    0x0004
226 #define GB_BATTERY_TECH_NiCd                    0x0005
227 #define GB_BATTERY_TECH_LiMn                    0x0006
228
229 struct gb_battery_technology_response {
230         __le32  technology;
231 };
232
233 /* Should match up with battery status in linux/power_supply.h */
234 #define GB_BATTERY_STATUS_UNKNOWN               0x0000
235 #define GB_BATTERY_STATUS_CHARGING              0x0001
236 #define GB_BATTERY_STATUS_DISCHARGING           0x0002
237 #define GB_BATTERY_STATUS_NOT_CHARGING          0x0003
238 #define GB_BATTERY_STATUS_FULL                  0x0004
239
240 struct gb_battery_status_response {
241         __le16  battery_status;
242 };
243
244 struct gb_battery_max_voltage_response {
245         __le32  max_voltage;
246 };
247
248 struct gb_battery_capacity_response {
249         __le32  capacity;
250 };
251
252 struct gb_battery_temperature_response {
253         __le32  temperature;
254 };
255
256 struct gb_battery_voltage_response {
257         __le32  voltage;
258 };
259
260
261 /* HID */
262
263 /* Version of the Greybus hid protocol we support */
264 #define GB_HID_VERSION_MAJOR            0x00
265 #define GB_HID_VERSION_MINOR            0x01
266
267 /* Greybus HID operation types */
268 #define GB_HID_TYPE_INVALID             0x00
269 #define GB_HID_TYPE_PROTOCOL_VERSION    0x01
270 #define GB_HID_TYPE_GET_DESC            0x02
271 #define GB_HID_TYPE_GET_REPORT_DESC     0x03
272 #define GB_HID_TYPE_PWR_ON              0x04
273 #define GB_HID_TYPE_PWR_OFF             0x05
274 #define GB_HID_TYPE_GET_REPORT          0x06
275 #define GB_HID_TYPE_SET_REPORT          0x07
276 #define GB_HID_TYPE_IRQ_EVENT           0x08
277
278 /* Report type */
279 #define GB_HID_INPUT_REPORT             0
280 #define GB_HID_OUTPUT_REPORT            1
281 #define GB_HID_FEATURE_REPORT           2
282
283 /* Different request/response structures */
284 /* HID get descriptor response */
285 struct gb_hid_desc_response {
286         __u8                            bLength;
287         __le16                          wReportDescLength;
288         __le16                          bcdHID;
289         __le16                          wProductID;
290         __le16                          wVendorID;
291         __u8                            bCountryCode;
292 } __packed;
293
294 /* HID get report request/response */
295 struct gb_hid_get_report_request {
296         __u8                            report_type;
297         __u8                            report_id;
298 };
299
300 /* HID set report request */
301 struct gb_hid_set_report_request {
302         __u8                            report_type;
303         __u8                            report_id;
304         __u8                            report[0];
305 };
306
307 /* HID input report request, via interrupt pipe */
308 struct gb_hid_input_report_request {
309         __u8                            report[0];
310 };
311
312
313 /* I2C */
314
315 /* Version of the Greybus i2c protocol we support */
316 #define GB_I2C_VERSION_MAJOR            0x00
317 #define GB_I2C_VERSION_MINOR            0x01
318
319 /* Greybus i2c request types */
320 #define GB_I2C_TYPE_INVALID             0x00
321 #define GB_I2C_TYPE_PROTOCOL_VERSION    0x01
322 #define GB_I2C_TYPE_FUNCTIONALITY       0x02
323 #define GB_I2C_TYPE_TIMEOUT             0x03
324 #define GB_I2C_TYPE_RETRIES             0x04
325 #define GB_I2C_TYPE_TRANSFER            0x05
326
327 #define GB_I2C_RETRIES_DEFAULT          3
328 #define GB_I2C_TIMEOUT_DEFAULT          1000    /* milliseconds */
329
330 /* functionality request has no payload */
331 struct gb_i2c_functionality_response {
332         __le32  functionality;
333 };
334
335 struct gb_i2c_timeout_request {
336         __le16  msec;
337 };
338 /* timeout response has no payload */
339
340 struct gb_i2c_retries_request {
341         __u8    retries;
342 };
343 /* retries response has no payload */
344
345 /*
346  * Outgoing data immediately follows the op count and ops array.
347  * The data for each write (master -> slave) op in the array is sent
348  * in order, with no (e.g. pad) bytes separating them.
349  *
350  * Short reads cause the entire transfer request to fail So response
351  * payload consists only of bytes read, and the number of bytes is
352  * exactly what was specified in the corresponding op.  Like
353  * outgoing data, the incoming data is in order and contiguous.
354  */
355 struct gb_i2c_transfer_op {
356         __le16  addr;
357         __le16  flags;
358         __le16  size;
359 };
360
361 struct gb_i2c_transfer_request {
362         __le16                          op_count;
363         struct gb_i2c_transfer_op       ops[0];         /* op_count of these */
364 };
365 struct gb_i2c_transfer_response {
366         __u8                            data[0];        /* inbound data */
367 };
368
369
370 /* GPIO */
371
372 /* Version of the Greybus GPIO protocol we support */
373 #define GB_GPIO_VERSION_MAJOR           0x00
374 #define GB_GPIO_VERSION_MINOR           0x01
375
376 /* Greybus GPIO request types */
377 #define GB_GPIO_TYPE_INVALID            0x00
378 #define GB_GPIO_TYPE_PROTOCOL_VERSION   0x01
379 #define GB_GPIO_TYPE_LINE_COUNT         0x02
380 #define GB_GPIO_TYPE_ACTIVATE           0x03
381 #define GB_GPIO_TYPE_DEACTIVATE         0x04
382 #define GB_GPIO_TYPE_GET_DIRECTION      0x05
383 #define GB_GPIO_TYPE_DIRECTION_IN       0x06
384 #define GB_GPIO_TYPE_DIRECTION_OUT      0x07
385 #define GB_GPIO_TYPE_GET_VALUE          0x08
386 #define GB_GPIO_TYPE_SET_VALUE          0x09
387 #define GB_GPIO_TYPE_SET_DEBOUNCE       0x0a
388 #define GB_GPIO_TYPE_IRQ_TYPE           0x0b
389 #define GB_GPIO_TYPE_IRQ_MASK           0x0c
390 #define GB_GPIO_TYPE_IRQ_UNMASK         0x0d
391 #define GB_GPIO_TYPE_IRQ_EVENT          0x0e
392
393 #define GB_GPIO_IRQ_TYPE_NONE           0x00
394 #define GB_GPIO_IRQ_TYPE_EDGE_RISING    0x01
395 #define GB_GPIO_IRQ_TYPE_EDGE_FALLING   0x02
396 #define GB_GPIO_IRQ_TYPE_EDGE_BOTH      0x03
397 #define GB_GPIO_IRQ_TYPE_LEVEL_HIGH     0x04
398 #define GB_GPIO_IRQ_TYPE_LEVEL_LOW      0x08
399
400 /* line count request has no payload */
401 struct gb_gpio_line_count_response {
402         __u8    count;
403 };
404
405 struct gb_gpio_activate_request {
406         __u8    which;
407 };
408 /* activate response has no payload */
409
410 struct gb_gpio_deactivate_request {
411         __u8    which;
412 };
413 /* deactivate response has no payload */
414
415 struct gb_gpio_get_direction_request {
416         __u8    which;
417 };
418 struct gb_gpio_get_direction_response {
419         __u8    direction;
420 };
421
422 struct gb_gpio_direction_in_request {
423         __u8    which;
424 };
425 /* direction in response has no payload */
426
427 struct gb_gpio_direction_out_request {
428         __u8    which;
429         __u8    value;
430 };
431 /* direction out response has no payload */
432
433 struct gb_gpio_get_value_request {
434         __u8    which;
435 };
436 struct gb_gpio_get_value_response {
437         __u8    value;
438 };
439
440 struct gb_gpio_set_value_request {
441         __u8    which;
442         __u8    value;
443 };
444 /* set value response has no payload */
445
446 struct gb_gpio_set_debounce_request {
447         __u8    which;
448         __le16  usec;
449 } __packed;
450 /* debounce response has no payload */
451
452 struct gb_gpio_irq_type_request {
453         __u8    which;
454         __u8    type;
455 };
456 /* irq type response has no payload */
457
458 struct gb_gpio_irq_mask_request {
459         __u8    which;
460 };
461 /* irq mask response has no payload */
462
463 struct gb_gpio_irq_unmask_request {
464         __u8    which;
465 };
466 /* irq unmask response has no payload */
467
468 /* irq event requests originate on another module and are handled on the AP */
469 struct gb_gpio_irq_event_request {
470         __u8    which;
471 };
472 /* irq event has no response */
473
474
475 /* PWM */
476
477 /* Version of the Greybus PWM protocol we support */
478 #define GB_PWM_VERSION_MAJOR            0x00
479 #define GB_PWM_VERSION_MINOR            0x01
480
481 /* Greybus PWM operation types */
482 #define GB_PWM_TYPE_INVALID             0x00
483 #define GB_PWM_TYPE_PROTOCOL_VERSION    0x01
484 #define GB_PWM_TYPE_PWM_COUNT           0x02
485 #define GB_PWM_TYPE_ACTIVATE            0x03
486 #define GB_PWM_TYPE_DEACTIVATE          0x04
487 #define GB_PWM_TYPE_CONFIG              0x05
488 #define GB_PWM_TYPE_POLARITY            0x06
489 #define GB_PWM_TYPE_ENABLE              0x07
490 #define GB_PWM_TYPE_DISABLE             0x08
491
492 /* pwm count request has no payload */
493 struct gb_pwm_count_response {
494         __u8    count;
495 };
496
497 struct gb_pwm_activate_request {
498         __u8    which;
499 };
500
501 struct gb_pwm_deactivate_request {
502         __u8    which;
503 };
504
505 struct gb_pwm_config_request {
506         __u8    which;
507         __le32  duty;
508         __le32  period;
509 } __packed;
510
511 struct gb_pwm_polarity_request {
512         __u8    which;
513         __u8    polarity;
514 };
515
516 struct gb_pwm_enable_request {
517         __u8    which;
518 };
519
520 struct gb_pwm_disable_request {
521         __u8    which;
522 };
523
524 /* I2S */
525
526 #define GB_I2S_MGMT_TYPE_PROTOCOL_VERSION               0x01
527 #define GB_I2S_MGMT_TYPE_GET_SUPPORTED_CONFIGURATIONS   0x02
528 #define GB_I2S_MGMT_TYPE_SET_CONFIGURATION              0x03
529 #define GB_I2S_MGMT_TYPE_SET_SAMPLES_PER_MESSAGE        0x04
530 #define GB_I2S_MGMT_TYPE_GET_PROCESSING_DELAY           0x05
531 #define GB_I2S_MGMT_TYPE_SET_START_DELAY                0x06
532 #define GB_I2S_MGMT_TYPE_ACTIVATE_CPORT                 0x07
533 #define GB_I2S_MGMT_TYPE_DEACTIVATE_CPORT               0x08
534 #define GB_I2S_MGMT_TYPE_REPORT_EVENT                   0x09
535
536 #define GB_I2S_MGMT_BYTE_ORDER_NA                       BIT(0)
537 #define GB_I2S_MGMT_BYTE_ORDER_BE                       BIT(1)
538 #define GB_I2S_MGMT_BYTE_ORDER_LE                       BIT(2)
539
540 #define GB_I2S_MGMT_SPATIAL_LOCATION_FL                 BIT(0)
541 #define GB_I2S_MGMT_SPATIAL_LOCATION_FR                 BIT(1)
542 #define GB_I2S_MGMT_SPATIAL_LOCATION_FC                 BIT(2)
543 #define GB_I2S_MGMT_SPATIAL_LOCATION_LFE                BIT(3)
544 #define GB_I2S_MGMT_SPATIAL_LOCATION_BL                 BIT(4)
545 #define GB_I2S_MGMT_SPATIAL_LOCATION_BR                 BIT(5)
546 #define GB_I2S_MGMT_SPATIAL_LOCATION_FLC                BIT(6)
547 #define GB_I2S_MGMT_SPATIAL_LOCATION_FRC                BIT(7)
548 #define GB_I2S_MGMT_SPATIAL_LOCATION_C                  BIT(8) /* BC in USB */
549 #define GB_I2S_MGMT_SPATIAL_LOCATION_SL                 BIT(9)
550 #define GB_I2S_MGMT_SPATIAL_LOCATION_SR                 BIT(10)
551 #define GB_I2S_MGMT_SPATIAL_LOCATION_TC                 BIT(11)
552 #define GB_I2S_MGMT_SPATIAL_LOCATION_TFL                BIT(12)
553 #define GB_I2S_MGMT_SPATIAL_LOCATION_TFC                BIT(13)
554 #define GB_I2S_MGMT_SPATIAL_LOCATION_TFR                BIT(14)
555 #define GB_I2S_MGMT_SPATIAL_LOCATION_TBL                BIT(15)
556 #define GB_I2S_MGMT_SPATIAL_LOCATION_TBC                BIT(16)
557 #define GB_I2S_MGMT_SPATIAL_LOCATION_TBR                BIT(17)
558 #define GB_I2S_MGMT_SPATIAL_LOCATION_TFLC               BIT(18)
559 #define GB_I2S_MGMT_SPATIAL_LOCATION_TFRC               BIT(19)
560 #define GB_I2S_MGMT_SPATIAL_LOCATION_LLFE               BIT(20)
561 #define GB_I2S_MGMT_SPATIAL_LOCATION_RLFE               BIT(21)
562 #define GB_I2S_MGMT_SPATIAL_LOCATION_TSL                BIT(22)
563 #define GB_I2S_MGMT_SPATIAL_LOCATION_TSR                BIT(23)
564 #define GB_I2S_MGMT_SPATIAL_LOCATION_BC                 BIT(24)
565 #define GB_I2S_MGMT_SPATIAL_LOCATION_BLC                BIT(25)
566 #define GB_I2S_MGMT_SPATIAL_LOCATION_BRC                BIT(26)
567 #define GB_I2S_MGMT_SPATIAL_LOCATION_RD                 BIT(31)
568
569 #define GB_I2S_MGMT_PROTOCOL_PCM                        BIT(0)
570 #define GB_I2S_MGMT_PROTOCOL_I2S                        BIT(1)
571 #define GB_I2S_MGMT_PROTOCOL_LR_STEREO                  BIT(2)
572
573 #define GB_I2S_MGMT_ROLE_MASTER                         BIT(0)
574 #define GB_I2S_MGMT_ROLE_SLAVE                          BIT(1)
575
576 #define GB_I2S_MGMT_POLARITY_NORMAL                     BIT(0)
577 #define GB_I2S_MGMT_POLARITY_REVERSED                   BIT(1)
578
579 #define GB_I2S_MGMT_EDGE_RISING                         BIT(0)
580 #define GB_I2S_MGMT_EDGE_FALLING                        BIT(1)
581
582 #define GB_I2S_MGMT_EVENT_UNSPECIFIED                   0x1
583 #define GB_I2S_MGMT_EVENT_HALT                          0x2
584 #define GB_I2S_MGMT_EVENT_INTERNAL_ERROR                0x3
585 #define GB_I2S_MGMT_EVENT_PROTOCOL_ERROR                0x4
586 #define GB_I2S_MGMT_EVENT_FAILURE                       0x5
587 #define GB_I2S_MGMT_EVENT_OUT_OF_SEQUENCE               0x6
588 #define GB_I2S_MGMT_EVENT_UNDERRUN                      0x7
589 #define GB_I2S_MGMT_EVENT_OVERRUN                       0x8
590 #define GB_I2S_MGMT_EVENT_CLOCKING                      0x9
591 #define GB_I2S_MGMT_EVENT_DATA_LEN                      0xa
592
593 struct gb_i2s_mgmt_configuration {
594         __le32  sample_frequency;
595         __u8    num_channels;
596         __u8    bytes_per_channel;
597         __u8    byte_order;
598         __u8    pad;
599         __le32  spatial_locations;
600         __le32  ll_protocol;
601         __u8    ll_mclk_role;
602         __u8    ll_bclk_role;
603         __u8    ll_wclk_role;
604         __u8    ll_wclk_polarity;
605         __u8    ll_wclk_change_edge;
606         __u8    ll_wclk_tx_edge;
607         __u8    ll_wclk_rx_edge;
608         __u8    ll_data_offset;
609 };
610
611 /* get supported configurations request has no payload */
612 struct gb_i2s_mgmt_get_supported_configurations_response {
613         __u8                                    config_count;
614         __u8                                    pad[3];
615         struct gb_i2s_mgmt_configuration        config[0];
616 };
617
618 struct gb_i2s_mgmt_set_configuration_request {
619         struct gb_i2s_mgmt_configuration        config;
620 };
621 /* set configuration response has no payload */
622
623 struct gb_i2s_mgmt_set_samples_per_message_request {
624         __le16  samples_per_message;
625 };
626 /* set samples per message response has no payload */
627
628 /* get processing request delay has no payload */
629 struct gb_i2s_mgmt_get_processing_delay_response {
630         __le32  microseconds;
631 };
632
633 struct gb_i2s_mgmt_set_start_delay_request {
634         __le32  microseconds;
635 };
636 /* set start delay response has no payload */
637
638 struct gb_i2s_mgmt_activate_cport_request {
639         __le16  cport;
640 };
641 /* activate cport response has no payload */
642
643 struct gb_i2s_mgmt_deactivate_cport_request {
644         __le16  cport;
645 };
646 /* deactivate cport response has no payload */
647
648 struct gb_i2s_mgmt_report_event_request {
649         __u8    event;
650 };
651 /* report event response has no payload */
652
653 #define GB_I2S_DATA_TYPE_PROTOCOL_VERSION               0x01
654 #define GB_I2S_DATA_TYPE_SEND_DATA                      0x02
655
656 struct gb_i2s_send_data_request {
657         __le32  sample_number;
658         __le32  size;
659         __u8    data[0];
660 };
661 /* send data has no response at all */
662
663
664 /* SPI */
665
666 /* Version of the Greybus spi protocol we support */
667 #define GB_SPI_VERSION_MAJOR            0x00
668 #define GB_SPI_VERSION_MINOR            0x01
669
670 /* Should match up with modes in linux/spi/spi.h */
671 #define GB_SPI_MODE_CPHA                0x01            /* clock phase */
672 #define GB_SPI_MODE_CPOL                0x02            /* clock polarity */
673 #define GB_SPI_MODE_MODE_0              (0|0)           /* (original MicroWire) */
674 #define GB_SPI_MODE_MODE_1              (0|GB_SPI_MODE_CPHA)
675 #define GB_SPI_MODE_MODE_2              (GB_SPI_MODE_CPOL|0)
676 #define GB_SPI_MODE_MODE_3              (GB_SPI_MODE_CPOL|GB_SPI_MODE_CPHA)
677 #define GB_SPI_MODE_CS_HIGH             0x04            /* chipselect active high? */
678 #define GB_SPI_MODE_LSB_FIRST           0x08            /* per-word bits-on-wire */
679 #define GB_SPI_MODE_3WIRE               0x10            /* SI/SO signals shared */
680 #define GB_SPI_MODE_LOOP                0x20            /* loopback mode */
681 #define GB_SPI_MODE_NO_CS               0x40            /* 1 dev/bus, no chipselect */
682 #define GB_SPI_MODE_READY               0x80            /* slave pulls low to pause */
683
684 /* Should match up with flags in linux/spi/spi.h */
685 #define GB_SPI_FLAG_HALF_DUPLEX         BIT(0)          /* can't do full duplex */
686 #define GB_SPI_FLAG_NO_RX               BIT(1)          /* can't do buffer read */
687 #define GB_SPI_FLAG_NO_TX               BIT(2)          /* can't do buffer write */
688
689 /* Greybus spi operation types */
690 #define GB_SPI_TYPE_INVALID             0x00
691 #define GB_SPI_TYPE_PROTOCOL_VERSION    0x01
692 #define GB_SPI_TYPE_MODE                0x02
693 #define GB_SPI_TYPE_FLAGS               0x03
694 #define GB_SPI_TYPE_BITS_PER_WORD_MASK  0x04
695 #define GB_SPI_TYPE_NUM_CHIPSELECT      0x05
696 #define GB_SPI_TYPE_TRANSFER            0x06
697
698 /* mode request has no payload */
699 struct gb_spi_mode_response {
700         __le16  mode;
701 };
702
703 /* flags request has no payload */
704 struct gb_spi_flags_response {
705         __le16  flags;
706 };
707
708 /* bits-per-word request has no payload */
709 struct gb_spi_bpw_response {
710         __le32  bits_per_word_mask;
711 };
712
713 /* num-chipselects request has no payload */
714 struct gb_spi_chipselect_response {
715         __le16  num_chipselect;
716 };
717
718 /**
719  * struct gb_spi_transfer - a read/write buffer pair
720  * @speed_hz: Select a speed other than the device default for this transfer. If
721  *      0 the default (from @spi_device) is used.
722  * @len: size of rx and tx buffers (in bytes)
723  * @delay_usecs: microseconds to delay after this transfer before (optionally)
724  *      changing the chipselect status, then starting the next transfer or
725  *      completing this spi_message.
726  * @cs_change: affects chipselect after this transfer completes
727  * @bits_per_word: select a bits_per_word other than the device default for this
728  *      transfer. If 0 the default (from @spi_device) is used.
729  */
730 struct gb_spi_transfer {
731         __le32          speed_hz;
732         __le32          len;
733         __le16          delay_usecs;
734         __u8            cs_change;
735         __u8            bits_per_word;
736 };
737
738 struct gb_spi_transfer_request {
739         __u8                    chip_select;    /* of the spi device */
740         __u8                    mode;           /* of the spi device */
741         __le16                  count;
742         struct gb_spi_transfer  transfers[0];   /* count of these */
743 };
744
745 struct gb_spi_transfer_response {
746         __u8                    data[0];        /* inbound data */
747 };
748
749 /* Version of the Greybus SVC protocol we support */
750 #define GB_SVC_VERSION_MAJOR            0x00
751 #define GB_SVC_VERSION_MINOR            0x01
752
753 /* Greybus SVC request types */
754 #define GB_SVC_TYPE_INVALID             0x00
755 #define GB_SVC_TYPE_PROTOCOL_VERSION    0x01
756 #define GB_SVC_TYPE_SVC_HELLO           0x02
757 #define GB_SVC_TYPE_INTF_DEVICE_ID      0x03
758 #define GB_SVC_TYPE_INTF_HOTPLUG        0x04
759 #define GB_SVC_TYPE_INTF_HOT_UNPLUG     0x05
760 #define GB_SVC_TYPE_INTF_RESET          0x06
761 #define GB_SVC_TYPE_CONN_CREATE         0x07
762 #define GB_SVC_TYPE_CONN_DESTROY        0x08
763 #define GB_SVC_TYPE_ROUTE_CREATE        0x0b
764
765 /* SVC version request/response have same payload as gb_protocol_version_response */
766
767 /* SVC protocol hello request */
768 struct gb_svc_hello_request {
769         __le16                  endo_id;
770         __u8                    interface_id;
771 } __packed;
772 /* hello response has no payload */
773
774 struct gb_svc_intf_device_id_request {
775         __u8    intf_id;
776         __u8    device_id;
777 };
778 /* device id response has no payload */
779
780 struct gb_svc_intf_hotplug_request {
781         __u8    intf_id;
782         struct {
783                 __le32  unipro_mfg_id;
784                 __le32  unipro_prod_id;
785                 __le32  ara_vend_id;
786                 __le32  ara_prod_id;
787         } data;
788 } __packed;
789 /* hotplug response has no payload */
790
791 struct gb_svc_intf_hot_unplug_request {
792         __u8    intf_id;
793 };
794 /* hot unplug response has no payload */
795
796 struct gb_svc_intf_reset_request {
797         __u8    intf_id;
798 };
799 /* interface reset response has no payload */
800
801 struct gb_svc_conn_create_request {
802         __u8    intf1_id;
803         __u16   cport1_id;
804         __u8    intf2_id;
805         __u16   cport2_id;
806         __u8    tc;
807         __u8    flags;
808 } __packed;
809 /* connection create response has no payload */
810
811 struct gb_svc_conn_destroy_request {
812         __u8    intf1_id;
813         __u16   cport1_id;
814         __u8    intf2_id;
815         __u16   cport2_id;
816 } __packed;
817 /* connection destroy response has no payload */
818
819 struct gb_svc_route_create_request {
820         __u8    intf1_id;
821         __u8    dev1_id;
822         __u8    intf2_id;
823         __u8    dev2_id;
824 };
825
826 /* UART */
827
828 /* Version of the Greybus UART protocol we support */
829 #define GB_UART_VERSION_MAJOR           0x00
830 #define GB_UART_VERSION_MINOR           0x01
831
832 /* Greybus UART operation types */
833 #define GB_UART_TYPE_INVALID                    0x00
834 #define GB_UART_TYPE_PROTOCOL_VERSION           0x01
835 #define GB_UART_TYPE_SEND_DATA                  0x02
836 #define GB_UART_TYPE_RECEIVE_DATA               0x03    /* Unsolicited data */
837 #define GB_UART_TYPE_SET_LINE_CODING            0x04
838 #define GB_UART_TYPE_SET_CONTROL_LINE_STATE     0x05
839 #define GB_UART_TYPE_SEND_BREAK                 0x06
840 #define GB_UART_TYPE_SERIAL_STATE               0x07    /* Unsolicited data */
841
842 /* Represents data from AP -> Module */
843 struct gb_uart_send_data_request {
844         __le16  size;
845         __u8    data[0];
846 };
847
848 /* recv-data-request flags */
849 #define GB_UART_RECV_FLAG_FRAMING               0x01    /* Framing error */
850 #define GB_UART_RECV_FLAG_PARITY                0x02    /* Parity error */
851 #define GB_UART_RECV_FLAG_OVERRUN               0x04    /* Overrun error */
852 #define GB_UART_RECV_FLAG_BREAK                 0x08    /* Break */
853
854 /* Represents data from Module -> AP */
855 struct gb_uart_recv_data_request {
856         __le16  size;
857         __u8    flags;
858         __u8    data[0];
859 } __packed;
860
861 struct gb_uart_set_line_coding_request {
862         __le32  rate;
863         __u8    format;
864 #define GB_SERIAL_1_STOP_BITS                   0
865 #define GB_SERIAL_1_5_STOP_BITS                 1
866 #define GB_SERIAL_2_STOP_BITS                   2
867
868         __u8    parity;
869 #define GB_SERIAL_NO_PARITY                     0
870 #define GB_SERIAL_ODD_PARITY                    1
871 #define GB_SERIAL_EVEN_PARITY                   2
872 #define GB_SERIAL_MARK_PARITY                   3
873 #define GB_SERIAL_SPACE_PARITY                  4
874
875         __u8    data_bits;
876 } __packed;
877
878 /* output control lines */
879 #define GB_UART_CTRL_DTR                        0x01
880 #define GB_UART_CTRL_RTS                        0x02
881
882 struct gb_uart_set_control_line_state_request {
883         __u8    control;
884 };
885
886 struct gb_uart_set_break_request {
887         __u8    state;
888 };
889
890 /* input control lines and line errors */
891 #define GB_UART_CTRL_DCD                        0x01
892 #define GB_UART_CTRL_DSR                        0x02
893 #define GB_UART_CTRL_RI                         0x04
894
895 struct gb_uart_serial_state_request {
896         __u8    control;
897 };
898
899 /* Loopback */
900
901 /* Version of the Greybus loopback protocol we support */
902 #define GB_LOOPBACK_VERSION_MAJOR               0x00
903 #define GB_LOOPBACK_VERSION_MINOR               0x01
904
905 /* Greybus loopback request types */
906 #define GB_LOOPBACK_TYPE_INVALID                0x00
907 #define GB_LOOPBACK_TYPE_PROTOCOL_VERSION       0x01
908 #define GB_LOOPBACK_TYPE_PING                   0x02
909 #define GB_LOOPBACK_TYPE_TRANSFER               0x03
910 #define GB_LOOPBACK_TYPE_SINK                   0x04
911
912 struct gb_loopback_transfer_request {
913         __le32  len;
914         __u8    data[0];
915 };
916
917 struct gb_loopback_transfer_response {
918         __u8    data[0];
919 };
920
921 /* SDIO */
922 /* Version of the Greybus sdio protocol we support */
923 #define GB_SDIO_VERSION_MAJOR           0x00
924 #define GB_SDIO_VERSION_MINOR           0x01
925
926 /* Greybus SDIO operation types */
927 #define GB_SDIO_TYPE_INVALID                    0x00
928 #define GB_SDIO_TYPE_PROTOCOL_VERSION           0x01
929 #define GB_SDIO_TYPE_GET_CAPABILITIES           0x02
930 #define GB_SDIO_TYPE_SET_IOS                    0x03
931 #define GB_SDIO_TYPE_COMMAND                    0x04
932 #define GB_SDIO_TYPE_TRANSFER                   0x05
933 #define GB_SDIO_TYPE_EVENT                      0x06
934
935 /* get caps response: request has no payload */
936 struct gb_sdio_get_caps_response {
937         __le32  caps;
938 #define GB_SDIO_CAP_NONREMOVABLE        0x00000001
939 #define GB_SDIO_CAP_4_BIT_DATA          0x00000002
940 #define GB_SDIO_CAP_8_BIT_DATA          0x00000004
941 #define GB_SDIO_CAP_MMC_HS              0x00000008
942 #define GB_SDIO_CAP_SD_HS               0x00000010
943 #define GB_SDIO_CAP_ERASE               0x00000020
944 #define GB_SDIO_CAP_1_2V_DDR            0x00000040
945 #define GB_SDIO_CAP_1_8V_DDR            0x00000080
946 #define GB_SDIO_CAP_POWER_OFF_CARD      0x00000100
947 #define GB_SDIO_CAP_UHS_SDR12           0x00000200
948 #define GB_SDIO_CAP_UHS_SDR25           0x00000400
949 #define GB_SDIO_CAP_UHS_SDR50           0x00000800
950 #define GB_SDIO_CAP_UHS_SDR104          0x00001000
951 #define GB_SDIO_CAP_UHS_DDR50           0x00002000
952 #define GB_SDIO_CAP_DRIVER_TYPE_A       0x00004000
953 #define GB_SDIO_CAP_DRIVER_TYPE_C       0x00008000
954 #define GB_SDIO_CAP_DRIVER_TYPE_D       0x00010000
955 #define GB_SDIO_CAP_HS200_1_2V          0x00020000
956 #define GB_SDIO_CAP_HS200_1_8V          0x00040000
957 #define GB_SDIO_CAP_HS400_1_2V          0x00080000
958 #define GB_SDIO_CAP_HS400_1_8V          0x00100000
959
960         /* see possible values below at vdd */
961         __le32 ocr;
962         __le16 max_blk_count;
963         __le16 max_blk_size;
964 };
965
966 /* set ios request: response has no payload */
967 struct gb_sdio_set_ios_request {
968         __le32  clock;
969         __le32  vdd;
970 #define GB_SDIO_VDD_165_195     0x00000001
971 #define GB_SDIO_VDD_20_21       0x00000002
972 #define GB_SDIO_VDD_21_22       0x00000004
973 #define GB_SDIO_VDD_22_23       0x00000008
974 #define GB_SDIO_VDD_23_24       0x00000010
975 #define GB_SDIO_VDD_24_25       0x00000020
976 #define GB_SDIO_VDD_25_26       0x00000040
977 #define GB_SDIO_VDD_26_27       0x00000080
978 #define GB_SDIO_VDD_27_28       0x00000100
979 #define GB_SDIO_VDD_28_29       0x00000200
980 #define GB_SDIO_VDD_29_30       0x00000400
981 #define GB_SDIO_VDD_30_31       0x00000800
982 #define GB_SDIO_VDD_31_32       0x00001000
983 #define GB_SDIO_VDD_32_33       0x00002000
984 #define GB_SDIO_VDD_33_34       0x00004000
985 #define GB_SDIO_VDD_34_35       0x00008000
986 #define GB_SDIO_VDD_35_36       0x00010000
987
988         __u8    bus_mode;
989 #define GB_SDIO_BUSMODE_OPENDRAIN       0x00
990 #define GB_SDIO_BUSMODE_PUSHPULL        0x01
991
992         __u8    power_mode;
993 #define GB_SDIO_POWER_OFF       0x00
994 #define GB_SDIO_POWER_UP        0x01
995 #define GB_SDIO_POWER_ON        0x02
996 #define GB_SDIO_POWER_UNDEFINED 0x03
997
998         __u8    bus_width;
999 #define GB_SDIO_BUS_WIDTH_1     0x00
1000 #define GB_SDIO_BUS_WIDTH_4     0x02
1001 #define GB_SDIO_BUS_WIDTH_8     0x03
1002
1003         __u8    timing;
1004 #define GB_SDIO_TIMING_LEGACY           0x00
1005 #define GB_SDIO_TIMING_MMC_HS           0x01
1006 #define GB_SDIO_TIMING_SD_HS            0x02
1007 #define GB_SDIO_TIMING_UHS_SDR12        0x03
1008 #define GB_SDIO_TIMING_UHS_SDR25        0x04
1009 #define GB_SDIO_TIMING_UHS_SDR50        0x05
1010 #define GB_SDIO_TIMING_UHS_SDR104       0x06
1011 #define GB_SDIO_TIMING_UHS_DDR50        0x07
1012 #define GB_SDIO_TIMING_MMC_DDR52        0x08
1013 #define GB_SDIO_TIMING_MMC_HS200        0x09
1014 #define GB_SDIO_TIMING_MMC_HS400        0x0A
1015
1016         __u8    signal_voltage;
1017 #define GB_SDIO_SIGNAL_VOLTAGE_330      0x00
1018 #define GB_SDIO_SIGNAL_VOLTAGE_180      0x01
1019 #define GB_SDIO_SIGNAL_VOLTAGE_120      0x02
1020
1021         __u8    drv_type;
1022 #define GB_SDIO_SET_DRIVER_TYPE_B       0x00
1023 #define GB_SDIO_SET_DRIVER_TYPE_A       0x01
1024 #define GB_SDIO_SET_DRIVER_TYPE_C       0x02
1025 #define GB_SDIO_SET_DRIVER_TYPE_D       0x03
1026 } __packed;
1027
1028 /* command request */
1029 struct gb_sdio_command_request {
1030         __u8    cmd;
1031         __u8    cmd_flags;
1032 #define GB_SDIO_RSP_NONE                0x00
1033 #define GB_SDIO_RSP_PRESENT             0x01
1034 #define GB_SDIO_RSP_136                 0x02
1035 #define GB_SDIO_RSP_CRC                 0x04
1036 #define GB_SDIO_RSP_BUSY                0x08
1037 #define GB_SDIO_RSP_OPCODE              0x10
1038
1039         __u8    cmd_type;
1040 #define GB_SDIO_CMD_AC          0x00
1041 #define GB_SDIO_CMD_ADTC        0x01
1042 #define GB_SDIO_CMD_BCR         0x02
1043 #define GB_SDIO_CMD_BC          0x03
1044
1045         __le32  cmd_arg;
1046 } __packed;
1047
1048 struct gb_sdio_command_response {
1049         __le32  resp[4];
1050 };
1051
1052 /* transfer request */
1053 struct gb_sdio_transfer_request {
1054         __u8    data_flags;
1055 #define GB_SDIO_DATA_WRITE      0x01
1056 #define GB_SDIO_DATA_READ       0x02
1057 #define GB_SDIO_DATA_STREAM     0x04
1058
1059         __le16  data_blocks;
1060         __le16  data_blksz;
1061         __u8    data[0];
1062 } __packed;
1063
1064 struct gb_sdio_transfer_response {
1065         __le16  data_blocks;
1066         __le16  data_blksz;
1067         __u8    data[0];
1068 };
1069
1070 /* event request: generated by module and is defined as unidirectional */
1071 struct gb_sdio_event_request {
1072         __u8    event;
1073 #define GB_SDIO_CARD_INSERTED   0x01
1074 #define GB_SDIO_CARD_REMOVED    0x02
1075 #define GB_SDIO_WP              0x04
1076 };
1077
1078 #endif /* __GREYBUS_PROTOCOLS_H */
1079