Commit e217ae76 authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman
Browse files

greybus: control: drop legacy-protocol dependency



Drop dependency on the legacy protocol abstraction.

Instead implement the protocol-specific version request directly, and
use the new interface for managing the control connection.

Note that the version request is being removed from most protocols, but
we need to keep the current request for the control protocol as-is
indefinitely to maintain backwards compatibility (e.g. with the ES2/ES3
bootrom).

Reviewed-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarJohan Hovold <johan@hovoldconsulting.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 6bd6e148
Loading
Loading
Loading
Loading
+48 −24
Original line number Diff line number Diff line
@@ -17,6 +17,43 @@
#define GB_CONTROL_VERSION_MINOR	1


int gb_control_get_version(struct gb_control *control)
{
	struct gb_interface *intf = control->connection->intf;
	struct gb_control_version_request request;
	struct gb_control_version_response response;
	int ret;

	request.major = GB_CONTROL_VERSION_MAJOR;
	request.minor = GB_CONTROL_VERSION_MINOR;

	ret = gb_operation_sync(control->connection,
				GB_CONTROL_TYPE_VERSION,
				&request, sizeof(request), &response,
				sizeof(response));
	if (ret) {
		dev_err(&intf->dev,
				"failed to get control-protocol version: %d\n",
				ret);
		return ret;
	}

	if (response.major > request.major) {
		dev_err(&intf->dev,
				"unsupported major control-protocol version (%u > %u)\n",
				response.major, request.major);
		return -ENOTSUPP;
	}

	control->protocol_major = response.major;
	control->protocol_minor = response.minor;

	dev_dbg(&intf->dev, "%s - %u.%u\n", __func__, response.major,
			response.minor);

	return 0;
}

/* Get Manifest's size from the interface */
int gb_control_get_manifest_size_operation(struct gb_interface *intf)
{
@@ -121,7 +158,7 @@ int gb_control_enable(struct gb_control *control)

	dev_dbg(&control->connection->intf->dev, "%s\n", __func__);

	ret = gb_connection_legacy_init(control->connection);
	ret = gb_connection_enable_tx(control->connection);
	if (ret) {
		dev_err(&control->connection->intf->dev,
				"failed to enable control connection: %d\n",
@@ -129,14 +166,23 @@ int gb_control_enable(struct gb_control *control)
		return ret;
	}

	ret = gb_control_get_version(control);
	if (ret)
		goto err_disable_connection;

	return 0;

err_disable_connection:
	gb_connection_disable(control->connection);

	return ret;
}

void gb_control_disable(struct gb_control *control)
{
	dev_dbg(&control->connection->intf->dev, "%s\n", __func__);

	gb_connection_legacy_exit(control->connection);
	gb_connection_disable(control->connection);
}

void gb_control_destroy(struct gb_control *control)
@@ -144,25 +190,3 @@ void gb_control_destroy(struct gb_control *control)
	gb_connection_destroy(control->connection);
	kfree(control);
}

static int gb_control_connection_init(struct gb_connection *connection)
{
	dev_dbg(&connection->intf->dev, "%s\n", __func__);

	return 0;
}

static void gb_control_connection_exit(struct gb_connection *connection)
{
	dev_dbg(&connection->intf->dev, "%s\n", __func__);
}

static struct gb_protocol control_protocol = {
	.name			= "control",
	.id			= GREYBUS_PROTOCOL_CONTROL,
	.major			= GB_CONTROL_VERSION_MAJOR,
	.minor			= GB_CONTROL_VERSION_MINOR,
	.connection_init	= gb_control_connection_init,
	.connection_exit	= gb_control_connection_exit,
};
gb_builtin_protocol_driver(control_protocol);
+3 −2
Original line number Diff line number Diff line
@@ -12,6 +12,9 @@

struct gb_control {
	struct gb_connection	*connection;

	u8 protocol_major;
	u8 protocol_minor;
};

struct gb_control *gb_control_create(struct gb_interface *intf);
@@ -26,6 +29,4 @@ int gb_control_get_manifest_operation(struct gb_interface *intf, void *manifest,
				      size_t size);
int gb_control_get_interface_version_operation(struct gb_interface *intf);

int gb_control_protocol_init(void);
void gb_control_protocol_exit(void);
#endif /* __CONTROL_H */
+0 −9
Original line number Diff line number Diff line
@@ -234,12 +234,6 @@ static int __init gb_init(void)
		goto error_operation;
	}

	retval = gb_control_protocol_init();
	if (retval) {
		pr_err("gb_control_protocol_init failed\n");
		goto error_control;
	}

	retval = gb_svc_protocol_init();
	if (retval) {
		pr_err("gb_svc_protocol_init failed\n");
@@ -265,8 +259,6 @@ static int __init gb_init(void)
error_firmware:
	gb_svc_protocol_exit();
error_svc:
	gb_control_protocol_exit();
error_control:
	gb_operation_exit();
error_operation:
	gb_hd_exit();
@@ -284,7 +276,6 @@ static void __exit gb_exit(void)
	gb_legacy_exit();
	gb_firmware_protocol_exit();
	gb_svc_protocol_exit();
	gb_control_protocol_exit();
	gb_operation_exit();
	gb_hd_exit();
	bus_unregister(&greybus_bus_type);
+11 −0
Original line number Diff line number Diff line
@@ -116,6 +116,7 @@ struct gb_protocol_version_response {
/* Control Protocol */

/* Greybus control request types */
#define GB_CONTROL_TYPE_VERSION			0x01
#define GB_CONTROL_TYPE_PROBE_AP		0x02
#define GB_CONTROL_TYPE_GET_MANIFEST_SIZE	0x03
#define GB_CONTROL_TYPE_GET_MANIFEST		0x04
@@ -123,6 +124,16 @@ struct gb_protocol_version_response {
#define GB_CONTROL_TYPE_DISCONNECTED		0x06
#define GB_CONTROL_TYPE_INTERFACE_VERSION	0x0a

struct gb_control_version_request {
	__u8	major;
	__u8	minor;
} __packed;

struct gb_control_version_response {
	__u8	major;
	__u8	minor;
} __packed;

/* Control protocol manifest get size request has no payload*/
struct gb_control_get_manifest_size_response {
	__le16			size;