]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/greybus/greybus_protocols.h
greybus: svc: implement module inserted and removed operations
[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 /* SVC switch-port device ids */
58 #define GB_SVC_DEVICE_ID_SVC                    0
59 #define GB_SVC_DEVICE_ID_AP                     1
60 #define GB_SVC_DEVICE_ID_MIN                    2
61 #define GB_SVC_DEVICE_ID_MAX                    31
62
63 #define GB_SVC_CPORT_ID                         0
64 #define GB_CONTROL_BUNDLE_ID                    0
65 #define GB_CONTROL_CPORT_ID                     0
66
67
68 /*
69  * All operation messages (both requests and responses) begin with
70  * a header that encodes the size of the message (header included).
71  * This header also contains a unique identifier, that associates a
72  * response message with its operation.  The header contains an
73  * operation type field, whose interpretation is dependent on what
74  * type of protocol is used over the connection.  The high bit
75  * (0x80) of the operation type field is used to indicate whether
76  * the message is a request (clear) or a response (set).
77  *
78  * Response messages include an additional result byte, which
79  * communicates the result of the corresponding request.  A zero
80  * result value means the operation completed successfully.  Any
81  * other value indicates an error; in this case, the payload of the
82  * response message (if any) is ignored.  The result byte must be
83  * zero in the header for a request message.
84  *
85  * The wire format for all numeric fields in the header is little
86  * endian.  Any operation-specific data begins immediately after the
87  * header.
88  */
89 struct gb_operation_msg_hdr {
90         __le16  size;           /* Size in bytes of header + payload */
91         __le16  operation_id;   /* Operation unique id */
92         __u8    type;           /* E.g GB_I2C_TYPE_* or GB_GPIO_TYPE_* */
93         __u8    result;         /* Result of request (in responses only) */
94         __u8    pad[2];         /* must be zero (ignore when read) */
95 } __packed;
96
97
98 /* Generic request numbers supported by all modules */
99 #define GB_REQUEST_TYPE_INVALID                 0x00
100 #define GB_REQUEST_TYPE_PROTOCOL_VERSION        0x01
101
102 struct gb_protocol_version_request {
103         __u8    major;
104         __u8    minor;
105 } __packed;
106
107 struct gb_protocol_version_response {
108         __u8    major;
109         __u8    minor;
110 } __packed;
111
112 /* Control Protocol */
113
114 /* Greybus control request types */
115 #define GB_CONTROL_TYPE_VERSION                 0x01
116 #define GB_CONTROL_TYPE_PROBE_AP                0x02
117 #define GB_CONTROL_TYPE_GET_MANIFEST_SIZE       0x03
118 #define GB_CONTROL_TYPE_GET_MANIFEST            0x04
119 #define GB_CONTROL_TYPE_CONNECTED               0x05
120 #define GB_CONTROL_TYPE_DISCONNECTED            0x06
121 #define GB_CONTROL_TYPE_TIMESYNC_ENABLE         0x07
122 #define GB_CONTROL_TYPE_TIMESYNC_DISABLE        0x08
123 #define GB_CONTROL_TYPE_TIMESYNC_AUTHORITATIVE  0x09
124 #define GB_CONTROL_TYPE_INTERFACE_VERSION       0x0a
125 #define GB_CONTROL_TYPE_BUNDLE_VERSION          0x0b
126
127 struct gb_control_version_request {
128         __u8    major;
129         __u8    minor;
130 } __packed;
131
132 struct gb_control_version_response {
133         __u8    major;
134         __u8    minor;
135 } __packed;
136
137 struct gb_control_bundle_version_request {
138         __u8    bundle_id;
139 } __packed;
140
141 struct gb_control_bundle_version_response {
142         __u8    major;
143         __u8    minor;
144 } __packed;
145
146 /* Control protocol manifest get size request has no payload*/
147 struct gb_control_get_manifest_size_response {
148         __le16                  size;
149 } __packed;
150
151 /* Control protocol manifest get request has no payload */
152 struct gb_control_get_manifest_response {
153         __u8                    data[0];
154 } __packed;
155
156 /* Control protocol [dis]connected request */
157 struct gb_control_connected_request {
158         __le16                  cport_id;
159 } __packed;
160
161 struct gb_control_disconnected_request {
162         __le16                  cport_id;
163 } __packed;
164 /* Control protocol [dis]connected response has no payload */
165
166 /* Control protocol interface version request has no payload */
167 struct gb_control_interface_version_response {
168         __le16                  major;
169         __le16                  minor;
170 } __packed;
171
172 #define GB_TIMESYNC_MAX_STROBES                 0x04
173
174 struct gb_control_timesync_enable_request {
175         __u8    count;
176         __le64  frame_time;
177         __le32  strobe_delay;
178         __le32  refclk;
179 } __packed;
180 /* timesync enable response has no payload */
181
182 struct gb_control_timesync_authoritative_request {
183         __le64  frame_time[GB_TIMESYNC_MAX_STROBES];
184 } __packed;
185 /* timesync authoritative response has no payload */
186
187 /* APBridge protocol */
188
189 /* request APB1 log */
190 #define GB_APB_REQUEST_LOG              0x02
191
192 /* request to map a cport to bulk in and bulk out endpoints */
193 #define GB_APB_REQUEST_EP_MAPPING       0x03
194
195 /* request to get the number of cports available */
196 #define GB_APB_REQUEST_CPORT_COUNT      0x04
197
198 /* request to reset a cport state */
199 #define GB_APB_REQUEST_RESET_CPORT      0x05
200
201 /* request to time the latency of messages on a given cport */
202 #define GB_APB_REQUEST_LATENCY_TAG_EN   0x06
203 #define GB_APB_REQUEST_LATENCY_TAG_DIS  0x07
204
205 /* request to control the CSI transmitter */
206 #define GB_APB_REQUEST_CSI_TX_CONTROL   0x08
207
208 /* request to control the CSI transmitter */
209 #define GB_APB_REQUEST_AUDIO_CONTROL    0x09
210
211 /* vendor requests to enable/disable CPort features */
212 #define GB_APB_REQUEST_CPORT_FEAT_EN    0x0b
213 #define GB_APB_REQUEST_CPORT_FEAT_DIS   0x0c
214
215 /* Bootrom Protocol */
216
217 /* Version of the Greybus bootrom protocol we support */
218 #define GB_BOOTROM_VERSION_MAJOR                0x00
219 #define GB_BOOTROM_VERSION_MINOR                0x01
220
221 /* Greybus bootrom request types */
222 #define GB_BOOTROM_TYPE_VERSION                 0x01
223 #define GB_BOOTROM_TYPE_FIRMWARE_SIZE           0x02
224 #define GB_BOOTROM_TYPE_GET_FIRMWARE            0x03
225 #define GB_BOOTROM_TYPE_READY_TO_BOOT           0x04
226 #define GB_BOOTROM_TYPE_AP_READY                0x05    /* Request with no-payload */
227 #define GB_BOOTROM_TYPE_GET_VID_PID             0x06    /* Request with no-payload */
228
229 /* Greybus bootrom boot stages */
230 #define GB_BOOTROM_BOOT_STAGE_ONE               0x01 /* Reserved for the boot ROM */
231 #define GB_BOOTROM_BOOT_STAGE_TWO               0x02 /* Bootrom package to be loaded by the boot ROM */
232 #define GB_BOOTROM_BOOT_STAGE_THREE             0x03 /* Module personality package loaded by Stage 2 firmware */
233
234 /* Greybus bootrom ready to boot status */
235 #define GB_BOOTROM_BOOT_STATUS_INVALID          0x00 /* Firmware blob could not be validated */
236 #define GB_BOOTROM_BOOT_STATUS_INSECURE         0x01 /* Firmware blob is valid but insecure */
237 #define GB_BOOTROM_BOOT_STATUS_SECURE           0x02 /* Firmware blob is valid and secure */
238
239 /* Max bootrom data fetch size in bytes */
240 #define GB_BOOTROM_FETCH_MAX                    2000
241
242 struct gb_bootrom_version_request {
243         __u8    major;
244         __u8    minor;
245 } __packed;
246
247 struct gb_bootrom_version_response {
248         __u8    major;
249         __u8    minor;
250 } __packed;
251
252 /* Bootrom protocol firmware size request/response */
253 struct gb_bootrom_firmware_size_request {
254         __u8                    stage;
255 } __packed;
256
257 struct gb_bootrom_firmware_size_response {
258         __le32                  size;
259 } __packed;
260
261 /* Bootrom protocol get firmware request/response */
262 struct gb_bootrom_get_firmware_request {
263         __le32                  offset;
264         __le32                  size;
265 } __packed;
266
267 struct gb_bootrom_get_firmware_response {
268         __u8                    data[0];
269 } __packed;
270
271 /* Bootrom protocol Ready to boot request */
272 struct gb_bootrom_ready_to_boot_request {
273         __u8                    status;
274 } __packed;
275 /* Bootrom protocol Ready to boot response has no payload */
276
277 /* Bootrom protocol get VID/PID request has no payload */
278 struct gb_bootrom_get_vid_pid_response {
279         __le32                  vendor_id;
280         __le32                  product_id;
281 } __packed;
282
283
284 /* Power Supply */
285
286 /* Version of the Greybus power supply protocol we support */
287 #define GB_POWER_SUPPLY_VERSION_MAJOR           0x00
288 #define GB_POWER_SUPPLY_VERSION_MINOR           0x01
289
290 /* Greybus power supply request types */
291 #define GB_POWER_SUPPLY_TYPE_GET_SUPPLIES               0x02
292 #define GB_POWER_SUPPLY_TYPE_GET_DESCRIPTION            0x03
293 #define GB_POWER_SUPPLY_TYPE_GET_PROP_DESCRIPTORS       0x04
294 #define GB_POWER_SUPPLY_TYPE_GET_PROPERTY               0x05
295 #define GB_POWER_SUPPLY_TYPE_SET_PROPERTY               0x06
296 #define GB_POWER_SUPPLY_TYPE_EVENT                      0x07
297
298 /* Should match up with battery technologies in linux/power_supply.h */
299 #define GB_POWER_SUPPLY_TECH_UNKNOWN                    0x0000
300 #define GB_POWER_SUPPLY_TECH_NiMH                       0x0001
301 #define GB_POWER_SUPPLY_TECH_LION                       0x0002
302 #define GB_POWER_SUPPLY_TECH_LIPO                       0x0003
303 #define GB_POWER_SUPPLY_TECH_LiFe                       0x0004
304 #define GB_POWER_SUPPLY_TECH_NiCd                       0x0005
305 #define GB_POWER_SUPPLY_TECH_LiMn                       0x0006
306
307 /* Should match up with power supply types in linux/power_supply.h */
308 #define GB_POWER_SUPPLY_UNKNOWN_TYPE                    0x0000
309 #define GB_POWER_SUPPLY_BATTERY_TYPE                    0x0001
310 #define GB_POWER_SUPPLY_UPS_TYPE                        0x0002
311 #define GB_POWER_SUPPLY_MAINS_TYPE                      0x0003
312 #define GB_POWER_SUPPLY_USB_TYPE                        0x0004
313 #define GB_POWER_SUPPLY_USB_DCP_TYPE                    0x0005
314 #define GB_POWER_SUPPLY_USB_CDP_TYPE                    0x0006
315 #define GB_POWER_SUPPLY_USB_ACA_TYPE                    0x0007
316
317 /* Should match up with power supply health in linux/power_supply.h */
318 #define GB_POWER_SUPPLY_HEALTH_UNKNOWN                  0x0000
319 #define GB_POWER_SUPPLY_HEALTH_GOOD                     0x0001
320 #define GB_POWER_SUPPLY_HEALTH_OVERHEAT                 0x0002
321 #define GB_POWER_SUPPLY_HEALTH_DEAD                     0x0003
322 #define GB_POWER_SUPPLY_HEALTH_OVERVOLTAGE              0x0004
323 #define GB_POWER_SUPPLY_HEALTH_UNSPEC_FAILURE           0x0005
324 #define GB_POWER_SUPPLY_HEALTH_COLD                     0x0006
325 #define GB_POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE    0x0007
326 #define GB_POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE      0x0008
327
328 /* Should match up with battery status in linux/power_supply.h */
329 #define GB_POWER_SUPPLY_STATUS_UNKNOWN          0x0000
330 #define GB_POWER_SUPPLY_STATUS_CHARGING         0x0001
331 #define GB_POWER_SUPPLY_STATUS_DISCHARGING      0x0002
332 #define GB_POWER_SUPPLY_STATUS_NOT_CHARGING     0x0003
333 #define GB_POWER_SUPPLY_STATUS_FULL             0x0004
334
335 struct gb_power_supply_get_supplies_response {
336         __u8    supplies_count;
337 } __packed;
338
339 struct gb_power_supply_get_description_request {
340         __u8    psy_id;
341 } __packed;
342
343 struct gb_power_supply_get_description_response {
344         __u8    manufacturer[32];
345         __u8    model[32];
346         __u8    serial_number[32];
347         __le16  type;
348         __u8    properties_count;
349 } __packed;
350
351 struct gb_power_supply_props_desc {
352         __u8    property;
353 #define GB_POWER_SUPPLY_PROP_STATUS                             0x00
354 #define GB_POWER_SUPPLY_PROP_CHARGE_TYPE                        0x01
355 #define GB_POWER_SUPPLY_PROP_HEALTH                             0x02
356 #define GB_POWER_SUPPLY_PROP_PRESENT                            0x03
357 #define GB_POWER_SUPPLY_PROP_ONLINE                             0x04
358 #define GB_POWER_SUPPLY_PROP_AUTHENTIC                          0x05
359 #define GB_POWER_SUPPLY_PROP_TECHNOLOGY                         0x06
360 #define GB_POWER_SUPPLY_PROP_CYCLE_COUNT                        0x07
361 #define GB_POWER_SUPPLY_PROP_VOLTAGE_MAX                        0x08
362 #define GB_POWER_SUPPLY_PROP_VOLTAGE_MIN                        0x09
363 #define GB_POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN                 0x0A
364 #define GB_POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN                 0x0B
365 #define GB_POWER_SUPPLY_PROP_VOLTAGE_NOW                        0x0C
366 #define GB_POWER_SUPPLY_PROP_VOLTAGE_AVG                        0x0D
367 #define GB_POWER_SUPPLY_PROP_VOLTAGE_OCV                        0x0E
368 #define GB_POWER_SUPPLY_PROP_VOLTAGE_BOOT                       0x0F
369 #define GB_POWER_SUPPLY_PROP_CURRENT_MAX                        0x10
370 #define GB_POWER_SUPPLY_PROP_CURRENT_NOW                        0x11
371 #define GB_POWER_SUPPLY_PROP_CURRENT_AVG                        0x12
372 #define GB_POWER_SUPPLY_PROP_CURRENT_BOOT                       0x13
373 #define GB_POWER_SUPPLY_PROP_POWER_NOW                          0x14
374 #define GB_POWER_SUPPLY_PROP_POWER_AVG                          0x15
375 #define GB_POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN                 0x16
376 #define GB_POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN                0x17
377 #define GB_POWER_SUPPLY_PROP_CHARGE_FULL                        0x18
378 #define GB_POWER_SUPPLY_PROP_CHARGE_EMPTY                       0x19
379 #define GB_POWER_SUPPLY_PROP_CHARGE_NOW                         0x1A
380 #define GB_POWER_SUPPLY_PROP_CHARGE_AVG                         0x1B
381 #define GB_POWER_SUPPLY_PROP_CHARGE_COUNTER                     0x1C
382 #define GB_POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT            0x1D
383 #define GB_POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX        0x1E
384 #define GB_POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE            0x1F
385 #define GB_POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX        0x20
386 #define GB_POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT               0x21
387 #define GB_POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX           0x22
388 #define GB_POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT                0x23
389 #define GB_POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN                 0x24
390 #define GB_POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN                0x25
391 #define GB_POWER_SUPPLY_PROP_ENERGY_FULL                        0x26
392 #define GB_POWER_SUPPLY_PROP_ENERGY_EMPTY                       0x27
393 #define GB_POWER_SUPPLY_PROP_ENERGY_NOW                         0x28
394 #define GB_POWER_SUPPLY_PROP_ENERGY_AVG                         0x29
395 #define GB_POWER_SUPPLY_PROP_CAPACITY                           0x2A
396 #define GB_POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN                 0x2B
397 #define GB_POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX                 0x2C
398 #define GB_POWER_SUPPLY_PROP_CAPACITY_LEVEL                     0x2D
399 #define GB_POWER_SUPPLY_PROP_TEMP                               0x2E
400 #define GB_POWER_SUPPLY_PROP_TEMP_MAX                           0x2F
401 #define GB_POWER_SUPPLY_PROP_TEMP_MIN                           0x30
402 #define GB_POWER_SUPPLY_PROP_TEMP_ALERT_MIN                     0x31
403 #define GB_POWER_SUPPLY_PROP_TEMP_ALERT_MAX                     0x32
404 #define GB_POWER_SUPPLY_PROP_TEMP_AMBIENT                       0x33
405 #define GB_POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN             0x34
406 #define GB_POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX             0x35
407 #define GB_POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW                  0x36
408 #define GB_POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG                  0x37
409 #define GB_POWER_SUPPLY_PROP_TIME_TO_FULL_NOW                   0x38
410 #define GB_POWER_SUPPLY_PROP_TIME_TO_FULL_AVG                   0x39
411 #define GB_POWER_SUPPLY_PROP_TYPE                               0x3A
412 #define GB_POWER_SUPPLY_PROP_SCOPE                              0x3B
413 #define GB_POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT                0x3C
414 #define GB_POWER_SUPPLY_PROP_CALIBRATE                          0x3D
415         __u8    is_writeable;
416 } __packed;
417
418 struct gb_power_supply_get_property_descriptors_request {
419         __u8    psy_id;
420 } __packed;
421
422 struct gb_power_supply_get_property_descriptors_response {
423         __u8    properties_count;
424         struct gb_power_supply_props_desc props[];
425 } __packed;
426
427 struct gb_power_supply_get_property_request {
428         __u8    psy_id;
429         __u8    property;
430 } __packed;
431
432 struct gb_power_supply_get_property_response {
433         __le32  prop_val;
434 };
435
436 struct gb_power_supply_set_property_request {
437         __u8    psy_id;
438         __u8    property;
439         __le32  prop_val;
440 } __packed;
441
442 struct gb_power_supply_event_request {
443         __u8    psy_id;
444         __u8    event;
445 #define GB_POWER_SUPPLY_UPDATE          0x01
446 } __packed;
447
448
449 /* HID */
450
451 /* Version of the Greybus hid protocol we support */
452 #define GB_HID_VERSION_MAJOR            0x00
453 #define GB_HID_VERSION_MINOR            0x01
454
455 /* Greybus HID operation types */
456 #define GB_HID_TYPE_GET_DESC            0x02
457 #define GB_HID_TYPE_GET_REPORT_DESC     0x03
458 #define GB_HID_TYPE_PWR_ON              0x04
459 #define GB_HID_TYPE_PWR_OFF             0x05
460 #define GB_HID_TYPE_GET_REPORT          0x06
461 #define GB_HID_TYPE_SET_REPORT          0x07
462 #define GB_HID_TYPE_IRQ_EVENT           0x08
463
464 /* Report type */
465 #define GB_HID_INPUT_REPORT             0
466 #define GB_HID_OUTPUT_REPORT            1
467 #define GB_HID_FEATURE_REPORT           2
468
469 /* Different request/response structures */
470 /* HID get descriptor response */
471 struct gb_hid_desc_response {
472         __u8                            bLength;
473         __le16                          wReportDescLength;
474         __le16                          bcdHID;
475         __le16                          wProductID;
476         __le16                          wVendorID;
477         __u8                            bCountryCode;
478 } __packed;
479
480 /* HID get report request/response */
481 struct gb_hid_get_report_request {
482         __u8                            report_type;
483         __u8                            report_id;
484 } __packed;
485
486 /* HID set report request */
487 struct gb_hid_set_report_request {
488         __u8                            report_type;
489         __u8                            report_id;
490         __u8                            report[0];
491 } __packed;
492
493 /* HID input report request, via interrupt pipe */
494 struct gb_hid_input_report_request {
495         __u8                            report[0];
496 } __packed;
497
498
499 /* I2C */
500
501 /* Version of the Greybus i2c protocol we support */
502 #define GB_I2C_VERSION_MAJOR            0x00
503 #define GB_I2C_VERSION_MINOR            0x01
504
505 /* Greybus i2c request types */
506 #define GB_I2C_TYPE_FUNCTIONALITY       0x02
507 #define GB_I2C_TYPE_TRANSFER            0x05
508
509 /* functionality request has no payload */
510 struct gb_i2c_functionality_response {
511         __le32  functionality;
512 } __packed;
513
514 /*
515  * Outgoing data immediately follows the op count and ops array.
516  * The data for each write (master -> slave) op in the array is sent
517  * in order, with no (e.g. pad) bytes separating them.
518  *
519  * Short reads cause the entire transfer request to fail So response
520  * payload consists only of bytes read, and the number of bytes is
521  * exactly what was specified in the corresponding op.  Like
522  * outgoing data, the incoming data is in order and contiguous.
523  */
524 struct gb_i2c_transfer_op {
525         __le16  addr;
526         __le16  flags;
527         __le16  size;
528 } __packed;
529
530 struct gb_i2c_transfer_request {
531         __le16                          op_count;
532         struct gb_i2c_transfer_op       ops[0];         /* op_count of these */
533 } __packed;
534 struct gb_i2c_transfer_response {
535         __u8                            data[0];        /* inbound data */
536 } __packed;
537
538
539 /* GPIO */
540
541 /* Version of the Greybus GPIO protocol we support */
542 #define GB_GPIO_VERSION_MAJOR           0x00
543 #define GB_GPIO_VERSION_MINOR           0x01
544
545 /* Greybus GPIO request types */
546 #define GB_GPIO_TYPE_LINE_COUNT         0x02
547 #define GB_GPIO_TYPE_ACTIVATE           0x03
548 #define GB_GPIO_TYPE_DEACTIVATE         0x04
549 #define GB_GPIO_TYPE_GET_DIRECTION      0x05
550 #define GB_GPIO_TYPE_DIRECTION_IN       0x06
551 #define GB_GPIO_TYPE_DIRECTION_OUT      0x07
552 #define GB_GPIO_TYPE_GET_VALUE          0x08
553 #define GB_GPIO_TYPE_SET_VALUE          0x09
554 #define GB_GPIO_TYPE_SET_DEBOUNCE       0x0a
555 #define GB_GPIO_TYPE_IRQ_TYPE           0x0b
556 #define GB_GPIO_TYPE_IRQ_MASK           0x0c
557 #define GB_GPIO_TYPE_IRQ_UNMASK         0x0d
558 #define GB_GPIO_TYPE_IRQ_EVENT          0x0e
559
560 #define GB_GPIO_IRQ_TYPE_NONE           0x00
561 #define GB_GPIO_IRQ_TYPE_EDGE_RISING    0x01
562 #define GB_GPIO_IRQ_TYPE_EDGE_FALLING   0x02
563 #define GB_GPIO_IRQ_TYPE_EDGE_BOTH      0x03
564 #define GB_GPIO_IRQ_TYPE_LEVEL_HIGH     0x04
565 #define GB_GPIO_IRQ_TYPE_LEVEL_LOW      0x08
566
567 /* line count request has no payload */
568 struct gb_gpio_line_count_response {
569         __u8    count;
570 } __packed;
571
572 struct gb_gpio_activate_request {
573         __u8    which;
574 } __packed;
575 /* activate response has no payload */
576
577 struct gb_gpio_deactivate_request {
578         __u8    which;
579 } __packed;
580 /* deactivate response has no payload */
581
582 struct gb_gpio_get_direction_request {
583         __u8    which;
584 } __packed;
585 struct gb_gpio_get_direction_response {
586         __u8    direction;
587 } __packed;
588
589 struct gb_gpio_direction_in_request {
590         __u8    which;
591 } __packed;
592 /* direction in response has no payload */
593
594 struct gb_gpio_direction_out_request {
595         __u8    which;
596         __u8    value;
597 } __packed;
598 /* direction out response has no payload */
599
600 struct gb_gpio_get_value_request {
601         __u8    which;
602 } __packed;
603 struct gb_gpio_get_value_response {
604         __u8    value;
605 } __packed;
606
607 struct gb_gpio_set_value_request {
608         __u8    which;
609         __u8    value;
610 } __packed;
611 /* set value response has no payload */
612
613 struct gb_gpio_set_debounce_request {
614         __u8    which;
615         __le16  usec;
616 } __packed;
617 /* debounce response has no payload */
618
619 struct gb_gpio_irq_type_request {
620         __u8    which;
621         __u8    type;
622 } __packed;
623 /* irq type response has no payload */
624
625 struct gb_gpio_irq_mask_request {
626         __u8    which;
627 } __packed;
628 /* irq mask response has no payload */
629
630 struct gb_gpio_irq_unmask_request {
631         __u8    which;
632 } __packed;
633 /* irq unmask response has no payload */
634
635 /* irq event requests originate on another module and are handled on the AP */
636 struct gb_gpio_irq_event_request {
637         __u8    which;
638 } __packed;
639 /* irq event has no response */
640
641
642 /* PWM */
643
644 /* Version of the Greybus PWM protocol we support */
645 #define GB_PWM_VERSION_MAJOR            0x00
646 #define GB_PWM_VERSION_MINOR            0x01
647
648 /* Greybus PWM operation types */
649 #define GB_PWM_TYPE_PWM_COUNT           0x02
650 #define GB_PWM_TYPE_ACTIVATE            0x03
651 #define GB_PWM_TYPE_DEACTIVATE          0x04
652 #define GB_PWM_TYPE_CONFIG              0x05
653 #define GB_PWM_TYPE_POLARITY            0x06
654 #define GB_PWM_TYPE_ENABLE              0x07
655 #define GB_PWM_TYPE_DISABLE             0x08
656
657 /* pwm count request has no payload */
658 struct gb_pwm_count_response {
659         __u8    count;
660 } __packed;
661
662 struct gb_pwm_activate_request {
663         __u8    which;
664 } __packed;
665
666 struct gb_pwm_deactivate_request {
667         __u8    which;
668 } __packed;
669
670 struct gb_pwm_config_request {
671         __u8    which;
672         __le32  duty;
673         __le32  period;
674 } __packed;
675
676 struct gb_pwm_polarity_request {
677         __u8    which;
678         __u8    polarity;
679 } __packed;
680
681 struct gb_pwm_enable_request {
682         __u8    which;
683 } __packed;
684
685 struct gb_pwm_disable_request {
686         __u8    which;
687 } __packed;
688
689 /* SPI */
690
691 /* Version of the Greybus spi protocol we support */
692 #define GB_SPI_VERSION_MAJOR            0x00
693 #define GB_SPI_VERSION_MINOR            0x01
694
695 /* Should match up with modes in linux/spi/spi.h */
696 #define GB_SPI_MODE_CPHA                0x01            /* clock phase */
697 #define GB_SPI_MODE_CPOL                0x02            /* clock polarity */
698 #define GB_SPI_MODE_MODE_0              (0|0)           /* (original MicroWire) */
699 #define GB_SPI_MODE_MODE_1              (0|GB_SPI_MODE_CPHA)
700 #define GB_SPI_MODE_MODE_2              (GB_SPI_MODE_CPOL|0)
701 #define GB_SPI_MODE_MODE_3              (GB_SPI_MODE_CPOL|GB_SPI_MODE_CPHA)
702 #define GB_SPI_MODE_CS_HIGH             0x04            /* chipselect active high? */
703 #define GB_SPI_MODE_LSB_FIRST           0x08            /* per-word bits-on-wire */
704 #define GB_SPI_MODE_3WIRE               0x10            /* SI/SO signals shared */
705 #define GB_SPI_MODE_LOOP                0x20            /* loopback mode */
706 #define GB_SPI_MODE_NO_CS               0x40            /* 1 dev/bus, no chipselect */
707 #define GB_SPI_MODE_READY               0x80            /* slave pulls low to pause */
708
709 /* Should match up with flags in linux/spi/spi.h */
710 #define GB_SPI_FLAG_HALF_DUPLEX         BIT(0)          /* can't do full duplex */
711 #define GB_SPI_FLAG_NO_RX               BIT(1)          /* can't do buffer read */
712 #define GB_SPI_FLAG_NO_TX               BIT(2)          /* can't do buffer write */
713
714 /* Greybus spi operation types */
715 #define GB_SPI_TYPE_MASTER_CONFIG       0x02
716 #define GB_SPI_TYPE_DEVICE_CONFIG       0x03
717 #define GB_SPI_TYPE_TRANSFER            0x04
718
719 /* mode request has no payload */
720 struct gb_spi_master_config_response {
721         __le32  bits_per_word_mask;
722         __le32  min_speed_hz;
723         __le32  max_speed_hz;
724         __le16  mode;
725         __le16  flags;
726         __u8    num_chipselect;
727 } __packed;
728
729 struct gb_spi_device_config_request {
730         __u8    chip_select;
731 } __packed;
732
733 struct gb_spi_device_config_response {
734         __le16  mode;
735         __u8    bits_per_word;
736         __le32  max_speed_hz;
737         __u8    device_type;
738 #define GB_SPI_SPI_DEV          0x00
739 #define GB_SPI_SPI_NOR          0x01
740 #define GB_SPI_SPI_MODALIAS     0x02
741         __u8    name[32];
742 } __packed;
743
744 /**
745  * struct gb_spi_transfer - a read/write buffer pair
746  * @speed_hz: Select a speed other than the device default for this transfer. If
747  *      0 the default (from @spi_device) is used.
748  * @len: size of rx and tx buffers (in bytes)
749  * @delay_usecs: microseconds to delay after this transfer before (optionally)
750  *      changing the chipselect status, then starting the next transfer or
751  *      completing this spi_message.
752  * @cs_change: affects chipselect after this transfer completes
753  * @bits_per_word: select a bits_per_word other than the device default for this
754  *      transfer. If 0 the default (from @spi_device) is used.
755  */
756 struct gb_spi_transfer {
757         __le32          speed_hz;
758         __le32          len;
759         __le16          delay_usecs;
760         __u8            cs_change;
761         __u8            bits_per_word;
762         __u8            rdwr;
763 #define GB_SPI_XFER_READ        0x01
764 #define GB_SPI_XFER_WRITE       0x02
765 } __packed;
766
767 struct gb_spi_transfer_request {
768         __u8                    chip_select;    /* of the spi device */
769         __u8                    mode;           /* of the spi device */
770         __le16                  count;
771         struct gb_spi_transfer  transfers[0];   /* count of these */
772 } __packed;
773
774 struct gb_spi_transfer_response {
775         __u8                    data[0];        /* inbound data */
776 } __packed;
777
778 /* Version of the Greybus SVC protocol we support */
779 #define GB_SVC_VERSION_MAJOR            0x00
780 #define GB_SVC_VERSION_MINOR            0x01
781
782 /* Greybus SVC request types */
783 #define GB_SVC_TYPE_SVC_HELLO                   0x02
784 #define GB_SVC_TYPE_INTF_DEVICE_ID              0x03
785 #define GB_SVC_TYPE_INTF_HOTPLUG                0x04
786 #define GB_SVC_TYPE_INTF_HOT_UNPLUG             0x05
787 #define GB_SVC_TYPE_INTF_RESET                  0x06
788 #define GB_SVC_TYPE_CONN_CREATE                 0x07
789 #define GB_SVC_TYPE_CONN_DESTROY                0x08
790 #define GB_SVC_TYPE_DME_PEER_GET                0x09
791 #define GB_SVC_TYPE_DME_PEER_SET                0x0a
792 #define GB_SVC_TYPE_ROUTE_CREATE                0x0b
793 #define GB_SVC_TYPE_ROUTE_DESTROY               0x0c
794 #define GB_SVC_TYPE_TIMESYNC_ENABLE             0x0d
795 #define GB_SVC_TYPE_TIMESYNC_DISABLE            0x0e
796 #define GB_SVC_TYPE_TIMESYNC_AUTHORITATIVE      0x0f
797 #define GB_SVC_TYPE_INTF_SET_PWRM               0x10
798 #define GB_SVC_TYPE_INTF_EJECT                  0x11
799 #define GB_SVC_TYPE_KEY_EVENT                   0x12
800 #define GB_SVC_TYPE_PING                        0x13
801 #define GB_SVC_TYPE_PWRMON_RAIL_COUNT_GET       0x14
802 #define GB_SVC_TYPE_PWRMON_RAIL_NAMES_GET       0x15
803 #define GB_SVC_TYPE_PWRMON_SAMPLE_GET           0x16
804 #define GB_SVC_TYPE_PWRMON_INTF_SAMPLE_GET      0x17
805 #define GB_SVC_TYPE_MODULE_INSERTED             0x1f
806 #define GB_SVC_TYPE_MODULE_REMOVED              0x20
807 #define GB_SVC_TYPE_INTF_ACTIVATE               0x27
808
809 /*
810  * SVC version request/response has the same payload as
811  * gb_protocol_version_request/response.
812  */
813
814 /* SVC protocol hello request */
815 struct gb_svc_hello_request {
816         __le16                  endo_id;
817         __u8                    interface_id;
818 } __packed;
819 /* hello response has no payload */
820
821 struct gb_svc_intf_device_id_request {
822         __u8    intf_id;
823         __u8    device_id;
824 } __packed;
825 /* device id response has no payload */
826
827 struct gb_svc_intf_hotplug_request {
828         __u8    intf_id;
829         struct {
830                 __le32  ddbl1_mfr_id;
831                 __le32  ddbl1_prod_id;
832                 __le32  ara_vend_id;
833                 __le32  ara_prod_id;
834                 __le64  serial_number;
835         } data;
836 } __packed;
837 /* hotplug response has no payload */
838
839 struct gb_svc_intf_hot_unplug_request {
840         __u8    intf_id;
841 } __packed;
842 /* hot unplug response has no payload */
843
844 struct gb_svc_intf_reset_request {
845         __u8    intf_id;
846 } __packed;
847 /* interface reset response has no payload */
848
849 struct gb_svc_intf_eject_request {
850         __u8    intf_id;
851 } __packed;
852 /* interface eject response has no payload */
853
854 struct gb_svc_conn_create_request {
855         __u8    intf1_id;
856         __le16  cport1_id;
857         __u8    intf2_id;
858         __le16  cport2_id;
859         __u8    tc;
860         __u8    flags;
861 } __packed;
862 /* connection create response has no payload */
863
864 struct gb_svc_conn_destroy_request {
865         __u8    intf1_id;
866         __le16  cport1_id;
867         __u8    intf2_id;
868         __le16  cport2_id;
869 } __packed;
870 /* connection destroy response has no payload */
871
872 struct gb_svc_dme_peer_get_request {
873         __u8    intf_id;
874         __le16  attr;
875         __le16  selector;
876 } __packed;
877
878 struct gb_svc_dme_peer_get_response {
879         __le16  result_code;
880         __le32  attr_value;
881 } __packed;
882
883 struct gb_svc_dme_peer_set_request {
884         __u8    intf_id;
885         __le16  attr;
886         __le16  selector;
887         __le32  value;
888 } __packed;
889
890 struct gb_svc_dme_peer_set_response {
891         __le16  result_code;
892 } __packed;
893
894 /* Greybus init-status values, currently retrieved using DME peer gets. */
895 #define GB_INIT_SPI_BOOT_STARTED                        0x02
896 #define GB_INIT_TRUSTED_SPI_BOOT_FINISHED               0x03
897 #define GB_INIT_UNTRUSTED_SPI_BOOT_FINISHED             0x04
898 #define GB_INIT_BOOTROM_UNIPRO_BOOT_STARTED             0x06
899 #define GB_INIT_BOOTROM_FALLBACK_UNIPRO_BOOT_STARTED    0x09
900
901 struct gb_svc_route_create_request {
902         __u8    intf1_id;
903         __u8    dev1_id;
904         __u8    intf2_id;
905         __u8    dev2_id;
906 } __packed;
907 /* route create response has no payload */
908
909 struct gb_svc_route_destroy_request {
910         __u8    intf1_id;
911         __u8    intf2_id;
912 } __packed;
913 /* route destroy response has no payload */
914
915 struct gb_svc_timesync_enable_request {
916         __u8    count;
917         __le64  frame_time;
918         __le32  strobe_delay;
919         __le32  strobe_mask;
920         __le32  refclk;
921 } __packed;
922 /* timesync enable response has no payload */
923
924 /* timesync authoritative request has no payload */
925 struct gb_svc_timesync_authoritative_response {
926         __le64  frame_time[GB_TIMESYNC_MAX_STROBES];
927 };
928
929 #define GB_SVC_UNIPRO_FAST_MODE                 0x01
930 #define GB_SVC_UNIPRO_SLOW_MODE                 0x02
931 #define GB_SVC_UNIPRO_FAST_AUTO_MODE            0x04
932 #define GB_SVC_UNIPRO_SLOW_AUTO_MODE            0x05
933 #define GB_SVC_UNIPRO_MODE_UNCHANGED            0x07
934 #define GB_SVC_UNIPRO_HIBERNATE_MODE            0x11
935 #define GB_SVC_UNIPRO_OFF_MODE                  0x12
936
937 #define GB_SVC_PWRM_RXTERMINATION               0x01
938 #define GB_SVC_PWRM_TXTERMINATION               0x02
939 #define GB_SVC_PWRM_LINE_RESET                  0x04
940 #define GB_SVC_PWRM_SCRAMBLING                  0x20
941
942 #define GB_SVC_PWRM_QUIRK_HSSER                 0x00000001
943
944 #define GB_SVC_UNIPRO_HS_SERIES_A               0x01
945 #define GB_SVC_UNIPRO_HS_SERIES_B               0x02
946
947 struct gb_svc_intf_set_pwrm_request {
948         __u8    intf_id;
949         __u8    hs_series;
950         __u8    tx_mode;
951         __u8    tx_gear;
952         __u8    tx_nlanes;
953         __u8    rx_mode;
954         __u8    rx_gear;
955         __u8    rx_nlanes;
956         __u8    flags;
957         __le32  quirks;
958 } __packed;
959
960 struct gb_svc_intf_set_pwrm_response {
961         __le16  result_code;
962 } __packed;
963
964 struct gb_svc_key_event_request {
965         __le16  key_code;
966 #define GB_KEYCODE_ARA         0x00
967
968         __u8    key_event;
969 #define GB_SVC_KEY_RELEASED    0x00
970 #define GB_SVC_KEY_PRESSED     0x01
971 } __packed;
972
973 #define GB_SVC_PWRMON_MAX_RAIL_COUNT            254
974
975 struct gb_svc_pwrmon_rail_count_get_response {
976         __u8    rail_count;
977 } __packed;
978
979 #define GB_SVC_PWRMON_RAIL_NAME_BUFSIZE         32
980
981 struct gb_svc_pwrmon_rail_names_get_response {
982         __u8    name[0][GB_SVC_PWRMON_RAIL_NAME_BUFSIZE];
983 } __packed;
984
985 #define GB_SVC_PWRMON_TYPE_CURR                 0x01
986 #define GB_SVC_PWRMON_TYPE_VOL                  0x02
987 #define GB_SVC_PWRMON_TYPE_PWR                  0x03
988
989 #define GB_SVC_PWRMON_GET_SAMPLE_OK             0x00
990 #define GB_SVC_PWRMON_GET_SAMPLE_INVAL          0x01
991 #define GB_SVC_PWRMON_GET_SAMPLE_NOSUPP         0x02
992 #define GB_SVC_PWRMON_GET_SAMPLE_HWERR          0x03
993
994 struct gb_svc_pwrmon_sample_get_request {
995         __u8    rail_id;
996         __u8    measurement_type;
997 } __packed;
998
999 struct gb_svc_pwrmon_sample_get_response {
1000         __u8    result;
1001         __le32  measurement;
1002 } __packed;
1003
1004 struct gb_svc_pwrmon_intf_sample_get_request {
1005         __u8    intf_id;
1006         __u8    measurement_type;
1007 } __packed;
1008
1009 struct gb_svc_pwrmon_intf_sample_get_response {
1010         __u8    result;
1011         __le32  measurement;
1012 } __packed;
1013
1014 #define GB_SVC_MODULE_INSERTED_FLAG_NO_PRIMARY  0x0001
1015
1016 struct gb_svc_module_inserted_request {
1017         __u8    primary_intf_id;
1018         __u8    intf_count;
1019         __le16  flags;
1020 } __packed;
1021 /* module_inserted response has no payload */
1022
1023 struct gb_svc_module_removed_request {
1024         __u8    primary_intf_id;
1025 } __packed;
1026 /* module_removed response has no payload */
1027
1028 struct gb_svc_intf_activate_request {
1029         __u8    intf_id;
1030 } __packed;
1031
1032 #define GB_SVC_INTF_TYPE_UNKNOWN                0x00
1033 #define GB_SVC_INTF_TYPE_DUMMY                  0x01
1034 #define GB_SVC_INTF_TYPE_UNIPRO                 0x02
1035 #define GB_SVC_INTF_TYPE_GREYBUS                0x03
1036
1037 struct gb_svc_intf_activate_response {
1038         __u8    intf_type;
1039 } __packed;
1040
1041 /* RAW */
1042
1043 /* Version of the Greybus raw protocol we support */
1044 #define GB_RAW_VERSION_MAJOR                    0x00
1045 #define GB_RAW_VERSION_MINOR                    0x01
1046
1047 /* Greybus raw request types */
1048 #define GB_RAW_TYPE_SEND                        0x02
1049
1050 struct gb_raw_send_request {
1051         __le32  len;
1052         __u8    data[0];
1053 } __packed;
1054
1055
1056 /* UART */
1057
1058 /* Version of the Greybus UART protocol we support */
1059 #define GB_UART_VERSION_MAJOR           0x00
1060 #define GB_UART_VERSION_MINOR           0x01
1061
1062 /* Greybus UART operation types */
1063 #define GB_UART_TYPE_SEND_DATA                  0x02
1064 #define GB_UART_TYPE_RECEIVE_DATA               0x03    /* Unsolicited data */
1065 #define GB_UART_TYPE_SET_LINE_CODING            0x04
1066 #define GB_UART_TYPE_SET_CONTROL_LINE_STATE     0x05
1067 #define GB_UART_TYPE_SEND_BREAK                 0x06
1068 #define GB_UART_TYPE_SERIAL_STATE               0x07    /* Unsolicited data */
1069
1070 /* Represents data from AP -> Module */
1071 struct gb_uart_send_data_request {
1072         __le16  size;
1073         __u8    data[0];
1074 } __packed;
1075
1076 /* recv-data-request flags */
1077 #define GB_UART_RECV_FLAG_FRAMING               0x01    /* Framing error */
1078 #define GB_UART_RECV_FLAG_PARITY                0x02    /* Parity error */
1079 #define GB_UART_RECV_FLAG_OVERRUN               0x04    /* Overrun error */
1080 #define GB_UART_RECV_FLAG_BREAK                 0x08    /* Break */
1081
1082 /* Represents data from Module -> AP */
1083 struct gb_uart_recv_data_request {
1084         __le16  size;
1085         __u8    flags;
1086         __u8    data[0];
1087 } __packed;
1088
1089 struct gb_uart_set_line_coding_request {
1090         __le32  rate;
1091         __u8    format;
1092 #define GB_SERIAL_1_STOP_BITS                   0
1093 #define GB_SERIAL_1_5_STOP_BITS                 1
1094 #define GB_SERIAL_2_STOP_BITS                   2
1095
1096         __u8    parity;
1097 #define GB_SERIAL_NO_PARITY                     0
1098 #define GB_SERIAL_ODD_PARITY                    1
1099 #define GB_SERIAL_EVEN_PARITY                   2
1100 #define GB_SERIAL_MARK_PARITY                   3
1101 #define GB_SERIAL_SPACE_PARITY                  4
1102
1103         __u8    data_bits;
1104 } __packed;
1105
1106 /* output control lines */
1107 #define GB_UART_CTRL_DTR                        0x01
1108 #define GB_UART_CTRL_RTS                        0x02
1109
1110 struct gb_uart_set_control_line_state_request {
1111         __u8    control;
1112 } __packed;
1113
1114 struct gb_uart_set_break_request {
1115         __u8    state;
1116 } __packed;
1117
1118 /* input control lines and line errors */
1119 #define GB_UART_CTRL_DCD                        0x01
1120 #define GB_UART_CTRL_DSR                        0x02
1121 #define GB_UART_CTRL_RI                         0x04
1122
1123 struct gb_uart_serial_state_request {
1124         __u8    control;
1125 } __packed;
1126
1127 /* Loopback */
1128
1129 /* Version of the Greybus loopback protocol we support */
1130 #define GB_LOOPBACK_VERSION_MAJOR               0x00
1131 #define GB_LOOPBACK_VERSION_MINOR               0x01
1132
1133 /* Greybus loopback request types */
1134 #define GB_LOOPBACK_TYPE_PING                   0x02
1135 #define GB_LOOPBACK_TYPE_TRANSFER               0x03
1136 #define GB_LOOPBACK_TYPE_SINK                   0x04
1137
1138 /*
1139  * Loopback request/response header format should be identical
1140  * to simplify bandwidth and data movement analysis.
1141  */
1142 struct gb_loopback_transfer_request {
1143         __le32  len;
1144         __le32  reserved0;
1145         __le32  reserved1;
1146         __u8    data[0];
1147 } __packed;
1148
1149 struct gb_loopback_transfer_response {
1150         __le32  len;
1151         __le32  reserved0;
1152         __le32  reserved1;
1153         __u8    data[0];
1154 } __packed;
1155
1156 /* SDIO */
1157 /* Version of the Greybus sdio protocol we support */
1158 #define GB_SDIO_VERSION_MAJOR           0x00
1159 #define GB_SDIO_VERSION_MINOR           0x01
1160
1161 /* Greybus SDIO operation types */
1162 #define GB_SDIO_TYPE_GET_CAPABILITIES           0x02
1163 #define GB_SDIO_TYPE_SET_IOS                    0x03
1164 #define GB_SDIO_TYPE_COMMAND                    0x04
1165 #define GB_SDIO_TYPE_TRANSFER                   0x05
1166 #define GB_SDIO_TYPE_EVENT                      0x06
1167
1168 /* get caps response: request has no payload */
1169 struct gb_sdio_get_caps_response {
1170         __le32  caps;
1171 #define GB_SDIO_CAP_NONREMOVABLE        0x00000001
1172 #define GB_SDIO_CAP_4_BIT_DATA          0x00000002
1173 #define GB_SDIO_CAP_8_BIT_DATA          0x00000004
1174 #define GB_SDIO_CAP_MMC_HS              0x00000008
1175 #define GB_SDIO_CAP_SD_HS               0x00000010
1176 #define GB_SDIO_CAP_ERASE               0x00000020
1177 #define GB_SDIO_CAP_1_2V_DDR            0x00000040
1178 #define GB_SDIO_CAP_1_8V_DDR            0x00000080
1179 #define GB_SDIO_CAP_POWER_OFF_CARD      0x00000100
1180 #define GB_SDIO_CAP_UHS_SDR12           0x00000200
1181 #define GB_SDIO_CAP_UHS_SDR25           0x00000400
1182 #define GB_SDIO_CAP_UHS_SDR50           0x00000800
1183 #define GB_SDIO_CAP_UHS_SDR104          0x00001000
1184 #define GB_SDIO_CAP_UHS_DDR50           0x00002000
1185 #define GB_SDIO_CAP_DRIVER_TYPE_A       0x00004000
1186 #define GB_SDIO_CAP_DRIVER_TYPE_C       0x00008000
1187 #define GB_SDIO_CAP_DRIVER_TYPE_D       0x00010000
1188 #define GB_SDIO_CAP_HS200_1_2V          0x00020000
1189 #define GB_SDIO_CAP_HS200_1_8V          0x00040000
1190 #define GB_SDIO_CAP_HS400_1_2V          0x00080000
1191 #define GB_SDIO_CAP_HS400_1_8V          0x00100000
1192
1193         /* see possible values below at vdd */
1194         __le32 ocr;
1195         __le16 max_blk_count;
1196         __le16 max_blk_size;
1197         __le32 f_min;
1198         __le32 f_max;
1199 } __packed;
1200
1201 /* set ios request: response has no payload */
1202 struct gb_sdio_set_ios_request {
1203         __le32  clock;
1204         __le32  vdd;
1205 #define GB_SDIO_VDD_165_195     0x00000001
1206 #define GB_SDIO_VDD_20_21       0x00000002
1207 #define GB_SDIO_VDD_21_22       0x00000004
1208 #define GB_SDIO_VDD_22_23       0x00000008
1209 #define GB_SDIO_VDD_23_24       0x00000010
1210 #define GB_SDIO_VDD_24_25       0x00000020
1211 #define GB_SDIO_VDD_25_26       0x00000040
1212 #define GB_SDIO_VDD_26_27       0x00000080
1213 #define GB_SDIO_VDD_27_28       0x00000100
1214 #define GB_SDIO_VDD_28_29       0x00000200
1215 #define GB_SDIO_VDD_29_30       0x00000400
1216 #define GB_SDIO_VDD_30_31       0x00000800
1217 #define GB_SDIO_VDD_31_32       0x00001000
1218 #define GB_SDIO_VDD_32_33       0x00002000
1219 #define GB_SDIO_VDD_33_34       0x00004000
1220 #define GB_SDIO_VDD_34_35       0x00008000
1221 #define GB_SDIO_VDD_35_36       0x00010000
1222
1223         __u8    bus_mode;
1224 #define GB_SDIO_BUSMODE_OPENDRAIN       0x00
1225 #define GB_SDIO_BUSMODE_PUSHPULL        0x01
1226
1227         __u8    power_mode;
1228 #define GB_SDIO_POWER_OFF       0x00
1229 #define GB_SDIO_POWER_UP        0x01
1230 #define GB_SDIO_POWER_ON        0x02
1231 #define GB_SDIO_POWER_UNDEFINED 0x03
1232
1233         __u8    bus_width;
1234 #define GB_SDIO_BUS_WIDTH_1     0x00
1235 #define GB_SDIO_BUS_WIDTH_4     0x02
1236 #define GB_SDIO_BUS_WIDTH_8     0x03
1237
1238         __u8    timing;
1239 #define GB_SDIO_TIMING_LEGACY           0x00
1240 #define GB_SDIO_TIMING_MMC_HS           0x01
1241 #define GB_SDIO_TIMING_SD_HS            0x02
1242 #define GB_SDIO_TIMING_UHS_SDR12        0x03
1243 #define GB_SDIO_TIMING_UHS_SDR25        0x04
1244 #define GB_SDIO_TIMING_UHS_SDR50        0x05
1245 #define GB_SDIO_TIMING_UHS_SDR104       0x06
1246 #define GB_SDIO_TIMING_UHS_DDR50        0x07
1247 #define GB_SDIO_TIMING_MMC_DDR52        0x08
1248 #define GB_SDIO_TIMING_MMC_HS200        0x09
1249 #define GB_SDIO_TIMING_MMC_HS400        0x0A
1250
1251         __u8    signal_voltage;
1252 #define GB_SDIO_SIGNAL_VOLTAGE_330      0x00
1253 #define GB_SDIO_SIGNAL_VOLTAGE_180      0x01
1254 #define GB_SDIO_SIGNAL_VOLTAGE_120      0x02
1255
1256         __u8    drv_type;
1257 #define GB_SDIO_SET_DRIVER_TYPE_B       0x00
1258 #define GB_SDIO_SET_DRIVER_TYPE_A       0x01
1259 #define GB_SDIO_SET_DRIVER_TYPE_C       0x02
1260 #define GB_SDIO_SET_DRIVER_TYPE_D       0x03
1261 } __packed;
1262
1263 /* command request */
1264 struct gb_sdio_command_request {
1265         __u8    cmd;
1266         __u8    cmd_flags;
1267 #define GB_SDIO_RSP_NONE                0x00
1268 #define GB_SDIO_RSP_PRESENT             0x01
1269 #define GB_SDIO_RSP_136                 0x02
1270 #define GB_SDIO_RSP_CRC                 0x04
1271 #define GB_SDIO_RSP_BUSY                0x08
1272 #define GB_SDIO_RSP_OPCODE              0x10
1273
1274         __u8    cmd_type;
1275 #define GB_SDIO_CMD_AC          0x00
1276 #define GB_SDIO_CMD_ADTC        0x01
1277 #define GB_SDIO_CMD_BC          0x02
1278 #define GB_SDIO_CMD_BCR         0x03
1279
1280         __le32  cmd_arg;
1281         __le16  data_blocks;
1282         __le16  data_blksz;
1283 } __packed;
1284
1285 struct gb_sdio_command_response {
1286         __le32  resp[4];
1287 } __packed;
1288
1289 /* transfer request */
1290 struct gb_sdio_transfer_request {
1291         __u8    data_flags;
1292 #define GB_SDIO_DATA_WRITE      0x01
1293 #define GB_SDIO_DATA_READ       0x02
1294 #define GB_SDIO_DATA_STREAM     0x04
1295
1296         __le16  data_blocks;
1297         __le16  data_blksz;
1298         __u8    data[0];
1299 } __packed;
1300
1301 struct gb_sdio_transfer_response {
1302         __le16  data_blocks;
1303         __le16  data_blksz;
1304         __u8    data[0];
1305 } __packed;
1306
1307 /* event request: generated by module and is defined as unidirectional */
1308 struct gb_sdio_event_request {
1309         __u8    event;
1310 #define GB_SDIO_CARD_INSERTED   0x01
1311 #define GB_SDIO_CARD_REMOVED    0x02
1312 #define GB_SDIO_WP              0x04
1313 } __packed;
1314
1315 /* Camera */
1316
1317 #define GB_CAMERA_VERSION_MAJOR                 0x00
1318 #define GB_CAMERA_VERSION_MINOR                 0x01
1319
1320 /* Greybus Camera request types */
1321 #define GB_CAMERA_TYPE_CAPABILITIES             0x02
1322 #define GB_CAMERA_TYPE_CONFIGURE_STREAMS        0x03
1323 #define GB_CAMERA_TYPE_CAPTURE                  0x04
1324 #define GB_CAMERA_TYPE_FLUSH                    0x05
1325 #define GB_CAMERA_TYPE_METADATA                 0x06
1326
1327 #define GB_CAMERA_MAX_STREAMS                   4
1328 #define GB_CAMERA_MAX_SETTINGS_SIZE             8192
1329
1330 /* Greybus Camera Configure Streams request payload */
1331 struct gb_camera_stream_config_request {
1332         __le16 width;
1333         __le16 height;
1334         __le16 format;
1335         __le16 padding;
1336 } __packed;
1337
1338 struct gb_camera_configure_streams_request {
1339         __u8 num_streams;
1340         __u8 flags;
1341 #define GB_CAMERA_CONFIGURE_STREAMS_TEST_ONLY   0x01
1342         __le16 padding;
1343         struct gb_camera_stream_config_request config[0];
1344 } __packed;
1345
1346 /* Greybus Camera Configure Streams response payload */
1347 struct gb_camera_stream_config_response {
1348         __le16 width;
1349         __le16 height;
1350         __le16 format;
1351         __u8 virtual_channel;
1352         __u8 data_type[2];
1353         __u8 padding[3];
1354         __le32 max_size;
1355 } __packed;
1356
1357 struct gb_camera_configure_streams_response {
1358         __u8 num_streams;
1359         __u8 flags;
1360 #define GB_CAMERA_CONFIGURE_STREAMS_ADJUSTED    0x01
1361         __u8 num_lanes;
1362         __u8 padding;
1363         __le32 bus_freq;
1364         __le32 lines_per_second;
1365         struct gb_camera_stream_config_response config[0];
1366 } __packed;
1367
1368 /* Greybus Camera Capture request payload - response has no payload */
1369 struct gb_camera_capture_request {
1370         __le32 request_id;
1371         __u8 streams;
1372         __u8 padding;
1373         __le16 num_frames;
1374         __u8 settings[0];
1375 } __packed;
1376
1377 /* Greybus Camera Flush response payload - request has no payload */
1378 struct gb_camera_flush_response {
1379         __le32 request_id;
1380 } __packed;
1381
1382 /* Greybus Camera Metadata request payload - operation has no response */
1383 struct gb_camera_metadata_request {
1384         __le32 request_id;
1385         __le16 frame_number;
1386         __u8 stream;
1387         __u8 padding;
1388         __u8 metadata[0];
1389 } __packed;
1390
1391 /* Lights */
1392
1393 #define GB_LIGHTS_VERSION_MAJOR 0x00
1394 #define GB_LIGHTS_VERSION_MINOR 0x01
1395
1396 /* Greybus Lights request types */
1397 #define GB_LIGHTS_TYPE_GET_LIGHTS               0x02
1398 #define GB_LIGHTS_TYPE_GET_LIGHT_CONFIG         0x03
1399 #define GB_LIGHTS_TYPE_GET_CHANNEL_CONFIG       0x04
1400 #define GB_LIGHTS_TYPE_GET_CHANNEL_FLASH_CONFIG 0x05
1401 #define GB_LIGHTS_TYPE_SET_BRIGHTNESS           0x06
1402 #define GB_LIGHTS_TYPE_SET_BLINK                0x07
1403 #define GB_LIGHTS_TYPE_SET_COLOR                0x08
1404 #define GB_LIGHTS_TYPE_SET_FADE                 0x09
1405 #define GB_LIGHTS_TYPE_EVENT                    0x0A
1406 #define GB_LIGHTS_TYPE_SET_FLASH_INTENSITY      0x0B
1407 #define GB_LIGHTS_TYPE_SET_FLASH_STROBE         0x0C
1408 #define GB_LIGHTS_TYPE_SET_FLASH_TIMEOUT        0x0D
1409 #define GB_LIGHTS_TYPE_GET_FLASH_FAULT          0x0E
1410
1411 /* Greybus Light modes */
1412
1413 /*
1414  * if you add any specific mode below, update also the
1415  * GB_CHANNEL_MODE_DEFINED_RANGE value accordingly
1416  */
1417 #define GB_CHANNEL_MODE_NONE            0x00000000
1418 #define GB_CHANNEL_MODE_BATTERY         0x00000001
1419 #define GB_CHANNEL_MODE_POWER           0x00000002
1420 #define GB_CHANNEL_MODE_WIRELESS        0x00000004
1421 #define GB_CHANNEL_MODE_BLUETOOTH       0x00000008
1422 #define GB_CHANNEL_MODE_KEYBOARD        0x00000010
1423 #define GB_CHANNEL_MODE_BUTTONS         0x00000020
1424 #define GB_CHANNEL_MODE_NOTIFICATION    0x00000040
1425 #define GB_CHANNEL_MODE_ATTENTION       0x00000080
1426 #define GB_CHANNEL_MODE_FLASH           0x00000100
1427 #define GB_CHANNEL_MODE_TORCH           0x00000200
1428 #define GB_CHANNEL_MODE_INDICATOR       0x00000400
1429
1430 /* Lights Mode valid bit values */
1431 #define GB_CHANNEL_MODE_DEFINED_RANGE   0x000004FF
1432 #define GB_CHANNEL_MODE_VENDOR_RANGE    0x00F00000
1433
1434 /* Greybus Light Channels Flags */
1435 #define GB_LIGHT_CHANNEL_MULTICOLOR     0x00000001
1436 #define GB_LIGHT_CHANNEL_FADER          0x00000002
1437 #define GB_LIGHT_CHANNEL_BLINK          0x00000004
1438
1439 /* get count of lights in module */
1440 struct gb_lights_get_lights_response {
1441         __u8    lights_count;
1442 } __packed;
1443
1444 /* light config request payload */
1445 struct gb_lights_get_light_config_request {
1446         __u8    id;
1447 } __packed;
1448
1449 /* light config response payload */
1450 struct gb_lights_get_light_config_response {
1451         __u8    channel_count;
1452         __u8    name[32];
1453 } __packed;
1454
1455 /* channel config request payload */
1456 struct gb_lights_get_channel_config_request {
1457         __u8    light_id;
1458         __u8    channel_id;
1459 } __packed;
1460
1461 /* channel flash config request payload */
1462 struct gb_lights_get_channel_flash_config_request {
1463         __u8    light_id;
1464         __u8    channel_id;
1465 } __packed;
1466
1467 /* channel config response payload */
1468 struct gb_lights_get_channel_config_response {
1469         __u8    max_brightness;
1470         __le32  flags;
1471         __le32  color;
1472         __u8    color_name[32];
1473         __le32  mode;
1474         __u8    mode_name[32];
1475 } __packed;
1476
1477 /* channel flash config response payload */
1478 struct gb_lights_get_channel_flash_config_response {
1479         __le32  intensity_min_uA;
1480         __le32  intensity_max_uA;
1481         __le32  intensity_step_uA;
1482         __le32  timeout_min_us;
1483         __le32  timeout_max_us;
1484         __le32  timeout_step_us;
1485 } __packed;
1486
1487 /* blink request payload: response have no payload */
1488 struct gb_lights_blink_request {
1489         __u8    light_id;
1490         __u8    channel_id;
1491         __le16  time_on_ms;
1492         __le16  time_off_ms;
1493 } __packed;
1494
1495 /* set brightness request payload: response have no payload */
1496 struct gb_lights_set_brightness_request {
1497         __u8    light_id;
1498         __u8    channel_id;
1499         __u8    brightness;
1500 } __packed;
1501
1502 /* set color request payload: response have no payload */
1503 struct gb_lights_set_color_request {
1504         __u8    light_id;
1505         __u8    channel_id;
1506         __le32  color;
1507 } __packed;
1508
1509 /* set fade request payload: response have no payload */
1510 struct gb_lights_set_fade_request {
1511         __u8    light_id;
1512         __u8    channel_id;
1513         __u8    fade_in;
1514         __u8    fade_out;
1515 } __packed;
1516
1517 /* event request: generated by module */
1518 struct gb_lights_event_request {
1519         __u8    light_id;
1520         __u8    event;
1521 #define GB_LIGHTS_LIGHT_CONFIG          0x01
1522 } __packed;
1523
1524 /* set flash intensity request payload: response have no payload */
1525 struct gb_lights_set_flash_intensity_request {
1526         __u8    light_id;
1527         __u8    channel_id;
1528         __le32  intensity_uA;
1529 } __packed;
1530
1531 /* set flash strobe state request payload: response have no payload */
1532 struct gb_lights_set_flash_strobe_request {
1533         __u8    light_id;
1534         __u8    channel_id;
1535         __u8    state;
1536 } __packed;
1537
1538 /* set flash timeout request payload: response have no payload */
1539 struct gb_lights_set_flash_timeout_request {
1540         __u8    light_id;
1541         __u8    channel_id;
1542         __le32  timeout_us;
1543 } __packed;
1544
1545 /* get flash fault request payload */
1546 struct gb_lights_get_flash_fault_request {
1547         __u8    light_id;
1548         __u8    channel_id;
1549 } __packed;
1550
1551 /* get flash fault response payload */
1552 struct gb_lights_get_flash_fault_response {
1553         __le32  fault;
1554 #define GB_LIGHTS_FLASH_FAULT_OVER_VOLTAGE              0x00000000
1555 #define GB_LIGHTS_FLASH_FAULT_TIMEOUT                   0x00000001
1556 #define GB_LIGHTS_FLASH_FAULT_OVER_TEMPERATURE          0x00000002
1557 #define GB_LIGHTS_FLASH_FAULT_SHORT_CIRCUIT             0x00000004
1558 #define GB_LIGHTS_FLASH_FAULT_OVER_CURRENT              0x00000008
1559 #define GB_LIGHTS_FLASH_FAULT_INDICATOR                 0x00000010
1560 #define GB_LIGHTS_FLASH_FAULT_UNDER_VOLTAGE             0x00000020
1561 #define GB_LIGHTS_FLASH_FAULT_INPUT_VOLTAGE             0x00000040
1562 #define GB_LIGHTS_FLASH_FAULT_LED_OVER_TEMPERATURE      0x00000080
1563 } __packed;
1564
1565 /* Audio */
1566
1567 /* Version of the Greybus audio protocol we support */
1568 #define GB_AUDIO_VERSION_MAJOR                  0x00
1569 #define GB_AUDIO_VERSION_MINOR                  0x01
1570
1571 #define GB_AUDIO_TYPE_PROTOCOL_VERSION          0x01
1572 #define GB_AUDIO_TYPE_GET_TOPOLOGY_SIZE         0x02
1573 #define GB_AUDIO_TYPE_GET_TOPOLOGY              0x03
1574 #define GB_AUDIO_TYPE_GET_CONTROL               0x04
1575 #define GB_AUDIO_TYPE_SET_CONTROL               0x05
1576 #define GB_AUDIO_TYPE_ENABLE_WIDGET             0x06
1577 #define GB_AUDIO_TYPE_DISABLE_WIDGET            0x07
1578 #define GB_AUDIO_TYPE_GET_PCM                   0x08
1579 #define GB_AUDIO_TYPE_SET_PCM                   0x09
1580 #define GB_AUDIO_TYPE_SET_TX_DATA_SIZE          0x0a
1581 #define GB_AUDIO_TYPE_GET_TX_DELAY              0x0b
1582 #define GB_AUDIO_TYPE_ACTIVATE_TX               0x0c
1583 #define GB_AUDIO_TYPE_DEACTIVATE_TX             0x0d
1584 #define GB_AUDIO_TYPE_SET_RX_DATA_SIZE          0x0e
1585 #define GB_AUDIO_TYPE_GET_RX_DELAY              0x0f
1586 #define GB_AUDIO_TYPE_ACTIVATE_RX               0x10
1587 #define GB_AUDIO_TYPE_DEACTIVATE_RX             0x11
1588 #define GB_AUDIO_TYPE_JACK_EVENT                0x12
1589 #define GB_AUDIO_TYPE_BUTTON_EVENT              0x13
1590 #define GB_AUDIO_TYPE_STREAMING_EVENT           0x14
1591 #define GB_AUDIO_TYPE_SEND_DATA                 0x15
1592
1593 /* Module must be able to buffer 10ms of audio data, minimum */
1594 #define GB_AUDIO_SAMPLE_BUFFER_MIN_US           10000
1595
1596 #define GB_AUDIO_PCM_NAME_MAX                   32
1597 #define AUDIO_DAI_NAME_MAX                      32
1598 #define AUDIO_CONTROL_NAME_MAX                  32
1599 #define AUDIO_CTL_ELEM_NAME_MAX                 44
1600 #define AUDIO_ENUM_NAME_MAX                     64
1601 #define AUDIO_WIDGET_NAME_MAX                   32
1602
1603 /* See SNDRV_PCM_FMTBIT_* in Linux source */
1604 #define GB_AUDIO_PCM_FMT_S8                     BIT(0)
1605 #define GB_AUDIO_PCM_FMT_U8                     BIT(1)
1606 #define GB_AUDIO_PCM_FMT_S16_LE                 BIT(2)
1607 #define GB_AUDIO_PCM_FMT_S16_BE                 BIT(3)
1608 #define GB_AUDIO_PCM_FMT_U16_LE                 BIT(4)
1609 #define GB_AUDIO_PCM_FMT_U16_BE                 BIT(5)
1610 #define GB_AUDIO_PCM_FMT_S24_LE                 BIT(6)
1611 #define GB_AUDIO_PCM_FMT_S24_BE                 BIT(7)
1612 #define GB_AUDIO_PCM_FMT_U24_LE                 BIT(8)
1613 #define GB_AUDIO_PCM_FMT_U24_BE                 BIT(9)
1614 #define GB_AUDIO_PCM_FMT_S32_LE                 BIT(10)
1615 #define GB_AUDIO_PCM_FMT_S32_BE                 BIT(11)
1616 #define GB_AUDIO_PCM_FMT_U32_LE                 BIT(12)
1617 #define GB_AUDIO_PCM_FMT_U32_BE                 BIT(13)
1618
1619 /* See SNDRV_PCM_RATE_* in Linux source */
1620 #define GB_AUDIO_PCM_RATE_5512                  BIT(0)
1621 #define GB_AUDIO_PCM_RATE_8000                  BIT(1)
1622 #define GB_AUDIO_PCM_RATE_11025                 BIT(2)
1623 #define GB_AUDIO_PCM_RATE_16000                 BIT(3)
1624 #define GB_AUDIO_PCM_RATE_22050                 BIT(4)
1625 #define GB_AUDIO_PCM_RATE_32000                 BIT(5)
1626 #define GB_AUDIO_PCM_RATE_44100                 BIT(6)
1627 #define GB_AUDIO_PCM_RATE_48000                 BIT(7)
1628 #define GB_AUDIO_PCM_RATE_64000                 BIT(8)
1629 #define GB_AUDIO_PCM_RATE_88200                 BIT(9)
1630 #define GB_AUDIO_PCM_RATE_96000                 BIT(10)
1631 #define GB_AUDIO_PCM_RATE_176400                BIT(11)
1632 #define GB_AUDIO_PCM_RATE_192000                BIT(12)
1633
1634 #define GB_AUDIO_STREAM_TYPE_CAPTURE            0x1
1635 #define GB_AUDIO_STREAM_TYPE_PLAYBACK           0x2
1636
1637 #define GB_AUDIO_CTL_ELEM_ACCESS_READ           BIT(0)
1638 #define GB_AUDIO_CTL_ELEM_ACCESS_WRITE          BIT(1)
1639
1640 /* See SNDRV_CTL_ELEM_TYPE_* in Linux source */
1641 #define GB_AUDIO_CTL_ELEM_TYPE_BOOLEAN          0x01
1642 #define GB_AUDIO_CTL_ELEM_TYPE_INTEGER          0x02
1643 #define GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED       0x03
1644 #define GB_AUDIO_CTL_ELEM_TYPE_INTEGER64        0x06
1645
1646 /* See SNDRV_CTL_ELEM_IFACE_* in Linux source */
1647 #define GB_AUDIO_CTL_ELEM_IFACE_CARD            0x00
1648 #define GB_AUDIO_CTL_ELEM_IFACE_HWDEP           0x01
1649 #define GB_AUDIO_CTL_ELEM_IFACE_MIXER           0x02
1650 #define GB_AUDIO_CTL_ELEM_IFACE_PCM             0x03
1651 #define GB_AUDIO_CTL_ELEM_IFACE_RAWMIDI         0x04
1652 #define GB_AUDIO_CTL_ELEM_IFACE_TIMER           0x05
1653 #define GB_AUDIO_CTL_ELEM_IFACE_SEQUENCER       0x06
1654
1655 /* SNDRV_CTL_ELEM_ACCESS_* in Linux source */
1656 #define GB_AUDIO_ACCESS_READ                    BIT(0)
1657 #define GB_AUDIO_ACCESS_WRITE                   BIT(1)
1658 #define GB_AUDIO_ACCESS_VOLATILE                BIT(2)
1659 #define GB_AUDIO_ACCESS_TIMESTAMP               BIT(3)
1660 #define GB_AUDIO_ACCESS_TLV_READ                BIT(4)
1661 #define GB_AUDIO_ACCESS_TLV_WRITE               BIT(5)
1662 #define GB_AUDIO_ACCESS_TLV_COMMAND             BIT(6)
1663 #define GB_AUDIO_ACCESS_INACTIVE                BIT(7)
1664 #define GB_AUDIO_ACCESS_LOCK                    BIT(8)
1665 #define GB_AUDIO_ACCESS_OWNER                   BIT(9)
1666
1667 /* enum snd_soc_dapm_type */
1668 #define GB_AUDIO_WIDGET_TYPE_INPUT              0x0
1669 #define GB_AUDIO_WIDGET_TYPE_OUTPUT             0x1
1670 #define GB_AUDIO_WIDGET_TYPE_MUX                0x2
1671 #define GB_AUDIO_WIDGET_TYPE_VIRT_MUX           0x3
1672 #define GB_AUDIO_WIDGET_TYPE_VALUE_MUX          0x4
1673 #define GB_AUDIO_WIDGET_TYPE_MIXER              0x5
1674 #define GB_AUDIO_WIDGET_TYPE_MIXER_NAMED_CTL    0x6
1675 #define GB_AUDIO_WIDGET_TYPE_PGA                0x7
1676 #define GB_AUDIO_WIDGET_TYPE_OUT_DRV            0x8
1677 #define GB_AUDIO_WIDGET_TYPE_ADC                0x9
1678 #define GB_AUDIO_WIDGET_TYPE_DAC                0xa
1679 #define GB_AUDIO_WIDGET_TYPE_MICBIAS            0xb
1680 #define GB_AUDIO_WIDGET_TYPE_MIC                0xc
1681 #define GB_AUDIO_WIDGET_TYPE_HP                 0xd
1682 #define GB_AUDIO_WIDGET_TYPE_SPK                0xe
1683 #define GB_AUDIO_WIDGET_TYPE_LINE               0xf
1684 #define GB_AUDIO_WIDGET_TYPE_SWITCH             0x10
1685 #define GB_AUDIO_WIDGET_TYPE_VMID               0x11
1686 #define GB_AUDIO_WIDGET_TYPE_PRE                0x12
1687 #define GB_AUDIO_WIDGET_TYPE_POST               0x13
1688 #define GB_AUDIO_WIDGET_TYPE_SUPPLY             0x14
1689 #define GB_AUDIO_WIDGET_TYPE_REGULATOR_SUPPLY   0x15
1690 #define GB_AUDIO_WIDGET_TYPE_CLOCK_SUPPLY       0x16
1691 #define GB_AUDIO_WIDGET_TYPE_AIF_IN             0x17
1692 #define GB_AUDIO_WIDGET_TYPE_AIF_OUT            0x18
1693 #define GB_AUDIO_WIDGET_TYPE_SIGGEN             0x19
1694 #define GB_AUDIO_WIDGET_TYPE_DAI_IN             0x1a
1695 #define GB_AUDIO_WIDGET_TYPE_DAI_OUT            0x1b
1696 #define GB_AUDIO_WIDGET_TYPE_DAI_LINK           0x1c
1697
1698 #define GB_AUDIO_WIDGET_STATE_DISABLED          0x01
1699 #define GB_AUDIO_WIDGET_STATE_ENAABLED          0x02
1700
1701 #define GB_AUDIO_JACK_EVENT_INSERTION           0x1
1702 #define GB_AUDIO_JACK_EVENT_REMOVAL             0x2
1703
1704 #define GB_AUDIO_BUTTON_EVENT_PRESS             0x1
1705 #define GB_AUDIO_BUTTON_EVENT_RELEASE           0x2
1706
1707 #define GB_AUDIO_STREAMING_EVENT_UNSPECIFIED    0x1
1708 #define GB_AUDIO_STREAMING_EVENT_HALT           0x2
1709 #define GB_AUDIO_STREAMING_EVENT_INTERNAL_ERROR 0x3
1710 #define GB_AUDIO_STREAMING_EVENT_PROTOCOL_ERROR 0x4
1711 #define GB_AUDIO_STREAMING_EVENT_FAILURE        0x5
1712 #define GB_AUDIO_STREAMING_EVENT_UNDERRUN       0x6
1713 #define GB_AUDIO_STREAMING_EVENT_OVERRUN        0x7
1714 #define GB_AUDIO_STREAMING_EVENT_CLOCKING       0x8
1715 #define GB_AUDIO_STREAMING_EVENT_DATA_LEN       0x9
1716
1717 #define GB_AUDIO_INVALID_INDEX                  0xff
1718
1719 struct gb_audio_pcm {
1720         __u8    stream_name[GB_AUDIO_PCM_NAME_MAX];
1721         __le32  formats;        /* GB_AUDIO_PCM_FMT_* */
1722         __le32  rates;          /* GB_AUDIO_PCM_RATE_* */
1723         __u8    chan_min;
1724         __u8    chan_max;
1725         __u8    sig_bits;       /* number of bits of content */
1726 } __packed;
1727
1728 struct gb_audio_dai {
1729         __u8                    name[AUDIO_DAI_NAME_MAX];
1730         __le16                  data_cport;
1731         struct gb_audio_pcm     capture;
1732         struct gb_audio_pcm     playback;
1733 } __packed;
1734
1735 struct gb_audio_integer {
1736         __le32  min;
1737         __le32  max;
1738         __le32  step;
1739 } __packed;
1740
1741 struct gb_audio_integer64 {
1742         __le64  min;
1743         __le64  max;
1744         __le64  step;
1745 } __packed;
1746
1747 struct gb_audio_enumerated {
1748         __le32  items;
1749         __le16  names_length;
1750         __u8    names[0];
1751 } __packed;
1752
1753 struct gb_audio_ctl_elem_info { /* See snd_ctl_elem_info in Linux source */
1754         __u8            type;           /* GB_AUDIO_CTL_ELEM_TYPE_* */
1755         __le16          dimen[4];
1756         union {
1757                 struct gb_audio_integer         integer;
1758                 struct gb_audio_integer64       integer64;
1759                 struct gb_audio_enumerated      enumerated;
1760         } value;
1761 } __packed;
1762
1763 struct gb_audio_ctl_elem_value { /* See snd_ctl_elem_value in Linux source */
1764         __le64                          timestamp; /* XXX needed? */
1765         union {
1766                 __le32  integer_value[2];       /* consider CTL_DOUBLE_xxx */
1767                 __le64  integer64_value[2];
1768                 __le32  enumerated_item[2];
1769         } value;
1770 } __packed;
1771
1772 struct gb_audio_control {
1773         __u8    name[AUDIO_CONTROL_NAME_MAX];
1774         __u8    id;             /* 0-63 */
1775         __u8    iface;          /* GB_AUDIO_IFACE_* */
1776         __le16  data_cport;
1777         __le32  access;         /* GB_AUDIO_ACCESS_* */
1778         __u8    count;          /* count of same elements */
1779         __u8    count_values;   /* count of values, max=2 for CTL_DOUBLE_xxx */
1780         struct gb_audio_ctl_elem_info   info;
1781 } __packed;
1782
1783 struct gb_audio_widget {
1784         __u8    name[AUDIO_WIDGET_NAME_MAX];
1785         __u8    sname[AUDIO_WIDGET_NAME_MAX];
1786         __u8    id;
1787         __u8    type;           /* GB_AUDIO_WIDGET_TYPE_* */
1788         __u8    state;          /* GB_AUDIO_WIDGET_STATE_* */
1789         __u8    ncontrols;
1790         struct gb_audio_control ctl[0]; /* 'ncontrols' entries */
1791 } __packed;
1792
1793 struct gb_audio_route {
1794         __u8    source_id;      /* widget id */
1795         __u8    destination_id; /* widget id */
1796         __u8    control_id;     /* 0-63 */
1797         __u8    index;          /* Selection within the control */
1798 } __packed;
1799
1800 struct gb_audio_topology {
1801         __u8    num_dais;
1802         __u8    num_controls;
1803         __u8    num_widgets;
1804         __u8    num_routes;
1805         __u32   size_dais;
1806         __u32   size_controls;
1807         __u32   size_widgets;
1808         __u32   size_routes;
1809         /*
1810          * struct gb_audio_dai          dai[num_dais];
1811          * struct gb_audio_control      controls[num_controls];
1812          * struct gb_audio_widget       widgets[num_widgets];
1813          * struct gb_audio_route        routes[num_routes];
1814          */
1815         __u8    data[0];
1816 } __packed;
1817
1818 struct gb_audio_get_topology_size_response {
1819         __le16  size;
1820 } __packed;
1821
1822 struct gb_audio_get_topology_response {
1823         struct gb_audio_topology        topology;
1824 } __packed;
1825
1826 struct gb_audio_get_control_request {
1827         __u8    control_id;
1828         __u8    index;
1829 } __packed;
1830
1831 struct gb_audio_get_control_response {
1832         struct gb_audio_ctl_elem_value  value;
1833 } __packed;
1834
1835 struct gb_audio_set_control_request {
1836         __u8    control_id;
1837         __u8    index;
1838         struct gb_audio_ctl_elem_value  value;
1839 } __packed;
1840
1841 struct gb_audio_enable_widget_request {
1842         __u8    widget_id;
1843 } __packed;
1844
1845 struct gb_audio_disable_widget_request {
1846         __u8    widget_id;
1847 } __packed;
1848
1849 struct gb_audio_get_pcm_request {
1850         __le16  data_cport;
1851 } __packed;
1852
1853 struct gb_audio_get_pcm_response {
1854         __le32  format;
1855         __le32  rate;
1856         __u8    channels;
1857         __u8    sig_bits;
1858 } __packed;
1859
1860 struct gb_audio_set_pcm_request {
1861         __le16  data_cport;
1862         __le32  format;
1863         __le32  rate;
1864         __u8    channels;
1865         __u8    sig_bits;
1866 } __packed;
1867
1868 struct gb_audio_set_tx_data_size_request {
1869         __le16  data_cport;
1870         __le16  size;
1871 } __packed;
1872
1873 struct gb_audio_get_tx_delay_request {
1874         __le16  data_cport;
1875 } __packed;
1876
1877 struct gb_audio_get_tx_delay_response {
1878         __le32  delay;
1879 } __packed;
1880
1881 struct gb_audio_activate_tx_request {
1882         __le16  data_cport;
1883 } __packed;
1884
1885 struct gb_audio_deactivate_tx_request {
1886         __le16  data_cport;
1887 } __packed;
1888
1889 struct gb_audio_set_rx_data_size_request {
1890         __le16  data_cport;
1891         __le16  size;
1892 } __packed;
1893
1894 struct gb_audio_get_rx_delay_request {
1895         __le16  data_cport;
1896 } __packed;
1897
1898 struct gb_audio_get_rx_delay_response {
1899         __le32  delay;
1900 } __packed;
1901
1902 struct gb_audio_activate_rx_request {
1903         __le16  data_cport;
1904 } __packed;
1905
1906 struct gb_audio_deactivate_rx_request {
1907         __le16  data_cport;
1908 } __packed;
1909
1910 struct gb_audio_jack_event_request {
1911         __u8    widget_id;
1912         __u8    widget_type;
1913         __u8    event;
1914 } __packed;
1915
1916 struct gb_audio_button_event_request {
1917         __u8    widget_id;
1918         __u8    button_id;
1919         __u8    event;
1920 } __packed;
1921
1922 struct gb_audio_streaming_event_request {
1923         __le16  data_cport;
1924         __u8    event;
1925 } __packed;
1926
1927 struct gb_audio_send_data_request {
1928         __le64  timestamp;
1929         __u8    data[0];
1930 } __packed;
1931
1932 #endif /* __GREYBUS_PROTOCOLS_H */
1933