From 2ab2fbbdda868ff5481fbdc95b07359d7b1ddf77 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Thu, 20 Nov 2014 22:18:48 +0100 Subject: [PATCH] phc2sys: default to the first clock in automatic mode. If we have clocks to synchronize but no source, just pick the last one in the list, which is the first one from the ptp4l command line. Signed-off-by: Richard Cochran --- phc2sys.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/phc2sys.c b/phc2sys.c index 9afc14e..d59814d 100644 --- a/phc2sys.c +++ b/phc2sys.c @@ -292,13 +292,12 @@ static void clock_reinit(struct clock *clock) static void reconfigure(struct node *node) { - struct clock *c, *rt, *src; + struct clock *c, *rt = NULL, *src = NULL, *last = NULL; int src_cnt = 0, dst_cnt = 0; pr_info("reconfiguring after port state change"); node->state_changed = 0; - src = rt = NULL; LIST_FOREACH(c, &node->clocks, list) { if (c->clkid == CLOCK_REALTIME) { rt = c; @@ -331,6 +330,15 @@ static void reconfigure(struct node *node) src_cnt++; break; } + last = c; + } + if (dst_cnt && !src) { + if (!rt || rt->dest_only) { + node->master = last; + pr_info("no source, selecting %s as the default clock", + last->device); + return; + } } if (src_cnt > 1) { pr_info("multiple master clocks available, postponing sync...");