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