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