/*
* This file is provided under a dual BSD/GPLv2 license. When using or
* redistributing this file, you may do so under either license.
*
* GPL LICENSE SUMMARY
*
* Copyright(c) 2014 - 2015 Google Inc. All rights reserved.
* Copyright(c) 2014 - 2015 Linaro Ltd. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License version 2 for more details.
*
* BSD LICENSE
*
* Copyright(c) 2014 - 2015 Google Inc. All rights reserved.
* Copyright(c) 2014 - 2015 Linaro Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. or Linaro Ltd. nor the names of
* its contributors may be used to endorse or promote products
* derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
* LINARO LTD. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __GREYBUS_PROTOCOLS_H
#define __GREYBUS_PROTOCOLS_H
/* Fixed IDs for control/svc protocols */
/* Device ID of SVC and AP */
#define GB_DEVICE_ID_SVC 0
#define GB_DEVICE_ID_AP 1
#define GB_DEVICE_ID_MODULES_START 2
/*
* Bundle/cport for control/svc cport: The same bundle/cport is shared by both
* CONTROL and SVC protocols for communication between AP and SVC.
*/
#define GB_SVC_BUNDLE_ID 0
#define GB_SVC_CPORT_ID 0
#define GB_CONTROL_BUNDLE_ID 0
#define GB_CONTROL_CPORT_ID 0
/*
* All operation messages (both requests and responses) begin with
* a header that encodes the size of the message (header included).
* This header also contains a unique identifier, that associates a
* response message with its operation. The header contains an
* operation type field, whose interpretation is dependent on what
* type of protocol is used over the connection. The high bit
* (0x80) of the operation type field is used to indicate whether
* the message is a request (clear) or a response (set).
*
* Response messages include an additional result byte, which
* communicates the result of the corresponding request. A zero
* result value means the operation completed successfully. Any
* other value indicates an error; in this case, the payload of the
* response message (if any) is ignored. The result byte must be
* zero in the header for a request message.
*
* The wire format for all numeric fields in the header is little
* endian. Any operation-specific data begins immediately after the
* header.
*/
struct gb_operation_msg_hdr {
__le16 size; /* Size in bytes of header + payload */
__le16 operation_id; /* Operation unique id */
__u8 type; /* E.g GB_I2C_TYPE_* or GB_GPIO_TYPE_* */
__u8 result; /* Result of request (in responses only) */
__u8 pad[2]; /* must be zero (ignore when read) */
} __packed;
/* Generic request numbers supported by all modules */
#define GB_REQUEST_TYPE_INVALID 0x00
#define GB_REQUEST_TYPE_PROTOCOL_VERSION 0x01
struct gb_protocol_version_request {
__u8 major;
__u8 minor;
} __packed;
struct gb_protocol_version_response {
__u8 major;
__u8 minor;
} __packed;
/* Control Protocol */
/* Version of the Greybus control protocol we support */
#define GB_CONTROL_VERSION_MAJOR 0x00
#define GB_CONTROL_VERSION_MINOR 0x01
/* Greybus control request types */
#define GB_CONTROL_TYPE_PROBE_AP 0x02
#define GB_CONTROL_TYPE_GET_MANIFEST_SIZE 0x03
#define GB_CONTROL_TYPE_GET_MANIFEST 0x04
#define GB_CONTROL_TYPE_CONNECTED 0x05
#define GB_CONTROL_TYPE_DISCONNECTED 0x06
/* Control protocol manifest get size request has no payload*/
struct gb_control_get_manifest_size_response {
__le16 size;
} __packed;
/* Control protocol manifest get request has no payload */
struct gb_control_get_manifest_response {
__u8 data[0];
} __packed;
/* Control protocol [dis]connected request */
struct gb_control_connected_request {
__le16 cport_id;
} __packed;
struct gb_control_disconnected_request {
__le16 cport_id;
} __packed;
/* Control protocol [dis]connected response has no payload */
/* Firmware Protocol */
/* Version of the Greybus firmware protocol we support */
#define GB_FIRMWARE_VERSION_MAJOR 0x00
#define GB_FIRMWARE_VERSION_MINOR 0x01
/* Greybus firmware request types */
#define GB_FIRMWARE_TYPE_FIRMWARE_SIZE 0x02
#define GB_FIRMWARE_TY