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