From: Jacob Keller <jacob.e.keller@intel.com>
To: Arun Ramadoss <arun.ramadoss@microchip.com>,
<linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>
Cc: <woojung.huh@microchip.com>, <UNGLinuxDriver@microchip.com>,
<andrew@lunn.ch>, <vivien.didelot@gmail.com>,
<f.fainelli@gmail.com>, <olteanv@gmail.com>,
<davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
<pabeni@redhat.com>, <linux@armlinux.org.uk>,
<Tristram.Ha@microchip.com>, <richardcochran@gmail.com>,
<ceggers@arri.de>
Subject: Re: [Patch net-next v4 01/13] net: dsa: microchip: ptp: add the posix clock support
Date: Mon, 19 Dec 2022 14:08:32 -0800 [thread overview]
Message-ID: <3e7ad9b4-9962-2eea-d6f2-c8f0cb7c121d@intel.com> (raw)
In-Reply-To: <20221212102639.24415-2-arun.ramadoss@microchip.com>
On 12/12/2022 2:26 AM, Arun Ramadoss wrote:
> +static int ksz_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
> +{
> + struct ksz_ptp_data *ptp_data = ptp_caps_to_data(ptp);
> + struct ksz_device *dev = ptp_data_to_ksz_dev(ptp_data);
> + int ret;
> +
> + mutex_lock(&ptp_data->lock);
> +
> + if (scaled_ppm) {
> + s64 ppb, adj;
> + u32 data32;
> +
> + /* see scaled_ppm_to_ppb() in ptp_clock.c for details */
> + ppb = 1 + scaled_ppm;
> + ppb *= 125;
> + ppb *= KSZ_PTP_INC_NS;
> + ppb <<= KSZ_PTP_SUBNS_BITS - 13;
> + adj = div_s64(ppb, NSEC_PER_SEC);
> +
> + data32 = abs(adj);
> + data32 &= PTP_SUBNANOSEC_M;
> + if (adj >= 0)
> + data32 |= PTP_RATE_DIR;
> +
Can you use adjust_by_scaled_ppm or diff_by_scalled_ppm? These work by
defining the base increment for your device to achieve nominal
nanoseconds, and then perform the multiple+divide to calculate the
modified adjustment based on scaled_ppm. The diff_by_scaled_ppm looks
like what you want as it takes a base, the scaled adjustment factor and
then exports the diff as the 3rd argument. It returns true if the
difference is negative so ou can use that to determine if you need to
add the PTP_RATE_DIR flag.
If for some reason diff_by_scaled_ppm isn't sufficient for your
hardware, at least use scaled_ppm_to_ppb to get the ppb value instead of
open coding the conversion.
Thanks,
Jake
next prev parent reply other threads:[~2022-12-19 22:10 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-12 10:26 [Patch net-next v4 00/13] net: dsa: microchip: add PTP support for KSZ9563/KSZ8563 and LAN937x Arun Ramadoss
2022-12-12 10:26 ` [Patch net-next v4 01/13] net: dsa: microchip: ptp: add the posix clock support Arun Ramadoss
2022-12-19 22:08 ` Jacob Keller [this message]
2022-12-12 10:26 ` [Patch net-next v4 02/13] net: dsa: microchip: ptp: Initial hardware time stamping support Arun Ramadoss
2022-12-12 10:26 ` [Patch net-next v4 03/13] net: dsa: microchip: ptp: add 4 bytes in tail tag when ptp enabled Arun Ramadoss
2022-12-12 10:26 ` [Patch net-next v4 04/13] net: dsa: microchip: ptp: manipulating absolute time using ptp hw clock Arun Ramadoss
2022-12-12 10:26 ` [Patch net-next v4 05/13] net: dsa: microchip: ptp: enable interrupt for timestamping Arun Ramadoss
2022-12-19 12:38 ` Vladimir Oltean
2022-12-12 10:26 ` [Patch net-next v4 06/13] net: ptp: add helper for one-step P2P clocks Arun Ramadoss
2022-12-12 10:26 ` [Patch net-next v4 07/13] net: dsa: microchip: ptp: add packet reception timestamping Arun Ramadoss
2022-12-12 10:26 ` [Patch net-next v4 08/13] net: dsa: microchip: ptp: add packet transmission timestamping Arun Ramadoss
2022-12-12 10:26 ` [Patch net-next v4 09/13] net: dsa: microchip: ptp: move pdelay_rsp correction field to tail tag Arun Ramadoss
2022-12-12 10:26 ` [Patch net-next v4 10/13] net: dsa: microchip: ptp: add periodic output signal Arun Ramadoss
2022-12-12 10:26 ` [Patch net-next v4 11/13] net: dsa: microchip: ptp: add support for perout programmable pins Arun Ramadoss
2022-12-12 10:26 ` [Patch net-next v4 12/13] net: dsa: microchip: ptp: lan937x: add 2 step timestamping Arun Ramadoss
2022-12-12 10:26 ` [Patch net-next v4 13/13] net: dsa: microchip: ptp: lan937x: Enable periodic output in LED pins Arun Ramadoss
2022-12-12 15:48 ` [Patch net-next v4 00/13] net: dsa: microchip: add PTP support for KSZ9563/KSZ8563 and LAN937x Christian Eggers
2022-12-12 23:47 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3e7ad9b4-9962-2eea-d6f2-c8f0cb7c121d@intel.com \
--to=jacob.e.keller@intel.com \
--cc=Tristram.Ha@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew@lunn.ch \
--cc=arun.ramadoss@microchip.com \
--cc=ceggers@arri.de \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=vivien.didelot@gmail.com \
--cc=woojung.huh@microchip.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox