[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y3zegX68J7Mfbrbr@hoboy.vegasvil.org>
Date: Tue, 22 Nov 2022 06:36:49 -0800
From: Richard Cochran <richardcochran@...il.com>
To: Arun Ramadoss <arun.ramadoss@...rochip.com>
Cc: linux-kernel@...r.kernel.org, netdev@...r.kernel.org,
woojung.huh@...rochip.com, UNGLinuxDriver@...rochip.com,
andrew@...n.ch, vivien.didelot@...il.com, f.fainelli@...il.com,
olteanv@...il.com, davem@...emloft.net, edumazet@...gle.com,
kuba@...nel.org, pabeni@...hat.com, linux@...linux.org.uk,
Tristram.Ha@...rochip.com
Subject: Re: [RFC Patch net-next v2 8/8] net: dsa: microchip: ptp: add
periodic output signal
On Mon, Nov 21, 2022 at 09:11:50PM +0530, Arun Ramadoss wrote:
> +static int ksz_ptp_enable_perout(struct ksz_device *dev,
> + struct ptp_perout_request const *perout_request,
> + int on)
> +{
> + struct ksz_ptp_data *ptp_data = &dev->ptp_data;
> + u64 cycle_width_ns;
> + u64 pulse_width_ns;
> + int ret;
> +
> + if (perout_request->flags & ~KSZ_PEROUT_VALID_FLAGS)
> + return -EINVAL;
> +
> + if (ptp_data->tou_mode != KSZ_PTP_TOU_PEROUT &&
> + ptp_data->tou_mode != KSZ_PTP_TOU_IDLE)
> + return -EBUSY;
> +
> + ret = ksz_ptp_tou_reset(dev, KSZ_PER_OUT_TOU);
> + if (ret)
> + return ret;
> +
> + if (!on) {
> + ptp_data->tou_mode = KSZ_PTP_TOU_IDLE;
> + return 0; /* success */
> + }
> +
> + ptp_data->perout_target_time_first.tv_sec = perout_request->start.sec;
> + ptp_data->perout_target_time_first.tv_nsec = perout_request->start.nsec;
> +
> + ptp_data->perout_period.tv_sec = perout_request->period.sec;
> + ptp_data->perout_period.tv_nsec = perout_request->period.nsec;
> +
> + cycle_width_ns = timespec64_to_ns(&ptp_data->perout_period);
> + if ((cycle_width_ns & TRIG_CYCLE_WIDTH_M) != cycle_width_ns)
> + return -EINVAL;
> +
> + if (perout_request->flags & PTP_PEROUT_DUTY_CYCLE)
> + pulse_width_ns = perout_request->on.sec * NSEC_PER_SEC +
> + perout_request->on.nsec;
> +
> + else
> + /* Use a duty cycle of 50%. Maximum pulse width supported by the
> + * hardware is a little bit more than 125 ms.
> + */
> + pulse_width_ns = min_t(u64,
> + (perout_request->period.sec * NSEC_PER_SEC
> + + perout_request->period.nsec) / 2
> + / 8 * 8,
> + 125000000LL);
CodyStyle nit: if/else bodies need {} because of two lines in 'else'.
Thanks,
Richard
> +
> + ret = ksz_ptp_tou_pulse_verify(pulse_width_ns);
> + if (ret)
> + return ret;
> +
> + ret = ksz_ptp_configure_perout(dev, cycle_width_ns,
> + pulse_width_ns,
> + &ptp_data->perout_target_time_first);
> + if (ret)
> + return ret;
> +
> + /* Activate trigger unit */
> + ret = ksz9477_ptp_tou_start(dev);
> + if (ret)
> + return ret;
> +
> + ptp_data->tou_mode = KSZ_PTP_TOU_PEROUT;
> +
> + return 0;
> +}
Powered by blists - more mailing lists