+ vlynq_reset(dev);
+ for (i = dev->dev_id ? vlynq_rdiv2 : vlynq_rdiv8; dev->dev_id ?
+ i <= vlynq_rdiv8 : i >= vlynq_rdiv2;
+ dev->dev_id ? i++ : i--) {
+
+ if (!vlynq_linked(dev))
+ break;
+
+ vlynq_reg_write(dev->remote->control,
+ (vlynq_reg_read(dev->remote->control) &
+ ~VLYNQ_CTRL_CLOCK_MASK) |
+ VLYNQ_CTRL_CLOCK_INT |
+ VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1));
+ vlynq_reg_write(dev->local->control,
+ ((vlynq_reg_read(dev->local->control)
+ & ~(VLYNQ_CTRL_CLOCK_INT |
+ VLYNQ_CTRL_CLOCK_MASK)) |
+ VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1)));
+
+ if (vlynq_linked(dev)) {
+ printk(KERN_DEBUG
+ "%s: using remote clock divisor %d\n",
+ dev->dev.bus_id, i - vlynq_rdiv1 + 1);
+ dev->divisor = i;
+ return 0;
+ } else {
+ vlynq_reset(dev);
+ }
+ }
+
+ return -ENODEV;
+}
+
+static int __vlynq_try_local(struct vlynq_device *dev)
+{
+ int i;
+
+ vlynq_reset(dev);
+
+ for (i = dev->dev_id ? vlynq_ldiv2 : vlynq_ldiv8; dev->dev_id ?
+ i <= vlynq_ldiv8 : i >= vlynq_ldiv2;
+ dev->dev_id ? i++ : i--) {
+
+ vlynq_reg_write(dev->local->control,
+ (vlynq_reg_read(dev->local->control) &
+ ~VLYNQ_CTRL_CLOCK_MASK) |
+ VLYNQ_CTRL_CLOCK_INT |
+ VLYNQ_CTRL_CLOCK_DIV(i - vlynq_ldiv1));
+
+ if (vlynq_linked(dev)) {
+ printk(KERN_DEBUG
+ "%s: using local clock divisor %d\n",
+ dev->dev.bus_id, i - vlynq_ldiv1 + 1);
+ dev->divisor = i;
+ return 0;
+ } else {
+ vlynq_reset(dev);
+ }
+ }
+
+ return -ENODEV;
+}
+
+static int __vlynq_try_external(struct vlynq_device *dev)
+{
+ vlynq_reset(dev);
+ if (!vlynq_linked(dev))
+ return -ENODEV;
+
+ vlynq_reg_write(dev->remote->control,
+ (vlynq_reg_read(dev->remote->control) &
+ ~VLYNQ_CTRL_CLOCK_INT));
+
+ vlynq_reg_write(dev->local->control,
+ (vlynq_reg_read(dev->local->control) &
+ ~VLYNQ_CTRL_CLOCK_INT));