From f1f6fa44ae49e91c0a5fe9e0c6e5614e6aa22283 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Sat, 8 Aug 2015 08:09:32 +0530
Subject: [PATCH 01/35] greybus: sdio: error out only for smaller payloads
 received

!= was used in place of <, while comparing expected and actual payload
size. The module may be running a higher version of the protocol and
might have some extra fields (towards the end) in the structure, and the
AP needs to ignore them.

This also updates the print (expected-payload-size <
actual-payload-size), when the size doesn't match for requests received
by the module. This gives more details required for debugging.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/sdio.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/sdio.c b/drivers/staging/greybus/sdio.c
index a709bd64f824..345cffff7db0 100644
--- a/drivers/staging/greybus/sdio.c
+++ b/drivers/staging/greybus/sdio.c
@@ -192,8 +192,9 @@ static int gb_sdio_event_recv(u8 type, struct gb_operation *op)
 
 	request = op->request;
 
-	if (request->payload_size != sizeof(*payload)) {
-		dev_err(mmc_dev(host->mmc), "wrong event size received\n");
+	if (request->payload_size < sizeof(*payload)) {
+		dev_err(mmc_dev(host->mmc), "wrong event size received (%zu < %zu)\n",
+			request->payload_size, sizeof(*payload));
 		return -EINVAL;
 	}
 

From d79ae495e2ddb2b6f39376c4eed080dbc1b074d5 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Sat, 8 Aug 2015 10:25:32 +0530
Subject: [PATCH 02/35] greybus: hid: spell fix (s/infomation/information)

Minor spell fix.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/hid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/greybus/hid.c b/drivers/staging/greybus/hid.c
index a367fd5fad70..d423f8eb145e 100644
--- a/drivers/staging/greybus/hid.c
+++ b/drivers/staging/greybus/hid.c
@@ -84,7 +84,7 @@ struct gb_hid {
 
 static DEFINE_MUTEX(gb_hid_open_mutex);
 
-/* Routines to get controller's infomation over greybus */
+/* Routines to get controller's information over greybus */
 
 /* Define get_version() routine */
 define_get_version(gb_hid, HID);

From 8cbd20aa0de89eb344e05d51ae3bedfabeae360a Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Sat, 8 Aug 2015 10:25:33 +0530
Subject: [PATCH 03/35] greybus: battery: Use (already defined) major/minor
 macros

We already have macros for these, use them instead of writing fixed
values.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/battery.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/battery.c b/drivers/staging/greybus/battery.c
index e66623966dc9..43799a357add 100644
--- a/drivers/staging/greybus/battery.c
+++ b/drivers/staging/greybus/battery.c
@@ -372,8 +372,8 @@ static void gb_battery_connection_exit(struct gb_connection *connection)
 static struct gb_protocol battery_protocol = {
 	.name			= "battery",
 	.id			= GREYBUS_PROTOCOL_BATTERY,
-	.major			= 0,
-	.minor			= 1,
+	.major			= GB_BATTERY_VERSION_MAJOR,
+	.minor			= GB_BATTERY_VERSION_MINOR,
 	.connection_init	= gb_battery_connection_init,
 	.connection_exit	= gb_battery_connection_exit,
 	.request_recv		= NULL,	/* no incoming requests */

From 8590ed30be0d3164073d90d1bcf728dd776487c4 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Sat, 8 Aug 2015 10:25:34 +0530
Subject: [PATCH 04/35] greybus: gpio: Use (already defined) major/minor macros

We already have macros for these, use them instead of writing fixed
values.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/gpio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/gpio.c b/drivers/staging/greybus/gpio.c
index caee9d19d723..a5db014eaaf2 100644
--- a/drivers/staging/greybus/gpio.c
+++ b/drivers/staging/greybus/gpio.c
@@ -719,8 +719,8 @@ static void gb_gpio_connection_exit(struct gb_connection *connection)
 static struct gb_protocol gpio_protocol = {
 	.name			= "gpio",
 	.id			= GREYBUS_PROTOCOL_GPIO,
-	.major			= 0,
-	.minor			= 1,
+	.major			= GB_GPIO_VERSION_MAJOR,
+	.minor			= GB_GPIO_VERSION_MINOR,
 	.connection_init	= gb_gpio_connection_init,
 	.connection_exit	= gb_gpio_connection_exit,
 	.request_recv		= gb_gpio_request_recv,

From 34ec36457f360fd2930fbf6e4cdfd6f7bc4d98c1 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Sat, 8 Aug 2015 10:25:35 +0530
Subject: [PATCH 05/35] greybus: hid: Use (already defined) major/minor macros

We already have macros for these, use them instead of writing fixed
values.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/hid.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/hid.c b/drivers/staging/greybus/hid.c
index d423f8eb145e..0baed865b760 100644
--- a/drivers/staging/greybus/hid.c
+++ b/drivers/staging/greybus/hid.c
@@ -523,8 +523,8 @@ static void gb_hid_connection_exit(struct gb_connection *connection)
 static struct gb_protocol hid_protocol = {
 	.name			= "hid",
 	.id			= GREYBUS_PROTOCOL_HID,
-	.major			= 0,
-	.minor			= 1,
+	.major			= GB_HID_VERSION_MAJOR,
+	.minor			= GB_HID_VERSION_MINOR,
 	.connection_init	= gb_hid_connection_init,
 	.connection_exit	= gb_hid_connection_exit,
 	.request_recv		= gb_hid_irq_handler,

From bbd80cc166dc841f6bab7fe721da157c6371e84b Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Sat, 8 Aug 2015 10:25:36 +0530
Subject: [PATCH 06/35] greybus: i2c: Use (already defined) major/minor macros

We already have macros for these, use them instead of writing fixed
values.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/i2c.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/i2c.c b/drivers/staging/greybus/i2c.c
index 9514e69d0d4b..edb675384a71 100644
--- a/drivers/staging/greybus/i2c.c
+++ b/drivers/staging/greybus/i2c.c
@@ -349,8 +349,8 @@ static void gb_i2c_connection_exit(struct gb_connection *connection)
 static struct gb_protocol i2c_protocol = {
 	.name			= "i2c",
 	.id			= GREYBUS_PROTOCOL_I2C,
-	.major			= 0,
-	.minor			= 1,
+	.major			= GB_I2C_VERSION_MAJOR,
+	.minor			= GB_I2C_VERSION_MINOR,
 	.connection_init	= gb_i2c_connection_init,
 	.connection_exit	= gb_i2c_connection_exit,
 	.request_recv		= NULL,	/* no incoming requests */

From 3fb97e43ba4ab094a72d9b9fe165e476e756c4ed Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Sat, 8 Aug 2015 10:25:37 +0530
Subject: [PATCH 07/35] greybus: pwm: Use (already defined) major/minor macros

We already have macros for these, use them instead of writing fixed
values.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/pwm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/pwm.c b/drivers/staging/greybus/pwm.c
index be7131a41a97..c7f8c6338801 100644
--- a/drivers/staging/greybus/pwm.c
+++ b/drivers/staging/greybus/pwm.c
@@ -239,8 +239,8 @@ static void gb_pwm_connection_exit(struct gb_connection *connection)
 static struct gb_protocol pwm_protocol = {
 	.name			= "pwm",
 	.id			= GREYBUS_PROTOCOL_PWM,
-	.major			= 0,
-	.minor			= 1,
+	.major			= GB_PWM_VERSION_MAJOR,
+	.minor			= GB_PWM_VERSION_MINOR,
 	.connection_init	= gb_pwm_connection_init,
 	.connection_exit	= gb_pwm_connection_exit,
 	.request_recv		= NULL, /* no incoming requests */

From 7549219d4ea0a9d8b78c3819dff8dcdb9db14eb1 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Sat, 8 Aug 2015 10:25:38 +0530
Subject: [PATCH 08/35] greybus: spi: Use (already defined) major/minor macros

We already have macros for these, use them instead of writing fixed
values.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/spi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/spi.c b/drivers/staging/greybus/spi.c
index 306fb074c183..77d6bf0b7f13 100644
--- a/drivers/staging/greybus/spi.c
+++ b/drivers/staging/greybus/spi.c
@@ -340,8 +340,8 @@ static void gb_spi_connection_exit(struct gb_connection *connection)
 static struct gb_protocol spi_protocol = {
 	.name			= "spi",
 	.id			= GREYBUS_PROTOCOL_SPI,
-	.major			= 0,
-	.minor			= 1,
+	.major			= GB_SPI_VERSION_MAJOR,
+	.minor			= GB_SPI_VERSION_MINOR,
 	.connection_init	= gb_spi_connection_init,
 	.connection_exit	= gb_spi_connection_exit,
 	.request_recv		= NULL,

From 9475fb5c5ad1d61a37c2bd47fb94dcf55b59aaf2 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Sat, 8 Aug 2015 10:25:39 +0530
Subject: [PATCH 09/35] greybus: uart: Use (already defined) major/minor macros

We already have macros for these, use them instead of writing fixed
values.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/uart.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index 0166c4cdb451..7a51c7c792c9 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -767,8 +767,8 @@ static void gb_tty_exit(void)
 static struct gb_protocol uart_protocol = {
 	.name			= "uart",
 	.id			= GREYBUS_PROTOCOL_UART,
-	.major			= 0,
-	.minor			= 1,
+	.major			= GB_UART_VERSION_MAJOR,
+	.minor			= GB_UART_VERSION_MINOR,
 	.connection_init	= gb_uart_connection_init,
 	.connection_exit	= gb_uart_connection_exit,
 	.request_recv		= gb_uart_request_recv,

From f514b5c31435909960fe32e309d7417c52629cc1 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Sat, 8 Aug 2015 10:25:40 +0530
Subject: [PATCH 10/35] greybus: usb: Use (already defined) major/minor macros

We already have macros for these, use them instead of writing fixed
values.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/usb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/usb.c b/drivers/staging/greybus/usb.c
index 50173b96f712..80c42b20adda 100644
--- a/drivers/staging/greybus/usb.c
+++ b/drivers/staging/greybus/usb.c
@@ -226,8 +226,8 @@ static void gb_usb_connection_exit(struct gb_connection *connection)
 static struct gb_protocol usb_protocol = {
 	.name			= "usb",
 	.id			= GREYBUS_PROTOCOL_USB,
-	.major			= 0,
-	.minor			= 1,
+	.major			= GB_USB_VERSION_MAJOR,
+	.minor			= GB_USB_VERSION_MINOR,
 	.connection_init	= gb_usb_connection_init,
 	.connection_exit	= gb_usb_connection_exit,
 	.request_recv		= NULL,	/* FIXME we have requests!!! */

From f0a1698f18722fccb920448285b8fc87f793870a Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Sat, 8 Aug 2015 10:25:41 +0530
Subject: [PATCH 11/35] greybus: vibrator: Use (already defined) major/minor
 macros

We already have macros for these, use them instead of writing fixed
values.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/vibrator.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/vibrator.c b/drivers/staging/greybus/vibrator.c
index 62b3552006fc..df9c4b14c707 100644
--- a/drivers/staging/greybus/vibrator.c
+++ b/drivers/staging/greybus/vibrator.c
@@ -167,8 +167,8 @@ static void gb_vibrator_connection_exit(struct gb_connection *connection)
 static struct gb_protocol vibrator_protocol = {
 	.name			= "vibrator",
 	.id			= GREYBUS_PROTOCOL_VIBRATOR,
-	.major			= 0,
-	.minor			= 1,
+	.major			= GB_VIBRATOR_VERSION_MAJOR,
+	.minor			= GB_VIBRATOR_VERSION_MINOR,
 	.connection_init	= gb_vibrator_connection_init,
 	.connection_exit	= gb_vibrator_connection_exit,
 	.request_recv		= NULL,	/* no incoming requests */

From 33f06a75eecaa34b43c83f57280c6ef1ffedd101 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Fri, 7 Aug 2015 18:06:43 +0530
Subject: [PATCH 12/35] greybus: svc: Remove FIXME for firmware download

Its handled by the firmware driver now, drop the FIXME comment from svc
code.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/svc.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/greybus/svc.c b/drivers/staging/greybus/svc.c
index 5f2b2b43b939..7ac45a9d95c4 100644
--- a/drivers/staging/greybus/svc.c
+++ b/drivers/staging/greybus/svc.c
@@ -256,7 +256,6 @@ static int gb_svc_intf_hotplug_recv(struct gb_operation *op)
 	ara_vend_id = le32_to_cpu(hotplug->data.ara_vend_id);
 	ara_prod_id = le32_to_cpu(hotplug->data.ara_prod_id);
 
-	// FIXME May require firmware download
 	intf = gb_interface_create(hd, intf_id);
 	if (!intf) {
 		dev_err(dev, "%s: Failed to create interface with id %hhu\n",

From 10c7ae04e36f05a82dd23eb314092c77df2c2049 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:29:18 +0530
Subject: [PATCH 13/35] greybus: audio: Add '<' to the print message for short
 messages

This increases readability a bit more, as it tells which value is actual
size and which one is expected size.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/audio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/greybus/audio.c b/drivers/staging/greybus/audio.c
index 9f5f95913e8f..0e9bec5089b2 100644
--- a/drivers/staging/greybus/audio.c
+++ b/drivers/staging/greybus/audio.c
@@ -357,7 +357,7 @@ static int gb_i2s_mgmt_report_event_recv(u8 type, struct gb_operation *op)
 	}
 
 	if (op->request->payload_size < sizeof(*req)) {
-		dev_err(&connection->dev, "Short request received: %zu, %zu\n",
+		dev_err(&connection->dev, "Short request received (%zu < %zu)\n",
 			op->request->payload_size, sizeof(*req));
 		return -EINVAL;
 	}

From 0c32d2a5b2a6f284efd196d568e1df3db5999c5d Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:29:19 +0530
Subject: [PATCH 14/35] greybus: svc: error out only for smaller payloads
 received

!= was used in place of <, while comparing expected and actual payload
size. The module may be running a higher version of the protocol and
might have some extra fields (towards the end) in the structure, and the
AP needs to ignore them.

This also updates the print (expected-payload-size <
actual-payload-size), when the size doesn't match for requests received
by the module. This gives more details required for debugging.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/svc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/svc.c b/drivers/staging/greybus/svc.c
index 7ac45a9d95c4..17ffb1353fb4 100644
--- a/drivers/staging/greybus/svc.c
+++ b/drivers/staging/greybus/svc.c
@@ -193,8 +193,8 @@ static int gb_svc_hello(struct gb_operation *op)
 	 * SVC sends information about the endo and interface-id on the hello
 	 * request, use that to create an endo.
 	 */
-	if (op->request->payload_size != sizeof(*hello_request)) {
-		dev_err(dev, "%s: Illegal size of hello request (%zu %zu)\n",
+	if (op->request->payload_size < sizeof(*hello_request)) {
+		dev_err(dev, "%s: Illegal size of hello request (%zu < %zu)\n",
 			__func__, op->request->payload_size,
 			sizeof(*hello_request));
 		return -EINVAL;

From 186906590280c907ee497ed5e48bb94926d7b960 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:35:56 +0530
Subject: [PATCH 15/35] greybus: connection: disconnect connection on failures
 during initialization

Its possible for connection_init() to fail, in such cases the
disconnected event must be sent to the module.

It is missing currently, fix it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/connection.c | 44 +++++++++++++++++-----------
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c
index 3b553e682359..7a5840bb8473 100644
--- a/drivers/staging/greybus/connection.c
+++ b/drivers/staging/greybus/connection.c
@@ -330,6 +330,27 @@ void gb_connection_destroy(struct gb_connection *connection)
 	device_unregister(&connection->dev);
 }
 
+static void gb_connection_disconnected(struct gb_connection *connection)
+{
+	struct gb_control *control;
+	int cport_id = connection->intf_cport_id;
+	int ret;
+
+	/*
+	 * Inform Interface about In-active CPorts. We don't need to do this
+	 * operation for control cport.
+	 */
+	if (cport_id == GB_CONTROL_CPORT_ID)
+		return;
+
+	control = connection->bundle->intf->control;
+
+	ret = gb_control_disconnected_operation(control, cport_id);
+	if (ret)
+		dev_warn(&connection->dev,
+			"Failed to disconnect CPort-%d (%d)\n", cport_id, ret);
+}
+
 int gb_connection_init(struct gb_connection *connection)
 {
 	int cport_id = connection->intf_cport_id;
@@ -366,15 +387,18 @@ int gb_connection_init(struct gb_connection *connection)
 		spin_lock_irq(&connection->lock);
 		connection->state = GB_CONNECTION_STATE_ERROR;
 		spin_unlock_irq(&connection->lock);
+		goto disconnect;
 	}
 
+	return 0;
+
+disconnect:
+	gb_connection_disconnected(connection);
 	return ret;
 }
 
 void gb_connection_exit(struct gb_connection *connection)
 {
-	int cport_id = connection->intf_cport_id;
-
 	if (!connection->protocol) {
 		dev_warn(&connection->dev, "exit without protocol.\n");
 		return;
@@ -391,21 +415,7 @@ void gb_connection_exit(struct gb_connection *connection)
 	gb_connection_cancel_operations(connection, -ESHUTDOWN);
 
 	connection->protocol->connection_exit(connection);
-
-	/*
-	 * Inform Interface about In-active CPorts. We don't need to do this
-	 * operation for control cport.
-	 */
-	if (cport_id != GB_CONTROL_CPORT_ID) {
-		struct gb_control *control = connection->bundle->intf->control;
-		int ret;
-
-		ret = gb_control_disconnected_operation(control, cport_id);
-		if (ret)
-			dev_warn(&connection->dev,
-				 "Failed to disconnect CPort-%d (%d)\n",
-				 cport_id, ret);
-	}
+	gb_connection_disconnected(connection);
 }
 
 void gb_hd_connections_exit(struct greybus_host_device *hd)

From 2b11a45d29f52c94fdea1d8f1c7baa25cb7368bb Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:35:57 +0530
Subject: [PATCH 16/35] greybus: define greybus wide protocol request numbers

Some request numbers (like invalid and get_version) are same across all
protocols. Create common macros for them.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/greybus_protocols.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/staging/greybus/greybus_protocols.h b/drivers/staging/greybus/greybus_protocols.h
index 290b85f6ff68..b95d24bd8e62 100644
--- a/drivers/staging/greybus/greybus_protocols.h
+++ b/drivers/staging/greybus/greybus_protocols.h
@@ -99,6 +99,10 @@ struct gb_operation_msg_hdr {
 };
 
 
+/* Generic request numbers supported by all modules */
+#define GB_REQUEST_TYPE_INVALID			0x00
+#define GB_REQUEST_TYPE_PROTOCOL_VERSION	0x01
+
 /* Control Protocol */
 
 /* version request has no payload */

From d653f4b19163aa9f3a8046bd6e895b8615856d11 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:35:58 +0530
Subject: [PATCH 17/35] greybus: connection: Save major/minor supported by
 module

Save major/minor number supported by the module inside connection
structure, as this can be used later.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/connection.h | 2 ++
 drivers/staging/greybus/protocol.c   | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/drivers/staging/greybus/connection.h b/drivers/staging/greybus/connection.h
index f02b9d9fb084..0dbbc202e953 100644
--- a/drivers/staging/greybus/connection.h
+++ b/drivers/staging/greybus/connection.h
@@ -34,6 +34,8 @@ struct gb_connection {
 	u8				protocol_id;
 	u8				major;
 	u8				minor;
+	u8				module_major;
+	u8				module_minor;
 
 	spinlock_t			lock;
 	enum gb_connection_state	state;
diff --git a/drivers/staging/greybus/protocol.c b/drivers/staging/greybus/protocol.c
index 06b4841173ce..ba80f552fa31 100644
--- a/drivers/staging/greybus/protocol.c
+++ b/drivers/staging/greybus/protocol.c
@@ -182,6 +182,9 @@ int gb_protocol_get_version(struct gb_connection *connection, int type,
 		return -ENOTSUPP;
 	}
 
+	connection->module_major = response->major;
+	connection->module_minor = response->minor;
+
 	dev_dbg(&connection->dev, "version_major = %u version_minor = %u\n",
 		response->major, response->minor);
 

From 7ba26a8ced4a391133aa899a61647154d8d4d24c Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:35:59 +0530
Subject: [PATCH 18/35] greybus: connection: request protocol version before
 initializing connection

This can (should) be done from a common place as its required for most
of the protocols. Do it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/connection.c | 31 +++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c
index 7a5840bb8473..b1f1df81be50 100644
--- a/drivers/staging/greybus/connection.c
+++ b/drivers/staging/greybus/connection.c
@@ -382,17 +382,34 @@ int gb_connection_init(struct gb_connection *connection)
 	connection->state = GB_CONNECTION_STATE_ENABLED;
 	spin_unlock_irq(&connection->lock);
 
-	ret = connection->protocol->connection_init(connection);
-	if (ret) {
-		spin_lock_irq(&connection->lock);
-		connection->state = GB_CONNECTION_STATE_ERROR;
-		spin_unlock_irq(&connection->lock);
-		goto disconnect;
+	/*
+	 * Request protocol version supported by the module. We don't need to do
+	 * this for SVC as that is initiated by the SVC.
+	 */
+	if (connection->hd_cport_id != GB_SVC_CPORT_ID) {
+		struct gb_protocol_version_response response;
+
+		ret = gb_protocol_get_version(connection,
+					      GB_REQUEST_TYPE_PROTOCOL_VERSION,
+					      NULL, 0, &response,
+					      connection->protocol->major);
+		if (ret) {
+			dev_err(&connection->dev,
+				"Failed to get version CPort-%d (%d)\n",
+				cport_id, ret);
+			goto disconnect;
+		}
 	}
 
-	return 0;
+	ret = connection->protocol->connection_init(connection);
+	if (!ret)
+		return 0;
 
 disconnect:
+	spin_lock_irq(&connection->lock);
+	connection->state = GB_CONNECTION_STATE_ERROR;
+	spin_unlock_irq(&connection->lock);
+
 	gb_connection_disconnected(connection);
 	return ret;
 }

From 9937a60a06ea21acc6680615258109a417ed25a8 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:36:00 +0530
Subject: [PATCH 19/35] greybus: audio: Drop get_version support

This is done from a common place now, no need to replicate it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/audio-gb-cmds.c | 28 -------------------------
 drivers/staging/greybus/audio.c         | 14 ++-----------
 drivers/staging/greybus/audio.h         |  2 --
 3 files changed, 2 insertions(+), 42 deletions(-)

diff --git a/drivers/staging/greybus/audio-gb-cmds.c b/drivers/staging/greybus/audio-gb-cmds.c
index 10de34d6fa93..112aed994fd2 100644
--- a/drivers/staging/greybus/audio-gb-cmds.c
+++ b/drivers/staging/greybus/audio-gb-cmds.c
@@ -12,37 +12,9 @@
 #include "greybus.h"
 #include "audio.h"
 
-#define GB_I2S_MGMT_VERSION_MAJOR		0x00
-#define GB_I2S_MGMT_VERSION_MINOR		0x01
-
-#define GB_I2S_DATA_VERSION_MAJOR		0x00
-#define GB_I2S_DATA_VERSION_MINOR		0x01
-
 /***********************************
  * GB I2S helper functions
  ***********************************/
-int gb_i2s_mgmt_get_version(struct gb_connection *connection)
-{
-	struct gb_protocol_version_response response;
-
-	memset(&response, 0, sizeof(response));
-	return gb_protocol_get_version(connection,
-				       GB_I2S_MGMT_TYPE_PROTOCOL_VERSION,
-				       NULL, 0, &response,
-				       GB_I2S_MGMT_VERSION_MAJOR);
-}
-
-int gb_i2s_data_get_version(struct gb_connection *connection)
-{
-	struct gb_protocol_version_response response;
-
-	memset(&response, 0, sizeof(response));
-	return gb_protocol_get_version(connection,
-				       GB_I2S_DATA_TYPE_PROTOCOL_VERSION,
-				       NULL, 0, &response,
-				       GB_I2S_DATA_VERSION_MAJOR);
-}
-
 int gb_i2s_mgmt_activate_cport(struct gb_connection *connection,
 				      uint16_t cport)
 {
diff --git a/drivers/staging/greybus/audio.c b/drivers/staging/greybus/audio.c
index 0e9bec5089b2..6754c907cd6e 100644
--- a/drivers/staging/greybus/audio.c
+++ b/drivers/staging/greybus/audio.c
@@ -225,12 +225,6 @@ static int gb_i2s_transmitter_connection_init(struct gb_connection *connection)
 		goto out_card;
 	}
 
-	ret = gb_i2s_data_get_version(connection);
-	if (ret) {
-		pr_err("i2s data get_version() failed: %d\n", ret);
-		goto out_get_ver;
-	}
-
 #if USE_RT5645
 	rt5647_info.addr = RT5647_I2C_ADDR;
 	strlcpy(rt5647_info.type, "rt5647", I2C_NAME_SIZE);
@@ -251,8 +245,10 @@ static int gb_i2s_transmitter_connection_init(struct gb_connection *connection)
 
 	return 0;
 
+#if USE_RT5645
 out_get_ver:
 	platform_device_unregister(&snd_dev->card);
+#endif
 out_card:
 	platform_device_unregister(&snd_dev->cpu_dai);
 out_dai:
@@ -296,12 +292,6 @@ static int gb_i2s_mgmt_connection_init(struct gb_connection *connection)
 	connection->private = snd_dev;
 	spin_unlock_irqrestore(&snd_dev->lock, flags);
 
-	ret = gb_i2s_mgmt_get_version(connection);
-	if (ret) {
-		pr_err("i2s mgmt get_version() failed: %d\n", ret);
-		goto err_free_snd_dev;
-	}
-
 	ret = gb_i2s_mgmt_get_cfgs(snd_dev, connection);
 	if (ret) {
 		pr_err("can't get i2s configurations: %d\n", ret);
diff --git a/drivers/staging/greybus/audio.h b/drivers/staging/greybus/audio.h
index da95c1b3cb1e..e4975930f29a 100644
--- a/drivers/staging/greybus/audio.h
+++ b/drivers/staging/greybus/audio.h
@@ -75,8 +75,6 @@ struct gb_snd {
 /*
  * GB I2S cmd functions
  */
-int gb_i2s_mgmt_get_version(struct gb_connection *connection);
-int gb_i2s_data_get_version(struct gb_connection *connection);
 int gb_i2s_mgmt_activate_cport(struct gb_connection *connection,
 				      uint16_t cport);
 int gb_i2s_mgmt_deactivate_cport(struct gb_connection *connection,

From f8cbc30de009fdf11aff0c5d9d5dfb3f8ceb4990 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:36:01 +0530
Subject: [PATCH 20/35] greybus: battery: Drop get_version support

This is done from a common place now, no need to replicate it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/battery.c | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/drivers/staging/greybus/battery.c b/drivers/staging/greybus/battery.c
index 43799a357add..a56eb81b2386 100644
--- a/drivers/staging/greybus/battery.c
+++ b/drivers/staging/greybus/battery.c
@@ -32,8 +32,6 @@ struct gb_battery {
 	// updates from the SVC "on the fly" so we don't have to always go ask
 	// the battery for some information.  Hopefully...
 	struct gb_connection *connection;
-	u8 version_major;
-	u8 version_minor;
 
 };
 
@@ -42,8 +40,6 @@ struct gb_battery {
 #define	GB_BATTERY_VERSION_MINOR		0x01
 
 /* Greybus battery request types */
-#define	GB_BATTERY_TYPE_INVALID			0x00
-#define	GB_BATTERY_TYPE_PROTOCOL_VERSION	0x01
 #define	GB_BATTERY_TYPE_TECHNOLOGY		0x02
 #define	GB_BATTERY_TYPE_STATUS			0x03
 #define	GB_BATTERY_TYPE_MAX_VOLTAGE		0x04
@@ -94,9 +90,6 @@ struct gb_battery_voltage_response {
 	__le32	voltage;
 };
 
-/* Define get_version() routine */
-define_get_version(gb_battery, BATTERY);
-
 static int get_tech(struct gb_battery *gb)
 {
 	struct gb_battery_technology_response tech_response;
@@ -345,12 +338,7 @@ static int gb_battery_connection_init(struct gb_connection *connection)
 	gb->connection = connection;
 	connection->private = gb;
 
-	/* Check the version */
-	retval = get_version(gb);
-	if (retval)
-		goto out;
 	retval = init_and_register(connection, gb);
-out:
 	if (retval)
 		kfree(gb);
 

From 507d75c4f4502cae84b50dcb0c246d67913e9ab5 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:36:02 +0530
Subject: [PATCH 21/35] greybus: control: Drop get_version support

This is done from a common place now, no need to replicate it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/control.c | 10 +---------
 drivers/staging/greybus/control.h |  2 --
 2 files changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/staging/greybus/control.c b/drivers/staging/greybus/control.c
index a69a703a1848..605e6134d564 100644
--- a/drivers/staging/greybus/control.c
+++ b/drivers/staging/greybus/control.c
@@ -12,9 +12,6 @@
 #include <linux/slab.h>
 #include "greybus.h"
 
-/* Define get_version() routine */
-define_get_version(gb_control, CONTROL);
-
 /* Get Manifest's size from the interface */
 int gb_control_get_manifest_size_operation(struct gb_interface *intf)
 {
@@ -100,7 +97,6 @@ static int gb_control_request_recv(u8 type, struct gb_operation *op)
 static int gb_control_connection_init(struct gb_connection *connection)
 {
 	struct gb_control *control;
-	int ret;
 
 	control = kzalloc(sizeof(*control), GFP_KERNEL);
 	if (!control)
@@ -109,14 +105,10 @@ static int gb_control_connection_init(struct gb_connection *connection)
 	control->connection = connection;
 	connection->private = control;
 
-	ret = get_version(control);
-	if (ret)
-		kfree(control);
-
 	/* Set interface's control connection */
 	connection->bundle->intf->control = control;
 
-	return ret;
+	return 0;
 }
 
 static void gb_control_connection_exit(struct gb_connection *connection)
diff --git a/drivers/staging/greybus/control.h b/drivers/staging/greybus/control.h
index 6e41a2b4c70d..3248d965e593 100644
--- a/drivers/staging/greybus/control.h
+++ b/drivers/staging/greybus/control.h
@@ -12,8 +12,6 @@
 
 struct gb_control {
 	struct gb_connection	*connection;
-	u8			version_major;
-	u8			version_minor;
 };
 
 int gb_control_connected_operation(struct gb_control *control, u16 cport_id);

From 03490fdbe745a6af23527df32e6ceab4b5749a8f Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:36:03 +0530
Subject: [PATCH 22/35] greybus: gpio: Drop get_version support

This is done from a common place now, no need to replicate it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/gpio.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/drivers/staging/greybus/gpio.c b/drivers/staging/greybus/gpio.c
index a5db014eaaf2..6a04a1be573a 100644
--- a/drivers/staging/greybus/gpio.c
+++ b/drivers/staging/greybus/gpio.c
@@ -33,8 +33,6 @@ struct gb_gpio_line {
 
 struct gb_gpio_controller {
 	struct gb_connection	*connection;
-	u8			version_major;
-	u8			version_minor;
 	u8			line_max;	/* max line number */
 	struct gb_gpio_line	*lines;
 
@@ -51,9 +49,6 @@ struct gb_gpio_controller {
 	container_of(chip, struct gb_gpio_controller, chip)
 #define irq_data_to_gpio_chip(d) (d->domain->host_data)
 
-/* Define get_version() routine */
-define_get_version(gb_gpio_controller, GPIO);
-
 static int gb_gpio_line_count_operation(struct gb_gpio_controller *ggc)
 {
 	struct gb_gpio_line_count_response response;
@@ -476,11 +471,6 @@ static int gb_gpio_controller_setup(struct gb_gpio_controller *ggc)
 {
 	int ret;
 
-	/* First thing we need to do is check the version */
-	ret = get_version(ggc);
-	if (ret)
-		return ret;
-
 	/* Now find out how many lines there are */
 	ret = gb_gpio_line_count_operation(ggc);
 	if (ret)

From 2dad338c9c28f464c9717e9d0391997b649e3acd Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:36:04 +0530
Subject: [PATCH 23/35] greybus: hid: Drop get_version support

This is done from a common place now, no need to replicate it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/hid.c | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/drivers/staging/greybus/hid.c b/drivers/staging/greybus/hid.c
index 0baed865b760..887dbac8c117 100644
--- a/drivers/staging/greybus/hid.c
+++ b/drivers/staging/greybus/hid.c
@@ -68,8 +68,6 @@ struct gb_hid_input_report_request {
 /* Greybus HID device's structure */
 struct gb_hid {
 	struct gb_connection		*connection;
-	u8				version_major;
-	u8				version_minor;
 
 	struct hid_device		*hid;
 	struct gb_hid_desc_response	hdesc;
@@ -86,9 +84,6 @@ static DEFINE_MUTEX(gb_hid_open_mutex);
 
 /* Routines to get controller's information over greybus */
 
-/* Define get_version() routine */
-define_get_version(gb_hid, HID);
-
 /* Operations performed on greybus */
 static int gb_hid_get_desc(struct gb_hid *ghid)
 {
@@ -445,10 +440,6 @@ static int gb_hid_init(struct gb_hid *ghid)
 	struct hid_device *hid = ghid->hid;
 	int ret;
 
-	ret = get_version(ghid);
-	if (ret)
-		return ret;
-
 	ret = gb_hid_get_desc(ghid);
 	if (ret)
 		return ret;

From d8886f4a06593fd1849a5076e08488c0ebaf74a3 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:36:05 +0530
Subject: [PATCH 24/35] greybus: i2c: Drop get_version support

This is done from a common place now, no need to replicate it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/i2c.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/drivers/staging/greybus/i2c.c b/drivers/staging/greybus/i2c.c
index edb675384a71..75b92d683036 100644
--- a/drivers/staging/greybus/i2c.c
+++ b/drivers/staging/greybus/i2c.c
@@ -16,8 +16,6 @@
 
 struct gb_i2c_device {
 	struct gb_connection	*connection;
-	u8			version_major;
-	u8			version_minor;
 
 	u32			functionality;
 	u16			timeout_msec;
@@ -26,9 +24,6 @@ struct gb_i2c_device {
 	struct i2c_adapter	adapter;
 };
 
-/* Define get_version() routine */
-define_get_version(gb_i2c_device, I2C);
-
 /*
  * Map Greybus i2c functionality bits into Linux ones
  */
@@ -277,11 +272,6 @@ static int gb_i2c_device_setup(struct gb_i2c_device *gb_i2c_dev)
 {
 	int ret;
 
-	/* First thing we need to do is check the version */
-	ret = get_version(gb_i2c_dev);
-	if (ret)
-		return ret;
-
 	/* Assume the functionality never changes, just get it once */
 	ret = gb_i2c_functionality_operation(gb_i2c_dev);
 	if (ret)

From 47d3cfbbadfb761aaf3967df314f860f8a324f8d Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:36:06 +0530
Subject: [PATCH 25/35] greybus: loopback: Drop get_version support

This is done from a common place now, no need to replicate it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/loopback.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/drivers/staging/greybus/loopback.c b/drivers/staging/greybus/loopback.c
index 564276d90da2..88c329afd3ea 100644
--- a/drivers/staging/greybus/loopback.c
+++ b/drivers/staging/greybus/loopback.c
@@ -31,8 +31,6 @@ struct gb_loopback_stats {
 
 struct gb_loopback {
 	struct gb_connection *connection;
-	u8 version_major;
-	u8 version_minor;
 
 	struct kfifo kfifo;
 	struct mutex mutex;
@@ -73,9 +71,6 @@ module_param(kfifo_depth, uint, 0444);
 
 #define GB_LOOPBACK_MS_WAIT_MAX				1000
 
-/* Define get_version() routine */
-define_get_version(gb_loopback, LOOPBACK);
-
 /* interface sysfs attributes */
 #define gb_loopback_ro_attr(field)					\
 static ssize_t field##_show(struct device *dev,				\
@@ -493,11 +488,6 @@ static int gb_loopback_connection_init(struct gb_connection *connection)
 		goto out_sysfs;
 	}
 
-	/* Check the version */
-	retval = get_version(gb);
-	if (retval)
-		goto out_minor;
-
 	/* Calculate maximum payload */
 	gb->size_max = gb_operation_get_payload_size_max(connection);
 	if (gb->size_max <= sizeof(struct gb_loopback_transfer_request)) {

From 2e93d02c18ce39430a0cf0c591f067067bad2181 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:36:07 +0530
Subject: [PATCH 26/35] greybus: pwm: Drop get_version support

This is done from a common place now, no need to replicate it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/pwm.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/drivers/staging/greybus/pwm.c b/drivers/staging/greybus/pwm.c
index c7f8c6338801..5f335895d230 100644
--- a/drivers/staging/greybus/pwm.c
+++ b/drivers/staging/greybus/pwm.c
@@ -16,8 +16,6 @@
 
 struct gb_pwm_chip {
 	struct gb_connection	*connection;
-	u8			version_major;
-	u8			version_minor;
 	u8			pwm_max;	/* max pwm number */
 
 	struct pwm_chip		chip;
@@ -27,9 +25,6 @@ struct gb_pwm_chip {
 	container_of(chip, struct gb_pwm_chip, chip)
 
 
-/* Define get_version() routine */
-define_get_version(gb_pwm_chip, PWM);
-
 static int gb_pwm_count_operation(struct gb_pwm_chip *pwmc)
 {
 	struct gb_pwm_count_response response;
@@ -194,11 +189,6 @@ static int gb_pwm_connection_init(struct gb_connection *connection)
 	pwmc->connection = connection;
 	connection->private = pwmc;
 
-	/* Check for compatible protocol version */
-	ret = get_version(pwmc);
-	if (ret)
-		goto out_err;
-
 	/* Query number of pwms present */
 	ret = gb_pwm_count_operation(pwmc);
 	if (ret)

From f06eda1b1744fcde6769eee22bceb7d9fee23bf5 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:36:08 +0530
Subject: [PATCH 27/35] greybus: raw: Drop get_version support

This is done from a common place now, no need to replicate it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/raw.c | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/drivers/staging/greybus/raw.c b/drivers/staging/greybus/raw.c
index a17a9868a08e..215d42165282 100644
--- a/drivers/staging/greybus/raw.c
+++ b/drivers/staging/greybus/raw.c
@@ -19,8 +19,6 @@
 
 struct gb_raw {
 	struct gb_connection *connection;
-	u8 version_major;
-	u8 version_minor;
 
 	struct list_head list;
 	int list_data;
@@ -35,13 +33,8 @@ struct gb_raw {
 #define	GB_RAW_VERSION_MINOR			0x01
 
 /* Greybus raw request types */
-#define	GB_RAW_TYPE_INVALID			0x00
-#define	GB_RAW_TYPE_PROTOCOL_VERSION		0x01
 #define	GB_RAW_TYPE_SEND			0x02
 
-/* Define get_version() routine */
-define_get_version(gb_raw, RAW);
-
 struct gb_raw_send_request {
 	__le32	len;
 	__u8	data[0];
@@ -180,11 +173,6 @@ static int gb_raw_connection_init(struct gb_connection *connection)
 	raw->connection = connection;
 	connection->private = raw;
 
-	/* Check the protocol version */
-	retval = get_version(raw);
-	if (retval)
-		goto error_free;
-
 	INIT_LIST_HEAD(&raw->list);
 	mutex_init(&raw->list_lock);
 

From 7071ca1df5e26949e6a24684f52d45ca18f07077 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:36:09 +0530
Subject: [PATCH 28/35] greybus: sdio: Drop get_version support

This is done from a common place now, no need to replicate it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/sdio.c | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/drivers/staging/greybus/sdio.c b/drivers/staging/greybus/sdio.c
index 345cffff7db0..24b2e3152fa1 100644
--- a/drivers/staging/greybus/sdio.c
+++ b/drivers/staging/greybus/sdio.c
@@ -18,8 +18,6 @@
 
 struct gb_sdio_host {
 	struct gb_connection	*connection;
-	u8			version_major;
-	u8			version_minor;
 	struct mmc_host		*mmc;
 	struct mmc_request	*mrq;
 	struct mutex		lock;	/* lock for this host */
@@ -36,9 +34,6 @@ struct gb_sdio_host {
 
 static struct workqueue_struct *gb_sdio_mrq_workqueue;
 
-/* Define get_version() routine */
-define_get_version(gb_sdio_host, SDIO);
-
 #define GB_SDIO_RSP_R1_R5_R6_R7	(GB_SDIO_RSP_PRESENT | GB_SDIO_RSP_CRC | \
 				 GB_SDIO_RSP_OPCODE)
 #define GB_SDIO_RSP_R3_R4	(GB_SDIO_RSP_PRESENT)
@@ -695,10 +690,6 @@ static int gb_sdio_connection_init(struct gb_connection *connection)
 	host->connection = connection;
 	connection->private = host;
 
-	ret = get_version(host);
-	if (ret < 0)
-		goto free_mmc;
-
 	ret = gb_sdio_get_caps(host);
 	if (ret < 0)
 		goto free_mmc;

From 3fb0c8f516e06cb3bc39610aeb1311b8376bdc61 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:36:10 +0530
Subject: [PATCH 29/35] greybus: spi: Drop get_version support

This is done from a common place now, no need to replicate it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/spi.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/drivers/staging/greybus/spi.c b/drivers/staging/greybus/spi.c
index 77d6bf0b7f13..ef3cc33772f8 100644
--- a/drivers/staging/greybus/spi.c
+++ b/drivers/staging/greybus/spi.c
@@ -17,8 +17,6 @@
 
 struct gb_spi {
 	struct gb_connection	*connection;
-	u8			version_major;
-	u8			version_minor;
 
 	/* Modes supported by spi controller */
 	u16			mode;
@@ -181,9 +179,6 @@ static void gb_spi_cleanup(struct spi_device *spi)
 
 /* Routines to get controller infomation */
 
-/* Define get_version() routine */
-define_get_version(gb_spi, SPI);
-
 /*
  * Map Greybus spi mode bits/flags/bpw into Linux ones.
  * All bits are same for now and so these macro's return same values.
@@ -264,11 +259,6 @@ static int gb_spi_init(struct gb_spi *spi)
 {
 	int ret;
 
-	/* First thing we need to do is check the version */
-	ret = get_version(spi);
-	if (ret)
-		return ret;
-
 	/* mode never changes, just get it once */
 	ret = gb_spi_mode_operation(spi);
 	if (ret)

From a94e14486477b5738061ac09ab69025985c1eda5 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:36:11 +0530
Subject: [PATCH 30/35] greybus: uart: Drop get_version support

This is done from a common place now, no need to replicate it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/uart.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index 7a51c7c792c9..9e8bf6f4b8d7 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -55,8 +55,6 @@ struct gb_tty {
 	struct async_icount oldcount;
 	wait_queue_head_t wioctl;
 	struct mutex mutex;
-	u8 version_major;
-	u8 version_minor;
 	u8 ctrlin;	/* input control lines */
 	u8 ctrlout;	/* output control lines */
 	struct gb_tty_line_coding line_coding;
@@ -67,9 +65,6 @@ static DEFINE_IDR(tty_minors);
 static DEFINE_MUTEX(table_lock);
 static atomic_t reference_count = ATOMIC_INIT(0);
 
-/* Define get_version() routine */
-define_get_version(gb_tty, UART);
-
 static int gb_uart_receive_data(struct gb_tty *gb_tty,
 				struct gb_connection *connection,
 				struct gb_uart_recv_data_request *receive_data)
@@ -628,21 +623,16 @@ static int gb_uart_connection_init(struct gb_connection *connection)
 	gb_tty->connection = connection;
 	connection->private = gb_tty;
 
-	/* Check for compatible protocol version */
-	retval = get_version(gb_tty);
-	if (retval)
-		goto error_version;
-
 	minor = alloc_minor(gb_tty);
 	if (minor < 0) {
 		if (minor == -ENOSPC) {
 			dev_err(&connection->dev,
 				"no more free minor numbers\n");
 			retval = -ENODEV;
-			goto error_version;
+			goto error_minor;
 		}
 		retval = minor;
-		goto error_version;
+		goto error_minor;
 	}
 
 	gb_tty->minor = minor;
@@ -674,7 +664,7 @@ static int gb_uart_connection_init(struct gb_connection *connection)
 error:
 	tty_port_destroy(&gb_tty->port);
 	release_minor(gb_tty);
-error_version:
+error_minor:
 	connection->private = NULL;
 	kfree(gb_tty->buffer);
 error_payload:

From 0a12a187fdaa90108a681423a7f1e8ef135a1544 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:36:12 +0530
Subject: [PATCH 31/35] greybus: usb: Drop get_version support

This is done from a common place now, no need to replicate it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/usb.c | 13 -------------
 1 file changed, 13 deletions(-)

diff --git a/drivers/staging/greybus/usb.c b/drivers/staging/greybus/usb.c
index 80c42b20adda..2133d0d25f25 100644
--- a/drivers/staging/greybus/usb.c
+++ b/drivers/staging/greybus/usb.c
@@ -20,8 +20,6 @@
 #define GB_USB_VERSION_MINOR		0x01
 
 /* Greybus USB request types */
-#define GB_USB_TYPE_INVALID		0x00
-#define GB_USB_TYPE_PROTOCOL_VERSION	0x01
 #define GB_USB_TYPE_HCD_START		0x02
 #define GB_USB_TYPE_HCD_STOP		0x03
 #define GB_USB_TYPE_HUB_CONTROL		0x04
@@ -39,9 +37,6 @@ struct gb_usb_hub_control_response {
 
 struct gb_usb_device {
 	struct gb_connection *connection;
-
-	u8 version_major;
-	u8 version_minor;
 };
 
 static inline struct gb_usb_device *to_gb_usb_device(struct usb_hcd *hcd)
@@ -54,9 +49,6 @@ static inline struct usb_hcd *gb_usb_device_to_hcd(struct gb_usb_device *dev)
 	return container_of((void *)dev, struct usb_hcd, hcd_priv);
 }
 
-/* Define get_version() routine */
-define_get_version(gb_usb_device, USB);
-
 static void hcd_stop(struct usb_hcd *hcd)
 {
 	struct gb_usb_device *dev = to_gb_usb_device(hcd);
@@ -183,11 +175,6 @@ static int gb_usb_connection_init(struct gb_connection *connection)
 	gb_usb_dev->connection = connection;
 	connection->private = gb_usb_dev;
 
-	/* Check for compatible protocol version */
-	retval = get_version(gb_usb_dev);
-	if (retval)
-		goto err_put_hcd;
-
 	hcd->has_tt = 1;
 
 	/*

From a404504a8651250b2632cf62356de6c77a923430 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:36:13 +0530
Subject: [PATCH 32/35] greybus: vibrator: Drop get_version support

This is done from a common place now, no need to replicate it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/vibrator.c | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/drivers/staging/greybus/vibrator.c b/drivers/staging/greybus/vibrator.c
index df9c4b14c707..96d649acf122 100644
--- a/drivers/staging/greybus/vibrator.c
+++ b/drivers/staging/greybus/vibrator.c
@@ -19,8 +19,6 @@ struct gb_vibrator_device {
 	struct gb_connection	*connection;
 	struct device		*dev;
 	int			minor;		/* vibrator minor number */
-	u8			version_major;
-	u8			version_minor;
 };
 
 /* Version of the Greybus vibrator protocol we support */
@@ -28,8 +26,6 @@ struct gb_vibrator_device {
 #define	GB_VIBRATOR_VERSION_MINOR		0x01
 
 /* Greybus Vibrator operation types */
-#define	GB_VIBRATOR_TYPE_INVALID		0x00
-#define	GB_VIBRATOR_TYPE_PROTOCOL_VERSION	0x01
 #define	GB_VIBRATOR_TYPE_ON			0x02
 #define	GB_VIBRATOR_TYPE_OFF			0x03
 
@@ -37,9 +33,6 @@ struct gb_vibrator_on_request {
 	__le16	timeout_ms;
 };
 
-/* Define get_version() routine */
-define_get_version(gb_vibrator_device, VIBRATOR);
-
 static int turn_on(struct gb_vibrator_device *vib, u16 timeout_ms)
 {
 	struct gb_vibrator_on_request request;
@@ -108,10 +101,6 @@ static int gb_vibrator_connection_init(struct gb_connection *connection)
 	vib->connection = connection;
 	connection->private = vib;
 
-	retval = get_version(vib);
-	if (retval)
-		goto error;
-
 	/*
 	 * For now we create a device in sysfs for the vibrator, but odds are
 	 * there is a "real" device somewhere in the kernel for this, but I

From 3ea959e3911e0c9ae49eb855d7b4f744349eb977 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:36:14 +0530
Subject: [PATCH 33/35] greybus: svc: preserve major/minor of protocol
 supported by SVC

These weren't preserved earlier, save them in the connection structure
instead of creating its own fields..

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/svc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/svc.c b/drivers/staging/greybus/svc.c
index 17ffb1353fb4..025b2bad9428 100644
--- a/drivers/staging/greybus/svc.c
+++ b/drivers/staging/greybus/svc.c
@@ -11,8 +11,6 @@
 
 struct gb_svc {
 	struct gb_connection	*connection;
-	u8			version_major;
-	u8			version_minor;
 };
 
 static struct ida greybus_svc_device_id_map;
@@ -163,6 +161,9 @@ static int gb_svc_version_request(struct gb_operation *op)
 		return -ENOTSUPP;
 	}
 
+	connection->module_major = version->major;
+	connection->module_minor = version->minor;
+
 	if (!gb_operation_response_alloc(op, sizeof(*version), GFP_KERNEL)) {
 		dev_err(dev, "%s: error allocating response\n",
 				__func__);

From b9938c49131f1d2c65e8783a5a17ff6a96d9ce89 Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:36:15 +0530
Subject: [PATCH 34/35] greybus: protocol: Drop define_get_version support

No more users now, drop it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/protocol.h | 23 -----------------------
 1 file changed, 23 deletions(-)

diff --git a/drivers/staging/greybus/protocol.h b/drivers/staging/greybus/protocol.h
index 758b36ef1f55..45606adacf35 100644
--- a/drivers/staging/greybus/protocol.h
+++ b/drivers/staging/greybus/protocol.h
@@ -107,27 +107,4 @@ void gb_##__protocol##_exit(void)			\
 	gb_protocol_deregister(&__protocol);		\
 }							\
 
-/*
- * Macro to create get_version() routine for protocols
- * @__device: name of the device struct
- * @__protocol: name of protocol in CAPITALS
- */
-#define define_get_version(__device, __protocol)	\
-static int get_version(struct __device *dev)		\
-{							\
-	struct gb_protocol_version_response response;	\
-	int retval;					\
-							\
-	retval = gb_protocol_get_version(dev->connection,		\
-				GB_##__protocol##_TYPE_PROTOCOL_VERSION,\
-				NULL, 0, &response,			\
-				GB_##__protocol##_VERSION_MAJOR);	\
-	if (retval)					\
-		return retval;				\
-							\
-	dev->version_major = response.major;		\
-	dev->version_minor = response.minor;		\
-	return 0;					\
-}
-
 #endif /* __PROTOCOL_H */

From bf81454738990e7acd089e1b8aac8bab6a54637f Mon Sep 17 00:00:00 2001
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Aug 2015 07:36:16 +0530
Subject: [PATCH 35/35] greybus: protocol: Remove unnecessary params of
 gb_protocol_get_version()

Some of the parameters are not really required, drop them.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/connection.c |  7 +------
 drivers/staging/greybus/protocol.c   | 22 +++++++++++-----------
 drivers/staging/greybus/protocol.h   |  6 ++----
 3 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c
index b1f1df81be50..88383b6e603f 100644
--- a/drivers/staging/greybus/connection.c
+++ b/drivers/staging/greybus/connection.c
@@ -387,12 +387,7 @@ int gb_connection_init(struct gb_connection *connection)
 	 * this for SVC as that is initiated by the SVC.
 	 */
 	if (connection->hd_cport_id != GB_SVC_CPORT_ID) {
-		struct gb_protocol_version_response response;
-
-		ret = gb_protocol_get_version(connection,
-					      GB_REQUEST_TYPE_PROTOCOL_VERSION,
-					      NULL, 0, &response,
-					      connection->protocol->major);
+		ret = gb_protocol_get_version(connection, NULL, 0);
 		if (ret) {
 			dev_err(&connection->dev,
 				"Failed to get version CPort-%d (%d)\n",
diff --git a/drivers/staging/greybus/protocol.c b/drivers/staging/greybus/protocol.c
index ba80f552fa31..b63e28c1b950 100644
--- a/drivers/staging/greybus/protocol.c
+++ b/drivers/staging/greybus/protocol.c
@@ -163,30 +163,30 @@ struct gb_protocol *gb_protocol_get(u8 id, u8 major, u8 minor)
 	return protocol;
 }
 
-int gb_protocol_get_version(struct gb_connection *connection, int type,
-			    void *request, int request_size,
-			    struct gb_protocol_version_response *response,
-			    __u8 major)
+int gb_protocol_get_version(struct gb_connection *connection, void *request,
+			    int request_size)
 {
+	struct gb_protocol_version_response response;
 	int retval;
 
-	retval = gb_operation_sync(connection, type, request, request_size,
-				   response, sizeof(*response));
+	retval = gb_operation_sync(connection, GB_REQUEST_TYPE_PROTOCOL_VERSION,
+				   request, request_size, &response,
+				   sizeof(response));
 	if (retval)
 		return retval;
 
-	if (response->major > major) {
+	if (response.major > connection->protocol->major) {
 		dev_err(&connection->dev,
 			"unsupported major version (%hhu > %hhu)\n",
-			response->major, major);
+			response.major, connection->protocol->major);
 		return -ENOTSUPP;
 	}
 
-	connection->module_major = response->major;
-	connection->module_minor = response->minor;
+	connection->module_major = response.major;
+	connection->module_minor = response.minor;
 
 	dev_dbg(&connection->dev, "version_major = %u version_minor = %u\n",
-		response->major, response->minor);
+		response.major, response.minor);
 
 	return 0;
 }
diff --git a/drivers/staging/greybus/protocol.h b/drivers/staging/greybus/protocol.h
index 45606adacf35..34a7f185a638 100644
--- a/drivers/staging/greybus/protocol.h
+++ b/drivers/staging/greybus/protocol.h
@@ -44,10 +44,8 @@ int gb_protocol_deregister(struct gb_protocol *protocol);
 	__gb_protocol_register(protocol, THIS_MODULE)
 
 struct gb_protocol *gb_protocol_get(u8 id, u8 major, u8 minor);
-int gb_protocol_get_version(struct gb_connection *connection, int type,
-			    void *request, int request_size,
-			    struct gb_protocol_version_response *response,
-			    __u8 major);
+int gb_protocol_get_version(struct gb_connection *connection, void *request,
+			    int request_size);
 
 void gb_protocol_put(struct gb_protocol *protocol);