From c68adb2f2c999886f8e18e98ad4e69aec14c9f32 Mon Sep 17 00:00:00 2001 From: Alex Elder Date: Wed, 1 Oct 2014 21:54:14 -0500 Subject: greybus: introduce a connection abstraction Within a UniPro network a pair of CPorts can be linked to form a UniPro Connection. This patch creates a new abstraction to represent an AP CPort that is connected with a CPort used by a function within a Greybus module. Signed-off-by: Alex Elder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/Makefile | 1 + drivers/staging/greybus/connection.c | 48 ++++++++++++++++++++++++++++++++++++ drivers/staging/greybus/connection.h | 29 ++++++++++++++++++++++ drivers/staging/greybus/core.c | 10 ++++++++ drivers/staging/greybus/greybus.h | 2 ++ 5 files changed, 90 insertions(+) create mode 100644 drivers/staging/greybus/connection.c create mode 100644 drivers/staging/greybus/connection.h (limited to 'drivers') diff --git a/drivers/staging/greybus/Makefile b/drivers/staging/greybus/Makefile index 0efb6958322d..ed39a5c6b6fd 100644 --- a/drivers/staging/greybus/Makefile +++ b/drivers/staging/greybus/Makefile @@ -6,6 +6,7 @@ greybus-y := core.o \ module.o \ interface.o \ function.o \ + connection.o \ i2c-gb.o \ gpio-gb.o \ sdio-gb.o \ diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c new file mode 100644 index 000000000000..113c98542858 --- /dev/null +++ b/drivers/staging/greybus/connection.c @@ -0,0 +1,48 @@ +/* + * Greybus connections + * + * Copyright 2014 Google Inc. + * + * Released under the GPLv2 only. + */ + +#include "greybus.h" + +/* + * Set up a Greybus connection, representing the bidirectional link + * between a CPort on a (local) Greybus host device and a CPort on + * another Greybus module. + * + * Returns a pointer to the new connection if successful, or a null + * pointer otherwise. + */ +struct gb_connection *gb_connection_create(struct greybus_host_device *hd, + u16 cport_id, struct gb_function *function) +{ + struct gb_connection *connection; + + connection = kzalloc(sizeof(*connection), GFP_KERNEL); + if (!connection) + return NULL; + + connection->hd = hd; /* XXX refcount? */ + connection->cport_id = cport_id; + connection->function = function; /* XXX refcount? */ + + return connection; +} + +/* + * Tear down a previously set up connection. + */ +void gb_connection_destroy(struct gb_connection *connection) +{ + if (WARN_ON(!connection)) + return; + + /* XXX Need to wait for any outstanding requests to complete */ + + /* kref_put(function); */ + /* kref_put(hd); */ + kfree(connection); +} diff --git a/drivers/staging/greybus/connection.h b/drivers/staging/greybus/connection.h new file mode 100644 index 000000000000..79b3b07f94c4 --- /dev/null +++ b/drivers/staging/greybus/connection.h @@ -0,0 +1,29 @@ +/* + * Greybus connections + * + * Copyright 2014 Google Inc. + * + * Released under the GPLv2 only. + */ + +#ifndef __CONNECTION_H +#define __CONNECTION_H + +#include + +#include "greybus.h" +#include "function.h" + +struct gb_connection { + struct gb_function *function; + struct greybus_host_device *hd; + u16 cport_id; /* Host side */ + + struct list_head host_links; +}; + +bool gb_connection_setup(struct greybus_host_device *hd, u16 cport_id, + struct gb_function *function); +void gb_connection_teardown(struct gb_connection *connection); + +#endif /* __CONNECTION_H */ diff --git a/drivers/staging/greybus/core.c b/drivers/staging/greybus/core.c index 934bdebe039c..eb8f8e522e5b 100644 --- a/drivers/staging/greybus/core.c +++ b/drivers/staging/greybus/core.c @@ -147,12 +147,22 @@ static struct device_type greybus_module_type = { .release = greybus_module_release, }; +/* XXX + * This needs to be driven by the list of functions that the + * manifest says are present. + */ static int gb_init_subdevs(struct gb_module *gmod, const struct greybus_module_id *id) { int retval; /* Allocate all of the different "sub device types" for this device */ + + /* XXX + * Decide what exactly we should get supplied for the i2c + * probe, and then work that back to what should be present + * in the manifest. + */ retval = gb_i2c_probe(gmod, id); if (retval) goto error_i2c; diff --git a/drivers/staging/greybus/greybus.h b/drivers/staging/greybus/greybus.h index 4eb70af9e006..732cc5e51dc4 100644 --- a/drivers/staging/greybus/greybus.h +++ b/drivers/staging/greybus/greybus.h @@ -23,6 +23,7 @@ #include "module.h" #include "interface.h" #include "function.h" +#include "connection.h" /* Matches up with the Greybus Protocol specification document */ @@ -180,6 +181,7 @@ struct greybus_host_device { const struct greybus_host_driver *driver; struct list_head modules; + struct list_head connections; /* Private data for the host driver */ unsigned long hd_priv[0] __attribute__ ((aligned(sizeof(s64)))); -- cgit v1.2.3-55-g7522