greybus: timesync: Bind TimeSync into Greybus
authorBryan O'Donoghue <bryan.odonoghue@linaro.org>
Sun, 5 Jun 2016 13:03:27 +0000 (14:03 +0100)
committerGreg Kroah-Hartman <gregkh@google.com>
Tue, 7 Jun 2016 03:50:08 +0000 (20:50 -0700)
TimeSync needs to bind into Greybus in a few places.

- core.c
  To initialize its internal state and tear-down its internal state.
  To schedule a timesync to a newly added Bundle after probe() completes.

- svc.c
  To get access to the SVC and enable/disable timesync as well as
  extracting the authoritative time from the SVC to subsequently
  disseminate to other entities in the system.

- interface.c
  To get access to an Interface in order to inform APBx of timesync
  enable/disable and authoritative operations.

This patch adds those bindings into Greybus core.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Acked-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/core.c
drivers/staging/greybus/interface.c
drivers/staging/greybus/svc.c

index 7350c5e..c812906 100644 (file)
@@ -178,6 +178,8 @@ static int greybus_probe(struct device *dev)
                return retval;
        }
 
+       gb_timesync_schedule_asynchronous(bundle->intf);
+
        return 0;
 }
 
@@ -267,8 +269,15 @@ static int __init gb_init(void)
                goto error_bootrom;
        }
 
+       retval = gb_timesync_init();
+       if (retval) {
+               pr_err("gb_timesync_init failed\n");
+               goto error_timesync;
+       }
        return 0;       /* Success */
 
+error_timesync:
+       gb_bootrom_exit();
 error_bootrom:
        gb_operation_exit();
 error_operation:
@@ -284,6 +293,7 @@ module_init(gb_init);
 
 static void __exit gb_exit(void)
 {
+       gb_timesync_exit();
        gb_bootrom_exit();
        gb_operation_exit();
        gb_hd_exit();
index 3eb8754..9b90209 100644 (file)
@@ -805,6 +805,12 @@ int gb_interface_enable(struct gb_interface *intf)
        if (ret)
                goto err_destroy_bundles;
 
+       ret = gb_timesync_interface_add(intf);
+       if (ret) {
+               dev_err(&intf->dev, "failed to add to timesync: %d\n", ret);
+               goto err_destroy_bundles;
+       }
+
        list_for_each_entry_safe_reverse(bundle, tmp, &intf->bundles, links) {
                ret = gb_bundle_add(bundle);
                if (ret) {
@@ -857,6 +863,7 @@ void gb_interface_disable(struct gb_interface *intf)
        list_for_each_entry_safe(bundle, next, &intf->bundles, links)
                gb_bundle_destroy(bundle);
 
+       gb_timesync_interface_remove(intf);
        gb_control_del(intf->control);
        gb_control_disable(intf->control);
        gb_control_put(intf->control);
index b41d262..d7458c5 100644 (file)
@@ -851,14 +851,25 @@ static int gb_svc_hello(struct gb_operation *op)
        ret = gb_svc_watchdog_create(svc);
        if (ret) {
                dev_err(&svc->dev, "failed to create watchdog: %d\n", ret);
-               input_unregister_device(svc->input);
-               device_del(&svc->dev);
-               return ret;
+               goto err_unregister_device;
        }
 
        gb_svc_debugfs_init(svc);
 
+       ret = gb_timesync_svc_add(svc);
+       if (ret) {
+               dev_err(&svc->dev, "failed to add SVC to timesync: %d\n", ret);
+               gb_svc_debugfs_exit(svc);
+               goto err_unregister_device;
+       }
+
        return gb_svc_queue_deferred_request(op);
+
+err_unregister_device:
+       gb_svc_watchdog_destroy(svc);
+       input_unregister_device(svc->input);
+       device_del(&svc->dev);
+       return ret;
 }
 
 static struct gb_interface *gb_svc_interface_lookup(struct gb_svc *svc,
@@ -1404,6 +1415,7 @@ void gb_svc_del(struct gb_svc *svc)
         * from the request handler.
         */
        if (device_is_registered(&svc->dev)) {
+               gb_timesync_svc_remove(svc);
                gb_svc_debugfs_exit(svc);
                gb_svc_watchdog_destroy(svc);
                input_unregister_device(svc->input);