The KSZ8463 supports periodic outputs but doesn't handle them in the same way as the other KSZ switches. To add proper support for the KSZ8463, a dedicated ksz8463_ptp_enable_perout() function needs to be created. This function will use the same algorithm to select the output pin as the common ksz_ptp_enable_perout() function. Extract the pin selection algorithm into a dedicated function so it can be used later by the KSZ8463 support. Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz_ptp.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c index fd27e5851003..79520d345efc 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -183,6 +183,26 @@ static int ksz_ptp_configure_perout(struct ksz_device *dev, return 0; } +static int ksz_ptp_get_pin(struct ksz_device *dev, + struct ptp_perout_request const *request) +{ + struct ksz_ptp_data *ptp_data = &dev->ptp_data; + int pin; + + if (request->flags & ~PTP_PEROUT_DUTY_CYCLE) + return -EOPNOTSUPP; + + if (ptp_data->tou_mode != KSZ_PTP_TOU_PEROUT && + ptp_data->tou_mode != KSZ_PTP_TOU_IDLE) + return -EBUSY; + + pin = ptp_find_pin(ptp_data->clock, PTP_PF_PEROUT, request->index); + if (pin < 0) + return -EINVAL; + + return pin; +} + static int ksz_ptp_enable_perout(struct ksz_device *dev, struct ptp_perout_request const *request, int on) @@ -196,16 +216,9 @@ static int ksz_ptp_enable_perout(struct ksz_device *dev, u32 data32; int ret; - if (request->flags & ~PTP_PEROUT_DUTY_CYCLE) - return -EOPNOTSUPP; - - if (ptp_data->tou_mode != KSZ_PTP_TOU_PEROUT && - ptp_data->tou_mode != KSZ_PTP_TOU_IDLE) - return -EBUSY; - - pin = ptp_find_pin(ptp_data->clock, PTP_PF_PEROUT, request->index); + pin = ksz_ptp_get_pin(dev, request); if (pin < 0) - return -EINVAL; + return pin; data32 = FIELD_PREP(PTP_GPIO_INDEX, pin) | FIELD_PREP(PTP_TOU_INDEX, request->index); -- 2.55.0