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