greybus: hd: generalise cport allocation
[cascardo/linux.git] / drivers / staging / greybus / hd.c
index b87e086..fba6d76 100644 (file)
@@ -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);
 }