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