From: Simon Horman <horms@kernel.org>
To: Min Li <lnimi@hotmail.com>
Cc: richardcochran@gmail.com, lee@kernel.org,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
Min Li <min.li.xe@renesas.com>
Subject: Re: [PATCH net-next v3 2/2] ptp: add FemtoClock3 Wireless as ptp hardware clock
Date: Sat, 16 Dec 2023 17:42:33 +0000 [thread overview]
Message-ID: <20231216174233.GA48471@kernel.org> (raw)
In-Reply-To: <PH7PR03MB7064D4543F1EE6E0A45053C8A08CA@PH7PR03MB7064.namprd03.prod.outlook.com>
On Thu, Dec 14, 2023 at 11:36:25AM -0500, Min Li wrote:
...
> diff --git a/drivers/ptp/ptp_fc3.c b/drivers/ptp/ptp_fc3.c
...
> +static inline s64 ns2counters(struct idtfc3 *idtfc3, s64 nsec, u32 *sub_ns)
Sorry, I missed this in my earlier response.
Please don't use inline in .c files unless htere is a demonstrable
reason to do so. Rather, please leave inlining up to the compiler.
> +{
> + s64 sync;
> + s32 rem;
> +
> + if (likely(nsec >= 0)) {
> + sync = div_u64_rem(nsec, idtfc3->ns_per_sync, &rem);
> + *sub_ns = rem;
> + } else if (nsec < 0) {
> + sync = -div_u64_rem(-nsec - 1, idtfc3->ns_per_sync, &rem) - 1;
> + *sub_ns = idtfc3->ns_per_sync - rem - 1;
> + }
> +
> + return sync * idtfc3->ns_per_sync;
> +}
> +
> +static inline s64 tdc_meas2offset(struct idtfc3 *idtfc3, u64 meas_read)
> +{
> + s64 coarse, fine;
> +
> + fine = sign_extend64(FIELD_GET(FINE_MEAS_MASK, meas_read), 12);
> + coarse = sign_extend64(FIELD_GET(COARSE_MEAS_MASK, meas_read), (39 - 13));
> +
> + fine = div64_s64(fine * NSEC_PER_SEC, idtfc3->tdc_apll_freq * 62LL);
> + coarse = div64_s64(coarse * NSEC_PER_SEC, idtfc3->time_ref_freq);
> +
> + return coarse + fine;
> +}
> +
> +static inline s64 tdc_offset2phase(struct idtfc3 *idtfc3, s64 offset_ns)
> +{
> + if (offset_ns > idtfc3->ns_per_sync / 2)
> + offset_ns -= idtfc3->ns_per_sync;
> +
> + return offset_ns * idtfc3->tdc_offset_sign;
> +}
...
> +static inline bool get_tdc_meas(struct idtfc3 *idtfc3, s64 *offset_ns)
> +{
> + bool valid = false;
> + u8 buf[9];
> + u8 val;
> + int err;
> +
> + while (true) {
> + err = regmap_bulk_read(idtfc3->regmap, TDC_FIFO_STS,
> + &val, sizeof(val));
> + if (err)
> + return false;
> +
> + if (val & FIFO_EMPTY)
> + break;
> +
> + err = regmap_bulk_read(idtfc3->regmap, TDC_FIFO_READ_REQ,
> + &buf, sizeof(buf));
> + if (err)
> + return false;
> +
> + valid = true;
> + }
> +
> + if (valid)
> + *offset_ns = tdc_meas2offset(idtfc3, get_unaligned_le64(&buf[1]));
> +
> + return valid;
> +}
> +
> +static inline int check_tdc_fifo_overrun(struct idtfc3 *idtfc3)
> +{
> + u8 val;
> + int err;
> +
> + /* Check if FIFO is overrun */
> + err = regmap_bulk_read(idtfc3->regmap, TDC_FIFO_STS, &val, sizeof(val));
> + if (err)
> + return err;
> +
> + if (!(val & FIFO_FULL))
> + return 0;
> +
> + dev_warn(idtfc3->dev, "TDC FIFO overrun !!!");
> +
> + err = idtfc3_enable_tdc(idtfc3, true, CONTINUOUS);
> + if (err)
> + return err;
> +
> + return 0;
> +}
...
> +static int idtfc3_remove(struct platform_device *pdev)
> +{
> + struct idtfc3 *idtfc3 = platform_get_drvdata(pdev);
> +
> + ptp_clock_unregister(idtfc3->ptp_clock);
FWIIW, I'm slightly surprised that more cleanup isn't needed.
> +
> + return 0;
> +}
> +
> +static struct platform_driver idtfc3_driver = {
> + .driver = {
> + .name = "rc38xxx-phc",
> + },
> + .probe = idtfc3_probe,
> + .remove = idtfc3_remove,
> +};
> +
> +module_platform_driver(idtfc3_driver);
...
prev parent reply other threads:[~2023-12-16 17:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20231214163625.17939-1-lnimi@hotmail.com>
2023-12-14 16:36 ` [PATCH net-next v3 2/2] ptp: add FemtoClock3 Wireless as ptp hardware clock Min Li
2023-12-16 16:54 ` Simon Horman
2023-12-16 17:42 ` Simon Horman [this message]
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=20231216174233.GA48471@kernel.org \
--to=horms@kernel.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lnimi@hotmail.com \
--cc=min.li.xe@renesas.com \
--cc=netdev@vger.kernel.org \
--cc=richardcochran@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.