diff options
author | Johan Hovold <johan@hovoldconsulting.com> | 2016-05-11 10:18:02 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@google.com> | 2016-05-13 15:30:05 +0200 |
commit | f2aae1c6e60f2acd636c005951a2c932bc5c8d05 (patch) | |
tree | 9510b4eca87e0edc136302e1b4074164d8a108cc /drivers | |
parent | 050615076699e537b26ed0934e105e78e7f1e765 (diff) |
greybus: hd: generalise cport allocation
Generalise CPort allocation by allowing host-device drivers to override
the default implementation.
Also pass the connection flags down the stack as such information is
needed for proper CPort allocation. Specifically, this will initially be
used to allow the camera driver to allocate the dedicated CDSI CPorts.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/greybus/connection.c | 2 | ||||
-rw-r--r-- | drivers/staging/greybus/hd.c | 11 | ||||
-rw-r--r-- | drivers/staging/greybus/hd.h | 6 |
3 files changed, 16 insertions, 3 deletions
diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c index ac99fc043e54..395a9dfc99c0 100644 --- a/drivers/staging/greybus/connection.c +++ b/drivers/staging/greybus/connection.c @@ -152,7 +152,7 @@ _gb_connection_create(struct gb_host_device *hd, int hd_cport_id, goto err_unlock; } - ret = gb_hd_cport_allocate(hd, hd_cport_id); + ret = gb_hd_cport_allocate(hd, hd_cport_id, flags); if (ret < 0) { dev_err(&hd->dev, "failed to allocate cport: %d\n", ret); goto err_unlock; diff --git a/drivers/staging/greybus/hd.c b/drivers/staging/greybus/hd.c index b87e086748b2..fba6d766209f 100644 --- a/drivers/staging/greybus/hd.c +++ b/drivers/staging/greybus/hd.c @@ -55,11 +55,15 @@ int gb_hd_cport_reserve(struct gb_host_device *hd, u16 cport_id) EXPORT_SYMBOL_GPL(gb_hd_cport_reserve); /* Locking: Caller guarantees serialisation */ -int gb_hd_cport_allocate(struct gb_host_device *hd, int cport_id) +int gb_hd_cport_allocate(struct gb_host_device *hd, int cport_id, + unsigned long flags) { struct ida *id_map = &hd->cport_id_map; int ida_start, ida_end; + if (hd->driver->cport_allocate) + return hd->driver->cport_allocate(hd, cport_id, flags); + if (cport_id < 0) { ida_start = 0; ida_end = hd->num_cports; @@ -77,6 +81,11 @@ int gb_hd_cport_allocate(struct gb_host_device *hd, int cport_id) /* Locking: Caller guarantees serialisation */ void gb_hd_cport_release(struct gb_host_device *hd, u16 cport_id) { + if (hd->driver->cport_release) { + hd->driver->cport_release(hd, cport_id); + return; + } + ida_simple_remove(&hd->cport_id_map, cport_id); } diff --git a/drivers/staging/greybus/hd.h b/drivers/staging/greybus/hd.h index 5d74e0c45162..80573aed56ef 100644 --- a/drivers/staging/greybus/hd.h +++ b/drivers/staging/greybus/hd.h @@ -16,6 +16,9 @@ struct gb_message; struct gb_hd_driver { size_t hd_priv_size; + int (*cport_allocate)(struct gb_host_device *hd, int cport_id, + unsigned long flags); + void (*cport_release)(struct gb_host_device *hd, u16 cport_id); int (*cport_enable)(struct gb_host_device *hd, u16 cport_id); int (*cport_disable)(struct gb_host_device *hd, u16 cport_id); int (*message_send)(struct gb_host_device *hd, u16 dest_cport_id, @@ -51,7 +54,8 @@ struct gb_host_device { #define to_gb_host_device(d) container_of(d, struct gb_host_device, dev) int gb_hd_cport_reserve(struct gb_host_device *hd, u16 cport_id); -int gb_hd_cport_allocate(struct gb_host_device *hd, int cport_id); +int gb_hd_cport_allocate(struct gb_host_device *hd, int cport_id, + unsigned long flags); void gb_hd_cport_release(struct gb_host_device *hd, u16 cport_id); struct gb_host_device *gb_hd_create(struct gb_hd_driver *driver, |