greybus: svc: register svc device at hello
Register the svc device upon reception of the HELLO request.
The SVC HELLO request contains the endo id and AP interface id, which
will be exposed from the svc device rather than the endo.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
diff --git a/drivers/staging/greybus/svc.c b/drivers/staging/greybus/svc.c
index 5aa21f7..fab5c45 100644
--- a/drivers/staging/greybus/svc.c
+++ b/drivers/staging/greybus/svc.c
@@ -16,19 +16,6 @@
#define CPORT_FLAGS_CSD_N BIT(1)
#define CPORT_FLAGS_CSV_N BIT(2)
-enum gb_svc_state {
- GB_SVC_STATE_RESET,
- GB_SVC_STATE_PROTOCOL_VERSION,
- GB_SVC_STATE_SVC_HELLO,
-};
-
-struct gb_svc {
- struct device dev;
-
- struct gb_connection *connection;
- enum gb_svc_state state;
- struct ida device_id_map;
-};
struct svc_hotplug {
struct work_struct work;
@@ -348,6 +335,7 @@
static int gb_svc_hello(struct gb_operation *op)
{
struct gb_connection *connection = op->connection;
+ struct gb_svc *svc = connection->private;
struct gb_host_device *hd = connection->hd;
struct gb_svc_hello_request *hello_request;
struct gb_interface *intf;
@@ -370,6 +358,12 @@
endo_id = le16_to_cpu(hello_request->endo_id);
interface_id = hello_request->interface_id;
+ ret = device_add(&svc->dev);
+ if (ret) {
+ dev_err(&svc->dev, "failed to register svc device: %d\n", ret);
+ return ret;
+ }
+
/* Setup Endo */
ret = greybus_endo_setup(hd, endo_id, interface_id);
if (ret)
@@ -671,7 +665,7 @@
static void gb_svc_release(struct device *dev)
{
- struct gb_svc *svc = container_of(dev, struct gb_svc, dev);
+ struct gb_svc *svc = to_gb_svc(dev);
ida_destroy(&svc->device_id_map);
kfree(svc);
@@ -716,6 +710,9 @@
{
struct gb_svc *svc = connection->private;
+ if (device_is_registered(&svc->dev))
+ device_del(&svc->dev);
+
connection->hd->svc = NULL;
connection->private = NULL;