Split out the EXTTS pin setup from the extts configuration. Signed-off-by: Russell King (Oracle) --- drivers/net/dsa/mv88e6xxx/ptp.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/ptp.c b/drivers/net/dsa/mv88e6xxx/ptp.c index de44622d8513..19ccc8cda1f0 100644 --- a/drivers/net/dsa/mv88e6xxx/ptp.c +++ b/drivers/net/dsa/mv88e6xxx/ptp.c @@ -111,6 +111,20 @@ static int mv88e6352_set_gpio_func(struct mv88e6xxx_chip *chip, int pin, return chip->info->ops->gpio_ops->set_pctl(chip, pin, func); } +static int mv88e6352_ptp_pin_setup(struct mv88e6xxx_chip *chip, int pin, + enum ptp_pin_function func, int enable) +{ + if (func != PTP_PF_EXTTS) + return -EOPNOTSUPP; + + if (enable) + func = MV88E6352_G2_SCRATCH_GPIO_PCTL_EVREQ; + else + func = MV88E6352_G2_SCRATCH_GPIO_PCTL_GPIO; + + return mv88e6352_set_gpio_func(chip, pin, func, true); +} + static const struct mv88e6xxx_cc_coeffs * mv88e6xxx_cc_coeff_get(struct mv88e6xxx_chip *chip) { @@ -352,27 +366,18 @@ static int mv88e6352_ptp_enable_extts(struct mv88e6xxx_chip *chip, return -EBUSY; mv88e6xxx_reg_lock(chip); + err = mv88e6352_ptp_pin_setup(chip, pin, PTP_PF_EXTTS, on); - if (on) { - func = MV88E6352_G2_SCRATCH_GPIO_PCTL_EVREQ; - - err = mv88e6352_set_gpio_func(chip, pin, func, true); - if (err) - goto out; - + if (!on) { + /* Always cancel the work, even if an error occurs */ + cancel_delayed_work_sync(&chip->tai_event_work); + } else if (!err) { schedule_delayed_work(&chip->tai_event_work, TAI_EVENT_WORK_INTERVAL); err = mv88e6352_config_eventcap(chip, rising); - } else { - func = MV88E6352_G2_SCRATCH_GPIO_PCTL_GPIO; - - err = mv88e6352_set_gpio_func(chip, pin, func, true); - - cancel_delayed_work_sync(&chip->tai_event_work); } -out: mv88e6xxx_reg_unlock(chip); return err; -- 2.47.3