greybus: APBridge: move APBridge request protocol to a common .h file
[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 /* Device ID of SVC and AP */
58 #define GB_DEVICE_ID_SVC                        0
59 #define GB_DEVICE_ID_AP                         1
60 #define GB_DEVICE_ID_MODULES_START              2
61
62 /*
63  * Bundle/cport for control/svc cport: The same bundle/cport is shared by both
64  * CONTROL and SVC protocols for communication between AP and SVC.
65  */
66 #define GB_SVC_BUNDLE_ID                        0
67 #define GB_SVC_CPORT_ID                         0
68 #define GB_CONTROL_BUNDLE_ID                    0
69 #define GB_CONTROL_CPORT_ID                     0
70
71
72 /*
73  * All operation messages (both requests and responses) begin with
74  * a header that encodes the size of the message (header included).
75  * This header also contains a unique identifier, that associates a
76  * response message with its operation.  The header contains an
77  * operation type field, whose interpretation is dependent on what
78  * type of protocol is used over the connection.  The high bit
79  * (0x80) of the operation type field is used to indicate whether
80  * the message is a request (clear) or a response (set).
81  *
82  * Response messages include an additional result byte, which
83  * communicates the result of the corresponding request.  A zero
84  * result value means the operation completed successfully.  Any
85  * other value indicates an error; in this case, the payload of the
86  * response message (if any) is ignored.  The result byte must be
87  * zero in the header for a request message.
88  *
89  * The wire format for all numeric fields in the header is little
90  * endian.  Any operation-specific data begins immediately after the
91  * header.
92  */
93 struct gb_operation_msg_hdr {
94         __le16  size;           /* Size in bytes of header + payload */
95         __le16  operation_id;   /* Operation unique id */
96         __u8    type;           /* E.g GB_I2C_TYPE_* or GB_GPIO_TYPE_* */
97         __u8    result;         /* Result of request (in responses only) */
98         __u8    pad[2];         /* must be zero (ignore when read) */
99 } __packed;
100
101
102 /* Generic request numbers supported by all modules */
103 #define GB_REQUEST_TYPE_INVALID                 0x00
104 #define GB_REQUEST_TYPE_PROTOCOL_VERSION        0x01
105
106 struct gb_protocol_version_request {
107         __u8    major;
108         __u8    minor;
109 } __packed;
110
111 struct gb_protocol_version_response {
112         __u8    major;
113         __u8    minor;
114 } __packed;
115
116 /* Control Protocol */
117
118 /* Version of the Greybus control protocol we support */
119 #define GB_CONTROL_VERSION_MAJOR                0x00
120 #define GB_CONTROL_VERSION_MINOR                0x01
121
122 /* Greybus control request types */
123 #define GB_CONTROL_TYPE_PROBE_AP                0x02
124 #define GB_CONTROL_TYPE_GET_MANIFEST_SIZE       0x03
125 #define GB_CONTROL_TYPE_GET_MANIFEST            0x04
126 #define GB_CONTROL_TYPE_CONNECTED               0x05
127 #define GB_CONTROL_TYPE_DISCONNECTED            0x06
128 #define GB_CONTROL_TYPE_INTERFACE_VERSION       0x0a
129
130 /* Control protocol manifest get size request has no payload*/
131 struct gb_control_get_manifest_size_response {
132         __le16                  size;
133 } __packed;
134
135 /* Control protocol manifest get request has no payload */
136 struct gb_control_get_manifest_response {
137         __u8                    data[0];
138 } __packed;
139
140 /* Control protocol [dis]connected request */
141 struct gb_control_connected_request {
142         __le16                  cport_id;
143 } __packed;
144
145 struct gb_control_disconnected_request {
146         __le16                  cport_id;
147 } __packed;
148 /* Control protocol [dis]connected response has no payload */
149
150 /* Control protocol interface version request has no payload */
151 struct gb_control_interface_version_response {
152         __le16                  major;
153         __le16                  minor;
154 } __packed;
155
156
157 /* APBridge protocol */
158
159 /* request APB1 log */
160 #define GB_APB_REQUEST_LOG              0x02
161
162 /* request to map a cport to bulk in and bulk out endpoints */
163 #define GB_APB_REQUEST_EP_MAPPING       0x03
164
165 /* request to get the number of cports available */
166 #define GB_APB_REQUEST_CPORT_COUNT      0x04
167
168 /* request to reset a cport state */
169 #define GB_APB_REQUEST_RESET_CPORT      0x05
170
171 /* request to time the latency of messages on a given cport */
172 #define GB_APB_REQUEST_LATENCY_TAG_EN   0x06
173 #define GB_APB_REQUEST_LATENCY_TAG_DIS  0x07
174
175 /* request to control the CSI transmitter */
176 #define GB_APB_REQUEST_CSI_TX_CONTROL   0x08
177
178
179 /* Firmware Protocol */
180
181 /* Version of the Greybus firmware protocol we support */
182 #define GB_FIRMWARE_VERSION_MAJOR               0x00
183 #define GB_FIRMWARE_VERSION_MINOR               0x01
184
185 /* Greybus firmware request types */
186 #define GB_FIRMWARE_TYPE_FIRMWARE_SIZE          0x02
187 #define GB_FIRMWARE_TYPE_GET_FIRMWARE           0x03
188 #define GB_FIRMWARE_TYPE_READY_TO_BOOT          0x04
189 #define GB_FIRMWARE_TYPE_AP_READY               0x05    /* Request with no-payload */
190 #define GB_FIRMWARE_TYPE_GET_VID_PID            0x06    /* Request with no-payload */
191
192 /* FIXME: remove all ES2-specific identifiers from the kernel */
193 #define ES2_DDBL1_MFR_ID        0x00000126
194 #define ES2_DDBL1_PROD_ID       0x00001000
195
196 /* Greybus firmware boot stages */
197 #define GB_FIRMWARE_BOOT_STAGE_ONE              0x01 /* Reserved for the boot ROM */
198 #define GB_FIRMWARE_BOOT_STAGE_TWO              0x02 /* Firmware package to be loaded by the boot ROM */
199 #define GB_FIRMWARE_BOOT_STAGE_THREE            0x03 /* Module personality package loaded by Stage 2 firmware */
200
201 /* Greybus firmware ready to boot status */
202 #define GB_FIRMWARE_BOOT_STATUS_INVALID         0x00 /* Firmware blob could not be validated */
203 #define GB_FIRMWARE_BOOT_STATUS_INSECURE        0x01 /* Firmware blob is valid but insecure */
204 #define GB_FIRMWARE_BOOT_STATUS_SECURE          0x02 /* Firmware blob is valid and secure */
205
206 /* Max firmware data fetch size in bytes */
207 #define GB_FIRMWARE_FETCH_MAX                   2000
208
209 /* Firmware protocol firmware size request/response */
210 struct gb_firmware_size_request {
211         __u8                    stage;
212 } __packed;
213
214 struct gb_firmware_size_response {
215         __le32                  size;
216 } __packed;
217
218 /* Firmware protocol get firmware request/response */
219 struct gb_firmware_get_firmware_request {
220         __le32                  offset;
221         __le32                  size;
222 } __packed;
223
224 struct gb_firmware_get_firmware_response {
225         __u8                    data[0];
226 } __packed;
227
228 /* Firmware protocol Ready to boot request */
229 struct gb_firmware_ready_to_boot_request {
230         __u8                    status;
231 } __packed;
232 /* Firmware protocol Ready to boot response has no payload */
233
234 /* Firmware protocol get VID/PID request has no payload */
235 struct gb_firmware_get_vid_pid_response {
236         __le32                  vendor_id;
237         __le32                  product_id;
238 } __packed;
239
240
241 /* Power Supply */
242
243 /* Version of the Greybus power supply protocol we support */
244 #define GB_POWER_SUPPLY_VERSION_MAJOR           0x00
245 #define GB_POWER_SUPPLY_VERSION_MINOR           0x01
246
247 /* Greybus power supply request types */
248 #define GB_POWER_SUPPLY_TYPE_GET_SUPPLIES               0x02
249 #define GB_POWER_SUPPLY_TYPE_GET_DESCRIPTION            0x03
250 #define GB_POWER_SUPPLY_TYPE_GET_PROP_DESCRIPTORS       0x04
251 #define GB_POWER_SUPPLY_TYPE_GET_PROPERTY               0x05
252 #define GB_POWER_SUPPLY_TYPE_SET_PROPERTY               0x06
253 #define GB_POWER_SUPPLY_TYPE_EVENT                      0x07
254
255 /* Should match up with battery technologies in linux/power_supply.h */
256 #define GB_POWER_SUPPLY_TECH_UNKNOWN                    0x0000
257 #define GB_POWER_SUPPLY_TECH_NiMH                       0x0001
258 #define GB_POWER_SUPPLY_TECH_LION                       0x0002
259 #define GB_POWER_SUPPLY_TECH_LIPO                       0x0003
260 #define GB_POWER_SUPPLY_TECH_LiFe                       0x0004
261 #define GB_POWER_SUPPLY_TECH_NiCd                       0x0005
262 #define GB_POWER_SUPPLY_TECH_LiMn                       0x0006
263
264 /* Should match up with power supply types in linux/power_supply.h */
265 #define GB_POWER_SUPPLY_UNKNOWN_TYPE                    0x0000
266 #define GB_POWER_SUPPLY_BATTERY_TYPE                    0x0001
267 #define GB_POWER_SUPPLY_UPS_TYPE                        0x0002
268 #define GB_POWER_SUPPLY_MAINS_TYPE                      0x0003
269 #define GB_POWER_SUPPLY_USB_TYPE                        0x0004
270 #define GB_POWER_SUPPLY_USB_DCP_TYPE                    0x0005
271 #define GB_POWER_SUPPLY_USB_CDP_TYPE                    0x0006
272 #define GB_POWER_SUPPLY_USB_ACA_TYPE                    0x0007
273
274 /* Should match up with power supply health in linux/power_supply.h */
275 #define GB_POWER_SUPPLY_HEALTH_UNKNOWN                  0x0000
276 #define GB_POWER_SUPPLY_HEALTH_GOOD                     0x0001
277 #define GB_POWER_SUPPLY_HEALTH_OVERHEAT                 0x0002
278 #define GB_POWER_SUPPLY_HEALTH_DEAD                     0x0003
279 #define GB_POWER_SUPPLY_HEALTH_OVERVOLTAGE              0x0004
280 #define GB_POWER_SUPPLY_HEALTH_UNSPEC_FAILURE           0x0005
281 #define GB_POWER_SUPPLY_HEALTH_COLD                     0x0006
282 #define GB_POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE    0x0007
283 #define GB_POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE      0x0008
284
285 /* Should match up with battery status in linux/power_supply.h */
286 #define GB_POWER_SUPPLY_STATUS_UNKNOWN          0x0000
287 #define GB_POWER_SUPPLY_STATUS_CHARGING         0x0001
288 #define GB_POWER_SUPPLY_STATUS_DISCHARGING      0x0002
289 #define GB_POWER_SUPPLY_STATUS_NOT_CHARGING     0x0003
290 #define GB_POWER_SUPPLY_STATUS_FULL             0x0004
291
292 struct gb_power_supply_get_supplies_response {
293         __u8    supplies_count;
294 } __packed;
295
296 struct gb_power_supply_get_description_request {
297         __u8    psy_id;
298 } __packed;
299
300 struct gb_power_supply_get_description_response {
301         __u8    manufacturer[32];
302         __u8    model[32];
303         __u8    serial_number[32];
304         __le16  type;
305         __u8    properties_count;
306 } __packed;
307
308 struct gb_power_supply_props_desc {
309         __u8    property;
310 #define GB_POWER_SUPPLY_PROP_STATUS                             0x00
311 #define GB_POWER_SUPPLY_PROP_CHARGE_TYPE                        0x01
312 #define GB_POWER_SUPPLY_PROP_HEALTH                             0x02
313 #define GB_POWER_SUPPLY_PROP_PRESENT                            0x03
314 #define GB_POWER_SUPPLY_PROP_ONLINE                             0x04
315 #define GB_POWER_SUPPLY_PROP_AUTHENTIC                          0x05
316 #define GB_POWER_SUPPLY_PROP_TECHNOLOGY                         0x06
317 #define GB_POWER_SUPPLY_PROP_CYCLE_COUNT                        0x07
318 #define GB_POWER_SUPPLY_PROP_VOLTAGE_MAX                        0x08
319 #define GB_POWER_SUPPLY_PROP_VOLTAGE_MIN                        0x09
320 #define GB_POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN                 0x0A
321 #define GB_POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN                 0x0B
322 #define GB_POWER_SUPPLY_PROP_VOLTAGE_NOW                        0x0C
323 #define GB_POWER_SUPPLY_PROP_VOLTAGE_AVG                        0x0D
324 #define GB_POWER_SUPPLY_PROP_VOLTAGE_OCV                        0x0E
325 #define GB_POWER_SUPPLY_PROP_VOLTAGE_BOOT                       0x0F
326 #define GB_POWER_SUPPLY_PROP_CURRENT_MAX                        0x10
327 #define GB_POWER_SUPPLY_PROP_CURRENT_NOW                        0x11
328 #define GB_POWER_SUPPLY_PROP_CURRENT_AVG                        0x12
329 #define GB_POWER_SUPPLY_PROP_CURRENT_BOOT                       0x13
330 #define GB_POWER_SUPPLY_PROP_POWER_NOW                          0x14
331 #define GB_POWER_SUPPLY_PROP_POWER_AVG                          0x15
332 #define GB_POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN                 0x16
333 #define GB_POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN                0x17
334 #define GB_POWER_SUPPLY_PROP_CHARGE_FULL                        0x18
335 #define GB_POWER_SUPPLY_PROP_CHARGE_EMPTY                       0x19
336 #define GB_POWER_SUPPLY_PROP_CHARGE_NOW                         0x1A
337 #define GB_POWER_SUPPLY_PROP_CHARGE_AVG                         0x1B
338 #define GB_POWER_SUPPLY_PROP_CHARGE_COUNTER                     0x1C
339 #define GB_POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT            0x1D
340 #define GB_POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX        0x1E
341 #define GB_POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE            0x1F
342 #define GB_POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX        0x20
343 #define GB_POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT               0x21
344 #define GB_POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX           0x22
345 #define GB_POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT                0x23
346 #define GB_POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN                 0x24
347 #define GB_POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN                0x25
348 #define GB_POWER_SUPPLY_PROP_ENERGY_FULL                        0x26
349 #define GB_POWER_SUPPLY_PROP_ENERGY_EMPTY                       0x27
350 #define GB_POWER_SUPPLY_PROP_ENERGY_NOW                         0x28
351 #define GB_POWER_SUPPLY_PROP_ENERGY_AVG                         0x29
352 #define GB_POWER_SUPPLY_PROP_CAPACITY                           0x2A
353 #define GB_POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN                 0x2B
354 #define GB_POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX                 0x2C
355 #define GB_POWER_SUPPLY_PROP_CAPACITY_LEVEL                     0x2D
356 #define GB_POWER_SUPPLY_PROP_TEMP                               0x2E
357 #define GB_POWER_SUPPLY_PROP_TEMP_MAX                           0x2F
358 #define GB_POWER_SUPPLY_PROP_TEMP_MIN                           0x30
359 #define GB_POWER_SUPPLY_PROP_TEMP_ALERT_MIN                     0x31
360 #define GB_POWER_SUPPLY_PROP_TEMP_ALERT_MAX                     0x32
361 #define GB_POWER_SUPPLY_PROP_TEMP_AMBIENT                       0x33
362 #define GB_POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN             0x34
363 #define GB_POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX             0x35
364 #define GB_POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW                  0x36
365 #define GB_POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG                  0x37
366 #define GB_POWER_SUPPLY_PROP_TIME_TO_FULL_NOW                   0x38
367 #define GB_POWER_SUPPLY_PROP_TIME_TO_FULL_AVG                   0x39
368 #define GB_POWER_SUPPLY_PROP_TYPE                               0x3A
369 #define GB_POWER_SUPPLY_PROP_SCOPE                              0x3B
370 #define GB_POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT                0x3C
371 #define GB_POWER_SUPPLY_PROP_CALIBRATE                          0x3D
372         __u8    is_writeable;
373 } __packed;
374
375 struct gb_power_supply_get_property_descriptors_request {
376         __u8    psy_id;
377 } __packed;
378
379 struct gb_power_supply_get_property_descriptors_response {
380         __u8    properties_count;
381         struct gb_power_supply_props_desc props[];
382 } __packed;
383
384 struct gb_power_supply_get_property_request {
385         __u8    psy_id;
386         __u8    property;
387 } __packed;
388
389 struct gb_power_supply_get_property_response {
390         __le32  prop_val;
391 };
392
393 struct gb_power_supply_set_property_request {
394         __u8    psy_id;
395         __u8    property;
396         __le32  prop_val;
397 } __packed;
398
399 struct gb_power_supply_event_request {
400         __u8    psy_id;
401         __u8    event;
402 #define GB_POWER_SUPPLY_UPDATE          0x01
403 } __packed;
404
405
406 /* HID */
407
408 /* Version of the Greybus hid protocol we support */
409 #define GB_HID_VERSION_MAJOR            0x00
410 #define GB_HID_VERSION_MINOR            0x01
411
412 /* Greybus HID operation types */
413 #define GB_HID_TYPE_GET_DESC            0x02
414 #define GB_HID_TYPE_GET_REPORT_DESC     0x03
415 #define GB_HID_TYPE_PWR_ON              0x04
416 #define GB_HID_TYPE_PWR_OFF             0x05
417 #define GB_HID_TYPE_GET_REPORT          0x06
418 #define GB_HID_TYPE_SET_REPORT          0x07
419 #define GB_HID_TYPE_IRQ_EVENT           0x08
420
421 /* Report type */
422 #define GB_HID_INPUT_REPORT             0
423 #define GB_HID_OUTPUT_REPORT            1
424 #define GB_HID_FEATURE_REPORT           2
425
426 /* Different request/response structures */
427 /* HID get descriptor response */
428 struct gb_hid_desc_response {
429         __u8                            bLength;
430         __le16                          wReportDescLength;
431         __le16                          bcdHID;
432         __le16                          wProductID;
433         __le16                          wVendorID;
434         __u8                            bCountryCode;
435 } __packed;
436
437 /* HID get report request/response */
438 struct gb_hid_get_report_request {
439         __u8                            report_type;
440         __u8                            report_id;
441 } __packed;
442
443 /* HID set report request */
444 struct gb_hid_set_report_request {
445         __u8                            report_type;
446         __u8                            report_id;
447         __u8                            report[0];
448 } __packed;
449
450 /* HID input report request, via interrupt pipe */
451 struct gb_hid_input_report_request {
452         __u8                            report[0];
453 } __packed;
454
455
456 /* I2C */
457
458 /* Version of the Greybus i2c protocol we support */
459 #define GB_I2C_VERSION_MAJOR            0x00
460 #define GB_I2C_VERSION_MINOR            0x01
461
462 /* Greybus i2c request types */
463 #define GB_I2C_TYPE_FUNCTIONALITY       0x02
464 #define GB_I2C_TYPE_TIMEOUT             0x03
465 #define GB_I2C_TYPE_RETRIES             0x04
466 #define GB_I2C_TYPE_TRANSFER            0x05
467
468 #define GB_I2C_RETRIES_DEFAULT          3
469 #define GB_I2C_TIMEOUT_DEFAULT          1000    /* milliseconds */
470
471 /* functionality request has no payload */
472 struct gb_i2c_functionality_response {
473         __le32  functionality;
474 } __packed;
475
476 struct gb_i2c_timeout_request {
477         __le16  msec;
478 } __packed;
479 /* timeout response has no payload */
480
481 struct gb_i2c_retries_request {
482         __u8    retries;
483 } __packed;
484 /* retries response has no payload */
485
486 /*
487  * Outgoing data immediately follows the op count and ops array.
488  * The data for each write (master -> slave) op in the array is sent
489  * in order, with no (e.g. pad) bytes separating them.
490  *
491  * Short reads cause the entire transfer request to fail So response
492  * payload consists only of bytes read, and the number of bytes is
493  * exactly what was specified in the corresponding op.  Like
494  * outgoing data, the incoming data is in order and contiguous.
495  */
496 struct gb_i2c_transfer_op {
497         __le16  addr;
498         __le16  flags;
499         __le16  size;
500 } __packed;
501
502 struct gb_i2c_transfer_request {
503         __le16                          op_count;
504         struct gb_i2c_transfer_op       ops[0];         /* op_count of these */
505 } __packed;
506 struct gb_i2c_transfer_response {
507         __u8                            data[0];        /* inbound data */
508 } __packed;
509
510
511 /* GPIO */
512
513 /* Version of the Greybus GPIO protocol we support */
514 #define GB_GPIO_VERSION_MAJOR           0x00
515 #define GB_GPIO_VERSION_MINOR           0x01
516
517 /* Greybus GPIO request types */
518 #define GB_GPIO_TYPE_LINE_COUNT         0x02
519 #define GB_GPIO_TYPE_ACTIVATE           0x03
520 #define GB_GPIO_TYPE_DEACTIVATE         0x04
521 #define GB_GPIO_TYPE_GET_DIRECTION      0x05
522 #define GB_GPIO_TYPE_DIRECTION_IN       0x06
523 #define GB_GPIO_TYPE_DIRECTION_OUT      0x07
524 #define GB_GPIO_TYPE_GET_VALUE          0x08
525 #define GB_GPIO_TYPE_SET_VALUE          0x09
526 #define GB_GPIO_TYPE_SET_DEBOUNCE       0x0a
527 #define GB_GPIO_TYPE_IRQ_TYPE           0x0b
528 #define GB_GPIO_TYPE_IRQ_MASK           0x0c
529 #define GB_GPIO_TYPE_IRQ_UNMASK         0x0d
530 #define GB_GPIO_TYPE_IRQ_EVENT          0x0e
531
532 #define GB_GPIO_IRQ_TYPE_NONE           0x00
533 #define GB_GPIO_IRQ_TYPE_EDGE_RISING    0x01
534 #define GB_GPIO_IRQ_TYPE_EDGE_FALLING   0x02
535 #define GB_GPIO_IRQ_TYPE_EDGE_BOTH      0x03
536 #define GB_GPIO_IRQ_TYPE_LEVEL_HIGH     0x04
537 #define GB_GPIO_IRQ_TYPE_LEVEL_LOW      0x08
538
539 /* line count request has no payload */
540 struct gb_gpio_line_count_response {
541         __u8    count;
542 } __packed;
543
544 struct gb_gpio_activate_request {
545         __u8    which;
546 } __packed;
547 /* activate response has no payload */
548
549 struct gb_gpio_deactivate_request {
550         __u8    which;
551 } __packed;
552 /* deactivate response has no payload */
553
554 struct gb_gpio_get_direction_request {
555         __u8    which;
556 } __packed;
557 struct gb_gpio_get_direction_response {
558         __u8    direction;
559 } __packed;
560
561 struct gb_gpio_direction_in_request {
562         __u8    which;
563 } __packed;
564 /* direction in response has no payload */
565
566 struct gb_gpio_direction_out_request {
567         __u8    which;
568         __u8    value;
569 } __packed;
570 /* direction out response has no payload */
571
572 struct gb_gpio_get_value_request {
573         __u8    which;
574 } __packed;
575 struct gb_gpio_get_value_response {
576         __u8    value;
577 } __packed;
578
579 struct gb_gpio_set_value_request {
580         __u8    which;
581         __u8    value;
582 } __packed;
583 /* set value response has no payload */
584
585 struct gb_gpio_set_debounce_request {
586         __u8    which;
587         __le16  usec;
588 } __packed;
589 /* debounce response has no payload */
590
591 struct gb_gpio_irq_type_request {
592         __u8    which;
593         __u8    type;
594 } __packed;
595 /* irq type response has no payload */
596
597 struct gb_gpio_irq_mask_request {
598         __u8    which;
599 } __packed;
600 /* irq mask response has no payload */
601
602 struct gb_gpio_irq_unmask_request {
603         __u8    which;
604 } __packed;
605 /* irq unmask response has no payload */
606
607 /* irq event requests originate on another module and are handled on the AP */
608 struct gb_gpio_irq_event_request {
609         __u8    which;
610 } __packed;
611 /* irq event has no response */
612
613
614 /* PWM */
615
616 /* Version of the Greybus PWM protocol we support */
617 #define GB_PWM_VERSION_MAJOR            0x00
618 #define GB_PWM_VERSION_MINOR            0x01
619
620 /* Greybus PWM operation types */
621 #define GB_PWM_TYPE_PWM_COUNT           0x02
622 #define GB_PWM_TYPE_ACTIVATE            0x03
623 #define GB_PWM_TYPE_DEACTIVATE          0x04
624 #define GB_PWM_TYPE_CONFIG              0x05
625 #define GB_PWM_TYPE_POLARITY            0x06
626 #define GB_PWM_TYPE_ENABLE              0x07
627 #define GB_PWM_TYPE_DISABLE             0x08
628
629 /* pwm count request has no payload */
630 struct gb_pwm_count_response {
631         __u8    count;
632 } __packed;
633
634 struct gb_pwm_activate_request {
635         __u8    which;
636 } __packed;
637
638 struct gb_pwm_deactivate_request {
639         __u8    which;
640 } __packed;
641
642 struct gb_pwm_config_request {
643         __u8    which;
644         __le32  duty;
645         __le32  period;
646 } __packed;
647
648 struct gb_pwm_polarity_request {
649         __u8    which;
650         __u8    polarity;
651 } __packed;
652
653 struct gb_pwm_enable_request {
654         __u8    which;
655 } __packed;
656
657 struct gb_pwm_disable_request {
658         __u8    which;
659 } __packed;
660
661 /* SPI */
662
663 /* Version of the Greybus spi protocol we support */
664 #define GB_SPI_VERSION_MAJOR            0x00
665 #define GB_SPI_VERSION_MINOR            0x01
666
667 /* Should match up with modes in linux/spi/spi.h */
668 #define GB_SPI_MODE_CPHA                0x01            /* clock phase */
669 #define GB_SPI_MODE_CPOL                0x02            /* clock polarity */
670 #define GB_SPI_MODE_MODE_0              (0|0)           /* (original MicroWire) */
671 #define GB_SPI_MODE_MODE_1              (0|GB_SPI_MODE_CPHA)
672 #define GB_SPI_MODE_MODE_2              (GB_SPI_MODE_CPOL|0)
673 #define GB_SPI_MODE_MODE_3              (GB_SPI_MODE_CPOL|GB_SPI_MODE_CPHA)
674 #define GB_SPI_MODE_CS_HIGH             0x04            /* chipselect active high? */
675 #define GB_SPI_MODE_LSB_FIRST           0x08            /* per-word bits-on-wire */
676 #define GB_SPI_MODE_3WIRE               0x10            /* SI/SO signals shared */
677 #define GB_SPI_MODE_LOOP                0x20            /* loopback mode */
678 #define GB_SPI_MODE_NO_CS               0x40            /* 1 dev/bus, no chipselect */
679 #define GB_SPI_MODE_READY               0x80            /* slave pulls low to pause */
680
681 /* Should match up with flags in linux/spi/spi.h */
682 #define GB_SPI_FLAG_HALF_DUPLEX         BIT(0)          /* can't do full duplex */
683 #define GB_SPI_FLAG_NO_RX               BIT(1)          /* can't do buffer read */
684 #define GB_SPI_FLAG_NO_TX               BIT(2)          /* can't do buffer write */
685
686 /* Greybus spi operation types */
687 #define GB_SPI_TYPE_MASTER_CONFIG       0x02
688 #define GB_SPI_TYPE_DEVICE_CONFIG       0x03
689 #define GB_SPI_TYPE_TRANSFER            0x04
690
691 /* mode request has no payload */
692 struct gb_spi_master_config_response {
693         __le32  bits_per_word_mask;
694         __le32  min_speed_hz;
695         __le32  max_speed_hz;
696         __le16  mode;
697         __le16  flags;
698         __u8    num_chipselect;
699 } __packed;
700
701 struct gb_spi_device_config_request {
702         __u8    chip_select;
703 } __packed;
704
705 struct gb_spi_device_config_response {
706         __le16  mode;
707         __u8    bits_per_word;
708         __le32  max_speed_hz;
709         __u8    name[32];
710 } __packed;
711
712 /**
713  * struct gb_spi_transfer - a read/write buffer pair
714  * @speed_hz: Select a speed other than the device default for this transfer. If
715  *      0 the default (from @spi_device) is used.
716  * @len: size of rx and tx buffers (in bytes)
717  * @delay_usecs: microseconds to delay after this transfer before (optionally)
718  *      changing the chipselect status, then starting the next transfer or
719  *      completing this spi_message.
720  * @cs_change: affects chipselect after this transfer completes
721  * @bits_per_word: select a bits_per_word other than the device default for this
722  *      transfer. If 0 the default (from @spi_device) is used.
723  */
724 struct gb_spi_transfer {
725         __le32          speed_hz;
726         __le32          len;
727         __le16          delay_usecs;
728         __u8            cs_change;
729         __u8            bits_per_word;
730         __u8            rdwr;
731 #define GB_SPI_XFER_READ        0x01
732 #define GB_SPI_XFER_WRITE       0x02
733 } __packed;
734
735 struct gb_spi_transfer_request {
736         __u8                    chip_select;    /* of the spi device */
737         __u8                    mode;           /* of the spi device */
738         __le16                  count;
739         struct gb_spi_transfer  transfers[0];   /* count of these */
740 } __packed;
741
742 struct gb_spi_transfer_response {
743         __u8                    data[0];        /* inbound data */
744 } __packed;
745
746 /* Version of the Greybus SVC protocol we support */
747 #define GB_SVC_VERSION_MAJOR            0x00
748 #define GB_SVC_VERSION_MINOR            0x01
749
750 /* Greybus SVC request types */
751 #define GB_SVC_TYPE_SVC_HELLO           0x02
752 #define GB_SVC_TYPE_INTF_DEVICE_ID      0x03
753 #define GB_SVC_TYPE_INTF_HOTPLUG        0x04
754 #define GB_SVC_TYPE_INTF_HOT_UNPLUG     0x05
755 #define GB_SVC_TYPE_INTF_RESET          0x06
756 #define GB_SVC_TYPE_CONN_CREATE         0x07
757 #define GB_SVC_TYPE_CONN_DESTROY        0x08
758 #define GB_SVC_TYPE_DME_PEER_GET        0x09
759 #define GB_SVC_TYPE_DME_PEER_SET        0x0a
760 #define GB_SVC_TYPE_ROUTE_CREATE        0x0b
761 #define GB_SVC_TYPE_ROUTE_DESTROY       0x0c
762 #define GB_SVC_TYPE_INTF_SET_PWRM       0x10
763
764 /*
765  * SVC version request/response has the same payload as
766  * gb_protocol_version_request/response.
767  */
768
769 /* SVC protocol hello request */
770 struct gb_svc_hello_request {
771         __le16                  endo_id;
772         __u8                    interface_id;
773 } __packed;
774 /* hello response has no payload */
775
776 struct gb_svc_intf_device_id_request {
777         __u8    intf_id;
778         __u8    device_id;
779 } __packed;
780 /* device id response has no payload */
781
782 struct gb_svc_intf_hotplug_request {
783         __u8    intf_id;
784         struct {
785                 __le32  ddbl1_mfr_id;
786                 __le32  ddbl1_prod_id;
787                 __le32  ara_vend_id;
788                 __le32  ara_prod_id;
789                 __le64  serial_number;
790         } data;
791 } __packed;
792 /* hotplug response has no payload */
793
794 struct gb_svc_intf_hot_unplug_request {
795         __u8    intf_id;
796 } __packed;
797 /* hot unplug response has no payload */
798
799 struct gb_svc_intf_reset_request {
800         __u8    intf_id;
801 } __packed;
802 /* interface reset response has no payload */
803
804 struct gb_svc_conn_create_request {
805         __u8    intf1_id;
806         __le16  cport1_id;
807         __u8    intf2_id;
808         __le16  cport2_id;
809         __u8    tc;
810         __u8    flags;
811 } __packed;
812 /* connection create response has no payload */
813
814 struct gb_svc_conn_destroy_request {
815         __u8    intf1_id;
816         __le16  cport1_id;
817         __u8    intf2_id;
818         __le16  cport2_id;
819 } __packed;
820 /* connection destroy response has no payload */
821
822 struct gb_svc_dme_peer_get_request {
823         __u8    intf_id;
824         __le16  attr;
825         __le16  selector;
826 } __packed;
827
828 struct gb_svc_dme_peer_get_response {
829         __le16  result_code;
830         __le32  attr_value;
831 } __packed;
832
833 struct gb_svc_dme_peer_set_request {
834         __u8    intf_id;
835         __le16  attr;
836         __le16  selector;
837         __le32  value;
838 } __packed;
839
840 struct gb_svc_dme_peer_set_response {
841         __le16  result_code;
842 } __packed;
843
844 /* Attributes for peer get/set operations */
845 #define DME_ATTR_SELECTOR_INDEX         0
846 /* FIXME: remove ES2 support and DME_ATTR_T_TST_SRC_INCREMENT */
847 #define DME_ATTR_T_TST_SRC_INCREMENT    0x4083
848 #define DME_ATTR_ES3_INIT_STATUS                0x6101
849
850 /* Return value from init-status attributes listed above */
851 #define DME_DIS_SPI_BOOT_STARTED                0x02
852 #define DME_DIS_TRUSTED_SPI_BOOT_FINISHED       0x03
853 #define DME_DIS_UNTRUSTED_SPI_BOOT_FINISHED     0x04
854 #define DME_DIS_UNIPRO_BOOT_STARTED             0x06
855 #define DME_DIS_FALLBACK_UNIPRO_BOOT_STARTED    0x09
856
857 struct gb_svc_route_create_request {
858         __u8    intf1_id;
859         __u8    dev1_id;
860         __u8    intf2_id;
861         __u8    dev2_id;
862 } __packed;
863 /* route create response has no payload */
864
865 struct gb_svc_route_destroy_request {
866         __u8    intf1_id;
867         __u8    intf2_id;
868 } __packed;
869 /* route destroy response has no payload */
870
871 #define GB_SVC_UNIPRO_FAST_MODE                 0x01
872 #define GB_SVC_UNIPRO_SLOW_MODE                 0x02
873 #define GB_SVC_UNIPRO_FAST_AUTO_MODE            0x04
874 #define GB_SVC_UNIPRO_SLOW_AUTO_MODE            0x05
875 #define GB_SVC_UNIPRO_MODE_UNCHANGED            0x07
876 #define GB_SVC_UNIPRO_HIBERNATE_MODE            0x11
877 #define GB_SVC_UNIPRO_OFF_MODE                  0x12
878
879 #define GB_SVC_PWRM_RXTERMINATION               0x01
880 #define GB_SVC_PWRM_TXTERMINATION               0x02
881 #define GB_SVC_PWRM_LINE_RESET                  0x04
882 #define GB_SVC_PWRM_SCRAMBLING                  0x20
883
884 #define GB_SVC_PWRM_QUIRK_HSSER                 0x00000001
885
886 #define GB_SVC_UNIPRO_HS_SERIES_A               0x01
887 #define GB_SVC_UNIPRO_HS_SERIES_B               0x02
888
889 struct gb_svc_intf_set_pwrm_request {
890         __u8    intf_id;
891         __u8    hs_series;
892         __u8    tx_mode;
893         __u8    tx_gear;
894         __u8    tx_nlanes;
895         __u8    rx_mode;
896         __u8    rx_gear;
897         __u8    rx_nlanes;
898         __u8    flags;
899         __le32  quirks;
900 } __packed;
901
902 struct gb_svc_intf_set_pwrm_response {
903         __le16  result_code;
904 } __packed;
905
906 /* RAW */
907
908 /* Version of the Greybus raw protocol we support */
909 #define GB_RAW_VERSION_MAJOR                    0x00
910 #define GB_RAW_VERSION_MINOR                    0x01
911
912 /* Greybus raw request types */
913 #define GB_RAW_TYPE_SEND                        0x02
914
915 struct gb_raw_send_request {
916         __le32  len;
917         __u8    data[0];
918 } __packed;
919
920
921 /* UART */
922
923 /* Version of the Greybus UART protocol we support */
924 #define GB_UART_VERSION_MAJOR           0x00
925 #define GB_UART_VERSION_MINOR           0x01
926
927 /* Greybus UART operation types */
928 #define GB_UART_TYPE_SEND_DATA                  0x02
929 #define GB_UART_TYPE_RECEIVE_DATA               0x03    /* Unsolicited data */
930 #define GB_UART_TYPE_SET_LINE_CODING            0x04
931 #define GB_UART_TYPE_SET_CONTROL_LINE_STATE     0x05
932 #define GB_UART_TYPE_SEND_BREAK                 0x06
933 #define GB_UART_TYPE_SERIAL_STATE               0x07    /* Unsolicited data */
934
935 /* Represents data from AP -> Module */
936 struct gb_uart_send_data_request {
937         __le16  size;
938         __u8    data[0];
939 } __packed;
940
941 /* recv-data-request flags */
942 #define GB_UART_RECV_FLAG_FRAMING               0x01    /* Framing error */
943 #define GB_UART_RECV_FLAG_PARITY                0x02    /* Parity error */
944 #define GB_UART_RECV_FLAG_OVERRUN               0x04    /* Overrun error */
945 #define GB_UART_RECV_FLAG_BREAK                 0x08    /* Break */
946
947 /* Represents data from Module -> AP */
948 struct gb_uart_recv_data_request {
949         __le16  size;
950         __u8    flags;
951         __u8    data[0];
952 } __packed;
953
954 struct gb_uart_set_line_coding_request {
955         __le32  rate;
956         __u8    format;
957 #define GB_SERIAL_1_STOP_BITS                   0
958 #define GB_SERIAL_1_5_STOP_BITS                 1
959 #define GB_SERIAL_2_STOP_BITS                   2
960
961         __u8    parity;
962 #define GB_SERIAL_NO_PARITY                     0
963 #define GB_SERIAL_ODD_PARITY                    1
964 #define GB_SERIAL_EVEN_PARITY                   2
965 #define GB_SERIAL_MARK_PARITY                   3
966 #define GB_SERIAL_SPACE_PARITY                  4
967
968         __u8    data_bits;
969 } __packed;
970
971 /* output control lines */
972 #define GB_UART_CTRL_DTR                        0x01
973 #define GB_UART_CTRL_RTS                        0x02
974
975 struct gb_uart_set_control_line_state_request {
976         __u8    control;
977 } __packed;
978
979 struct gb_uart_set_break_request {
980         __u8    state;
981 } __packed;
982
983 /* input control lines and line errors */
984 #define GB_UART_CTRL_DCD                        0x01
985 #define GB_UART_CTRL_DSR                        0x02
986 #define GB_UART_CTRL_RI                         0x04
987
988 struct gb_uart_serial_state_request {
989         __u8    control;
990 } __packed;
991
992 /* Loopback */
993
994 /* Version of the Greybus loopback protocol we support */
995 #define GB_LOOPBACK_VERSION_MAJOR               0x00
996 #define GB_LOOPBACK_VERSION_MINOR               0x01
997
998 /* Greybus loopback request types */
999 #define GB_LOOPBACK_TYPE_PING                   0x02
1000 #define GB_LOOPBACK_TYPE_TRANSFER               0x03
1001 #define GB_LOOPBACK_TYPE_SINK                   0x04
1002
1003 struct gb_loopback_transfer_request {
1004         __le32  len;
1005         __u8    data[0];
1006 } __packed;
1007
1008 struct gb_loopback_transfer_response {
1009         __le32  len;
1010         __le32  reserved0;
1011         __le32  reserved1;
1012         __u8    data[0];
1013 } __packed;
1014
1015 /* SDIO */
1016 /* Version of the Greybus sdio protocol we support */
1017 #define GB_SDIO_VERSION_MAJOR           0x00
1018 #define GB_SDIO_VERSION_MINOR           0x01
1019
1020 /* Greybus SDIO operation types */
1021 #define GB_SDIO_TYPE_GET_CAPABILITIES           0x02
1022 #define GB_SDIO_TYPE_SET_IOS                    0x03
1023 #define GB_SDIO_TYPE_COMMAND                    0x04
1024 #define GB_SDIO_TYPE_TRANSFER                   0x05
1025 #define GB_SDIO_TYPE_EVENT                      0x06
1026
1027 /* get caps response: request has no payload */
1028 struct gb_sdio_get_caps_response {
1029         __le32  caps;
1030 #define GB_SDIO_CAP_NONREMOVABLE        0x00000001
1031 #define GB_SDIO_CAP_4_BIT_DATA          0x00000002
1032 #define GB_SDIO_CAP_8_BIT_DATA          0x00000004
1033 #define GB_SDIO_CAP_MMC_HS              0x00000008
1034 #define GB_SDIO_CAP_SD_HS               0x00000010
1035 #define GB_SDIO_CAP_ERASE               0x00000020
1036 #define GB_SDIO_CAP_1_2V_DDR            0x00000040
1037 #define GB_SDIO_CAP_1_8V_DDR            0x00000080
1038 #define GB_SDIO_CAP_POWER_OFF_CARD      0x00000100
1039 #define GB_SDIO_CAP_UHS_SDR12           0x00000200
1040 #define GB_SDIO_CAP_UHS_SDR25           0x00000400
1041 #define GB_SDIO_CAP_UHS_SDR50           0x00000800
1042 #define GB_SDIO_CAP_UHS_SDR104          0x00001000
1043 #define GB_SDIO_CAP_UHS_DDR50           0x00002000
1044 #define GB_SDIO_CAP_DRIVER_TYPE_A       0x00004000
1045 #define GB_SDIO_CAP_DRIVER_TYPE_C       0x00008000
1046 #define GB_SDIO_CAP_DRIVER_TYPE_D       0x00010000
1047 #define GB_SDIO_CAP_HS200_1_2V          0x00020000
1048 #define GB_SDIO_CAP_HS200_1_8V          0x00040000
1049 #define GB_SDIO_CAP_HS400_1_2V          0x00080000
1050 #define GB_SDIO_CAP_HS400_1_8V          0x00100000
1051
1052         /* see possible values below at vdd */
1053         __le32 ocr;
1054         __le16 max_blk_count;
1055         __le16 max_blk_size;
1056         __le32 f_min;
1057         __le32 f_max;
1058 } __packed;
1059
1060 /* set ios request: response has no payload */
1061 struct gb_sdio_set_ios_request {
1062         __le32  clock;
1063         __le32  vdd;
1064 #define GB_SDIO_VDD_165_195     0x00000001
1065 #define GB_SDIO_VDD_20_21       0x00000002
1066 #define GB_SDIO_VDD_21_22       0x00000004
1067 #define GB_SDIO_VDD_22_23       0x00000008
1068 #define GB_SDIO_VDD_23_24       0x00000010
1069 #define GB_SDIO_VDD_24_25       0x00000020
1070 #define GB_SDIO_VDD_25_26       0x00000040
1071 #define GB_SDIO_VDD_26_27       0x00000080
1072 #define GB_SDIO_VDD_27_28       0x00000100
1073 #define GB_SDIO_VDD_28_29       0x00000200
1074 #define GB_SDIO_VDD_29_30       0x00000400
1075 #define GB_SDIO_VDD_30_31       0x00000800
1076 #define GB_SDIO_VDD_31_32       0x00001000
1077 #define GB_SDIO_VDD_32_33       0x00002000
1078 #define GB_SDIO_VDD_33_34       0x00004000
1079 #define GB_SDIO_VDD_34_35       0x00008000
1080 #define GB_SDIO_VDD_35_36       0x00010000
1081
1082         __u8    bus_mode;
1083 #define GB_SDIO_BUSMODE_OPENDRAIN       0x00
1084 #define GB_SDIO_BUSMODE_PUSHPULL        0x01
1085
1086         __u8    power_mode;
1087 #define GB_SDIO_POWER_OFF       0x00
1088 #define GB_SDIO_POWER_UP        0x01
1089 #define GB_SDIO_POWER_ON        0x02
1090 #define GB_SDIO_POWER_UNDEFINED 0x03
1091
1092         __u8    bus_width;
1093 #define GB_SDIO_BUS_WIDTH_1     0x00
1094 #define GB_SDIO_BUS_WIDTH_4     0x02
1095 #define GB_SDIO_BUS_WIDTH_8     0x03
1096
1097         __u8    timing;
1098 #define GB_SDIO_TIMING_LEGACY           0x00
1099 #define GB_SDIO_TIMING_MMC_HS           0x01
1100 #define GB_SDIO_TIMING_SD_HS            0x02
1101 #define GB_SDIO_TIMING_UHS_SDR12        0x03
1102 #define GB_SDIO_TIMING_UHS_SDR25        0x04
1103 #define GB_SDIO_TIMING_UHS_SDR50        0x05
1104 #define GB_SDIO_TIMING_UHS_SDR104       0x06
1105 #define GB_SDIO_TIMING_UHS_DDR50        0x07
1106 #define GB_SDIO_TIMING_MMC_DDR52        0x08
1107 #define GB_SDIO_TIMING_MMC_HS200        0x09
1108 #define GB_SDIO_TIMING_MMC_HS400        0x0A
1109
1110         __u8    signal_voltage;
1111 #define GB_SDIO_SIGNAL_VOLTAGE_330      0x00
1112 #define GB_SDIO_SIGNAL_VOLTAGE_180      0x01
1113 #define GB_SDIO_SIGNAL_VOLTAGE_120      0x02
1114
1115         __u8    drv_type;
1116 #define GB_SDIO_SET_DRIVER_TYPE_B       0x00
1117 #define GB_SDIO_SET_DRIVER_TYPE_A       0x01
1118 #define GB_SDIO_SET_DRIVER_TYPE_C       0x02
1119 #define GB_SDIO_SET_DRIVER_TYPE_D       0x03
1120 } __packed;
1121
1122 /* command request */
1123 struct gb_sdio_command_request {
1124         __u8    cmd;
1125         __u8    cmd_flags;
1126 #define GB_SDIO_RSP_NONE                0x00
1127 #define GB_SDIO_RSP_PRESENT             0x01
1128 #define GB_SDIO_RSP_136                 0x02
1129 #define GB_SDIO_RSP_CRC                 0x04
1130 #define GB_SDIO_RSP_BUSY                0x08
1131 #define GB_SDIO_RSP_OPCODE              0x10
1132
1133         __u8    cmd_type;
1134 #define GB_SDIO_CMD_AC          0x00
1135 #define GB_SDIO_CMD_ADTC        0x01
1136 #define GB_SDIO_CMD_BC          0x02
1137 #define GB_SDIO_CMD_BCR         0x03
1138
1139         __le32  cmd_arg;
1140         __le16  data_blocks;
1141         __le16  data_blksz;
1142 } __packed;
1143
1144 struct gb_sdio_command_response {
1145         __le32  resp[4];
1146 } __packed;
1147
1148 /* transfer request */
1149 struct gb_sdio_transfer_request {
1150         __u8    data_flags;
1151 #define GB_SDIO_DATA_WRITE      0x01
1152 #define GB_SDIO_DATA_READ       0x02
1153 #define GB_SDIO_DATA_STREAM     0x04
1154
1155         __le16  data_blocks;
1156         __le16  data_blksz;
1157         __u8    data[0];
1158 } __packed;
1159
1160 struct gb_sdio_transfer_response {
1161         __le16  data_blocks;
1162         __le16  data_blksz;
1163         __u8    data[0];
1164 } __packed;
1165
1166 /* event request: generated by module and is defined as unidirectional */
1167 struct gb_sdio_event_request {
1168         __u8    event;
1169 #define GB_SDIO_CARD_INSERTED   0x01
1170 #define GB_SDIO_CARD_REMOVED    0x02
1171 #define GB_SDIO_WP              0x04
1172 } __packed;
1173
1174 /* Camera */
1175
1176 #define GB_CAMERA_VERSION_MAJOR                 0x00
1177 #define GB_CAMERA_VERSION_MINOR                 0x01
1178
1179 /* Greybus Camera request types */
1180 #define GB_CAMERA_TYPE_CAPABILITIES             0x02
1181 #define GB_CAMERA_TYPE_CONFIGURE_STREAMS        0x03
1182 #define GB_CAMERA_TYPE_CAPTURE                  0x04
1183 #define GB_CAMERA_TYPE_FLUSH                    0x05
1184 #define GB_CAMERA_TYPE_METADATA                 0x06
1185
1186 #define GB_CAMERA_MAX_STREAMS                   4
1187 #define GB_CAMERA_MAX_SETTINGS_SIZE             8192
1188
1189 /* Greybus Camera Configure Streams request payload */
1190 struct gb_camera_stream_config_request {
1191         __le16 width;
1192         __le16 height;
1193         __le16 format;
1194         __le16 padding;
1195 } __packed;
1196
1197 struct gb_camera_configure_streams_request {
1198         __u8 num_streams;
1199         __u8 flags;
1200 #define GB_CAMERA_CONFIGURE_STREAMS_TEST_ONLY   0x01
1201         __le16 padding;
1202         struct gb_camera_stream_config_request config[0];
1203 } __packed;
1204
1205 /* Greybus Camera Configure Streams response payload */
1206 struct gb_camera_stream_config_response {
1207         __le16 width;
1208         __le16 height;
1209         __le16 format;
1210         __u8 virtual_channel;
1211         __u8 data_type[2];
1212         __u8 padding[3];
1213         __le32 max_size;
1214 } __packed;
1215
1216 struct gb_camera_configure_streams_response {
1217         __u8 num_streams;
1218         __u8 flags;
1219 #define GB_CAMERA_CONFIGURE_STREAMS_ADJUSTED    0x01
1220         __le16 padding;
1221         struct gb_camera_stream_config_response config[0];
1222 } __packed;
1223
1224 /* Greybus Camera Capture request payload - response has no payload */
1225 struct gb_camera_capture_request {
1226         __le32 request_id;
1227         __u8 streams;
1228         __u8 padding;
1229         __le16 num_frames;
1230         __u8 settings[0];
1231 } __packed;
1232
1233 /* Greybus Camera Flush response payload - request has no payload */
1234 struct gb_camera_flush_response {
1235         __le32 request_id;
1236 } __packed;
1237
1238 /* Greybus Camera Metadata request payload - operation has no response */
1239 struct gb_camera_metadata_request {
1240         __le32 request_id;
1241         __le16 frame_number;
1242         __u8 stream;
1243         __u8 padding;
1244         __u8 metadata[0];
1245 } __packed;
1246
1247 /* Lights */
1248
1249 #define GB_LIGHTS_VERSION_MAJOR 0x00
1250 #define GB_LIGHTS_VERSION_MINOR 0x01
1251
1252 /* Greybus Lights request types */
1253 #define GB_LIGHTS_TYPE_GET_LIGHTS               0x02
1254 #define GB_LIGHTS_TYPE_GET_LIGHT_CONFIG         0x03
1255 #define GB_LIGHTS_TYPE_GET_CHANNEL_CONFIG       0x04
1256 #define GB_LIGHTS_TYPE_GET_CHANNEL_FLASH_CONFIG 0x05
1257 #define GB_LIGHTS_TYPE_SET_BRIGHTNESS           0x06
1258 #define GB_LIGHTS_TYPE_SET_BLINK                0x07
1259 #define GB_LIGHTS_TYPE_SET_COLOR                0x08
1260 #define GB_LIGHTS_TYPE_SET_FADE                 0x09
1261 #define GB_LIGHTS_TYPE_EVENT                    0x0A
1262 #define GB_LIGHTS_TYPE_SET_FLASH_INTENSITY      0x0B
1263 #define GB_LIGHTS_TYPE_SET_FLASH_STROBE         0x0C
1264 #define GB_LIGHTS_TYPE_SET_FLASH_TIMEOUT        0x0D
1265 #define GB_LIGHTS_TYPE_GET_FLASH_FAULT          0x0E
1266
1267 /* Greybus Light modes */
1268
1269 /*
1270  * if you add any specific mode below, update also the
1271  * GB_CHANNEL_MODE_DEFINED_RANGE value accordingly
1272  */
1273 #define GB_CHANNEL_MODE_NONE            0x00000000
1274 #define GB_CHANNEL_MODE_BATTERY         0x00000001
1275 #define GB_CHANNEL_MODE_POWER           0x00000002
1276 #define GB_CHANNEL_MODE_WIRELESS        0x00000004
1277 #define GB_CHANNEL_MODE_BLUETOOTH       0x00000008
1278 #define GB_CHANNEL_MODE_KEYBOARD        0x00000010
1279 #define GB_CHANNEL_MODE_BUTTONS         0x00000020
1280 #define GB_CHANNEL_MODE_NOTIFICATION    0x00000040
1281 #define GB_CHANNEL_MODE_ATTENTION       0x00000080
1282 #define GB_CHANNEL_MODE_FLASH           0x00000100
1283 #define GB_CHANNEL_MODE_TORCH           0x00000200
1284 #define GB_CHANNEL_MODE_INDICATOR       0x00000400
1285
1286 /* Lights Mode valid bit values */
1287 #define GB_CHANNEL_MODE_DEFINED_RANGE   0x000004FF
1288 #define GB_CHANNEL_MODE_VENDOR_RANGE    0x00F00000
1289
1290 /* Greybus Light Channels Flags */
1291 #define GB_LIGHT_CHANNEL_MULTICOLOR     0x00000001
1292 #define GB_LIGHT_CHANNEL_FADER          0x00000002
1293 #define GB_LIGHT_CHANNEL_BLINK          0x00000004
1294
1295 /* get count of lights in module */
1296 struct gb_lights_get_lights_response {
1297         __u8    lights_count;
1298 } __packed;
1299
1300 /* light config request payload */
1301 struct gb_lights_get_light_config_request {
1302         __u8    id;
1303 } __packed;
1304
1305 /* light config response payload */
1306 struct gb_lights_get_light_config_response {
1307         __u8    channel_count;
1308         __u8    name[32];
1309 } __packed;
1310
1311 /* channel config request payload */
1312 struct gb_lights_get_channel_config_request {
1313         __u8    light_id;
1314         __u8    channel_id;
1315 } __packed;
1316
1317 /* channel flash config request payload */
1318 struct gb_lights_get_channel_flash_config_request {
1319         __u8    light_id;
1320         __u8    channel_id;
1321 } __packed;
1322
1323 /* channel config response payload */
1324 struct gb_lights_get_channel_config_response {
1325         __u8    max_brightness;
1326         __le32  flags;
1327         __le32  color;
1328         __u8    color_name[32];
1329         __le32  mode;
1330         __u8    mode_name[32];
1331 } __packed;
1332
1333 /* channel flash config response payload */
1334 struct gb_lights_get_channel_flash_config_response {
1335         __le32  intensity_min_uA;
1336         __le32  intensity_max_uA;
1337         __le32  intensity_step_uA;
1338         __le32  timeout_min_us;
1339         __le32  timeout_max_us;
1340         __le32  timeout_step_us;
1341 } __packed;
1342
1343 /* blink request payload: response have no payload */
1344 struct gb_lights_blink_request {
1345         __u8    light_id;
1346         __u8    channel_id;
1347         __le16  time_on_ms;
1348         __le16  time_off_ms;
1349 } __packed;
1350
1351 /* set brightness request payload: response have no payload */
1352 struct gb_lights_set_brightness_request {
1353         __u8    light_id;
1354         __u8    channel_id;
1355         __u8    brightness;
1356 } __packed;
1357
1358 /* set color request payload: response have no payload */
1359 struct gb_lights_set_color_request {
1360         __u8    light_id;
1361         __u8    channel_id;
1362         __le32  color;
1363 } __packed;
1364
1365 /* set fade request payload: response have no payload */
1366 struct gb_lights_set_fade_request {
1367         __u8    light_id;
1368         __u8    channel_id;
1369         __u8    fade_in;
1370         __u8    fade_out;
1371 } __packed;
1372
1373 /* event request: generated by module */
1374 struct gb_lights_event_request {
1375         __u8    light_id;
1376         __u8    event;
1377 #define GB_LIGHTS_LIGHT_CONFIG          0x01
1378 } __packed;
1379
1380 /* set flash intensity request payload: response have no payload */
1381 struct gb_lights_set_flash_intensity_request {
1382         __u8    light_id;
1383         __u8    channel_id;
1384         __le32  intensity_uA;
1385 } __packed;
1386
1387 /* set flash strobe state request payload: response have no payload */
1388 struct gb_lights_set_flash_strobe_request {
1389         __u8    light_id;
1390         __u8    channel_id;
1391         __u8    state;
1392 } __packed;
1393
1394 /* set flash timeout request payload: response have no payload */
1395 struct gb_lights_set_flash_timeout_request {
1396         __u8    light_id;
1397         __u8    channel_id;
1398         __le32  timeout_us;
1399 } __packed;
1400
1401 /* get flash fault request payload */
1402 struct gb_lights_get_flash_fault_request {
1403         __u8    light_id;
1404         __u8    channel_id;
1405 } __packed;
1406
1407 /* get flash fault response payload */
1408 struct gb_lights_get_flash_fault_response {
1409         __le32  fault;
1410 #define GB_LIGHTS_FLASH_FAULT_OVER_VOLTAGE              0x00000000
1411 #define GB_LIGHTS_FLASH_FAULT_TIMEOUT                   0x00000001
1412 #define GB_LIGHTS_FLASH_FAULT_OVER_TEMPERATURE          0x00000002
1413 #define GB_LIGHTS_FLASH_FAULT_SHORT_CIRCUIT             0x00000004
1414 #define GB_LIGHTS_FLASH_FAULT_OVER_CURRENT              0x00000008
1415 #define GB_LIGHTS_FLASH_FAULT_INDICATOR                 0x00000010
1416 #define GB_LIGHTS_FLASH_FAULT_UNDER_VOLTAGE             0x00000020
1417 #define GB_LIGHTS_FLASH_FAULT_INPUT_VOLTAGE             0x00000040
1418 #define GB_LIGHTS_FLASH_FAULT_LED_OVER_TEMPERATURE      0x00000080
1419 } __packed;
1420
1421 #endif /* __GREYBUS_PROTOCOLS_H */
1422