From: Frank Li <Frank.li@nxp.com>
To: Wei Fang <wei.fang@nxp.com>
Cc: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
richardcochran@gmail.com, claudiu.manoil@nxp.com,
vladimir.oltean@nxp.com, xiaoning.wang@nxp.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, vadim.fedorenko@linux.dev,
shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com,
fushi.peng@nxp.com, devicetree@vger.kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
imx@lists.linux.dev, kernel@pengutronix.de
Subject: Re: [PATCH v4 net-next 03/15] ptp: add helpers to get the phc_index by of_node or dev
Date: Tue, 19 Aug 2025 10:45:29 -0400 [thread overview]
Message-ID: <aKSOCbuKcwRkBe82@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20250819123620.916637-4-wei.fang@nxp.com>
On Tue, Aug 19, 2025 at 08:36:08PM +0800, Wei Fang wrote:
> Some Ethernet controllers do not have an integrated PTP timer function.
> Instead, the PTP timer is a separated device and provides PTP hardware
> clock to the Ethernet controller to use. Therefore, the Ethernet
> controller driver needs to obtain the PTP clock's phc_index in its
> ethtool_ops::get_ts_info(). Currently, most drivers implement this in
> the following ways.
>
> 1. The PTP device driver adds a custom API and exports it to the Ethernet
> controller driver.
> 2. The PTP device driver adds private data to its device structure. So
> the private data structure needs to be exposed to the Ethernet controller
> driver.
>
> When registering the ptp clock, ptp_clock_register() always saves the
> ptp_clock pointer to the private data of ptp_clock::dev. Therefore, as
> long as ptp_clock::dev is obtained, the phc_index can be obtained. So
> the following generic APIs can be added to the ptp driver to obtain the
> phc_index.
>
> 1. ptp_clock_index_by_dev(): Obtain the phc_index by the device pointer
> of the PTP device.
> 2.ptp_clock_index_by_of_node(): Obtain the phc_index by the of_node
> pointer of the PTP device.
>
> Also, we can add another API like ptp_clock_index_by_fwnode() to get the
> phc_index by fwnode of PTP device. However, this API is not used in this
> patch set, so it is better to add it when needed.
Needn't this paragraph.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
>
> Suggested-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> Signed-off-by: Wei Fang <wei.fang@nxp.com>
>
> ---
> v4 changes:
> New patch
> ---
> drivers/ptp/ptp_clock.c | 53 ++++++++++++++++++++++++++++++++
> include/linux/ptp_clock_kernel.h | 22 +++++++++++++
> 2 files changed, 75 insertions(+)
>
> diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
> index 1cc06b7cb17e..2b0fd62a17ef 100644
> --- a/drivers/ptp/ptp_clock.c
> +++ b/drivers/ptp/ptp_clock.c
> @@ -11,6 +11,7 @@
> #include <linux/module.h>
> #include <linux/posix-clock.h>
> #include <linux/pps_kernel.h>
> +#include <linux/property.h>
> #include <linux/slab.h>
> #include <linux/syscalls.h>
> #include <linux/uaccess.h>
> @@ -477,6 +478,58 @@ int ptp_clock_index(struct ptp_clock *ptp)
> }
> EXPORT_SYMBOL(ptp_clock_index);
>
> +static int ptp_clock_of_node_match(struct device *dev, const void *data)
> +{
> + const struct device_node *parent_np = data;
> +
> + return (dev->parent && dev_of_node(dev->parent) == parent_np);
> +}
> +
> +int ptp_clock_index_by_of_node(struct device_node *np)
> +{
> + struct ptp_clock *ptp;
> + struct device *dev;
> + int phc_index;
> +
> + dev = class_find_device(&ptp_class, NULL, np,
> + ptp_clock_of_node_match);
> + if (!dev)
> + return -1;
> +
> + ptp = dev_get_drvdata(dev);
> + phc_index = ptp_clock_index(ptp);
> + put_device(dev);
> +
> + return phc_index;
> +}
> +EXPORT_SYMBOL_GPL(ptp_clock_index_by_of_node);
> +
> +static int ptp_clock_dev_match(struct device *dev, const void *data)
> +{
> + const struct device *parent = data;
> +
> + return dev->parent == parent;
> +}
> +
> +int ptp_clock_index_by_dev(struct device *parent)
> +{
> + struct ptp_clock *ptp;
> + struct device *dev;
> + int phc_index;
> +
> + dev = class_find_device(&ptp_class, NULL, parent,
> + ptp_clock_dev_match);
> + if (!dev)
> + return -1;
> +
> + ptp = dev_get_drvdata(dev);
> + phc_index = ptp_clock_index(ptp);
> + put_device(dev);
> +
> + return phc_index;
> +}
> +EXPORT_SYMBOL_GPL(ptp_clock_index_by_dev);
> +
> int ptp_find_pin(struct ptp_clock *ptp,
> enum ptp_pin_function func, unsigned int chan)
> {
> diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h
> index 3d089bd4d5e9..7dd7951b23d5 100644
> --- a/include/linux/ptp_clock_kernel.h
> +++ b/include/linux/ptp_clock_kernel.h
> @@ -360,6 +360,24 @@ extern void ptp_clock_event(struct ptp_clock *ptp,
>
> extern int ptp_clock_index(struct ptp_clock *ptp);
>
> +/**
> + * ptp_clock_index_by_of_node() - obtain the device index of
> + * a PTP clock based on the PTP device of_node
> + *
> + * @np: The device of_node pointer of the PTP device.
> + * Return: The PHC index on success or -1 on failure.
> + */
> +int ptp_clock_index_by_of_node(struct device_node *np);
> +
> +/**
> + * ptp_clock_index_by_dev() - obtain the device index of
> + * a PTP clock based on the PTP device.
> + *
> + * @parent: The parent device (PTP device) pointer of the PTP clock.
> + * Return: The PHC index on success or -1 on failure.
> + */
> +int ptp_clock_index_by_dev(struct device *parent);
> +
> /**
> * ptp_find_pin() - obtain the pin index of a given auxiliary function
> *
> @@ -425,6 +443,10 @@ static inline void ptp_clock_event(struct ptp_clock *ptp,
> { }
> static inline int ptp_clock_index(struct ptp_clock *ptp)
> { return -1; }
> +static inline int ptp_clock_index_by_of_node(struct device_node *np)
> +{ return -1; }
> +static inline int ptp_clock_index_by_dev(struct device *parent)
> +{ return -1; }
> static inline int ptp_find_pin(struct ptp_clock *ptp,
> enum ptp_pin_function func, unsigned int chan)
> { return -1; }
> --
> 2.34.1
>
next prev parent reply other threads:[~2025-08-19 14:45 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-19 12:36 [PATCH v4 net-next 00/15] Add NETC Timer PTP driver and add PTP support for i.MX95 Wei Fang
2025-08-19 12:36 ` [PATCH v4 net-next 01/15] dt-bindings: ptp: add NETC Timer PTP clock Wei Fang
2025-08-19 14:38 ` Frank Li
2025-08-20 1:32 ` Wei Fang
2025-08-19 12:36 ` [PATCH v4 net-next 02/15] dt-bindings: net: move ptp-timer property to ethernet-controller.yaml Wei Fang
2025-08-19 20:43 ` Rob Herring (Arm)
2025-08-19 12:36 ` [PATCH v4 net-next 03/15] ptp: add helpers to get the phc_index by of_node or dev Wei Fang
2025-08-19 14:45 ` Frank Li [this message]
2025-08-19 14:53 ` Jakub Kicinski
2025-08-19 12:36 ` [PATCH v4 net-next 04/15] ptp: netc: add NETC V4 Timer PTP driver support Wei Fang
2025-08-19 15:14 ` Frank Li
2025-08-20 2:48 ` Wei Fang
2025-08-19 15:48 ` Vadim Fedorenko
2025-08-20 1:44 ` Wei Fang
2025-08-19 12:36 ` [PATCH v4 net-next 05/15] ptp: netc: add PTP_CLK_REQ_PPS support Wei Fang
2025-08-19 15:25 ` Frank Li
2025-08-20 2:29 ` Wei Fang
2025-08-19 12:36 ` [PATCH v4 net-next 06/15] ptp: netc: add periodic pulse output support Wei Fang
2025-08-19 15:28 ` Frank Li
2025-08-19 12:36 ` [PATCH v4 net-next 07/15] ptp: netc: add external trigger stamp support Wei Fang
2025-08-19 12:36 ` [PATCH v4 net-next 08/15] ptp: netc: add debugfs support to loop back pulse signal Wei Fang
2025-08-19 12:36 ` [PATCH v4 net-next 09/15] MAINTAINERS: add NETC Timer PTP clock driver section Wei Fang
2025-08-19 12:36 ` [PATCH v4 net-next 10/15] net: enetc: save the parsed information of PTP packet to skb->cb Wei Fang
2025-08-19 12:36 ` [PATCH v4 net-next 11/15] net: enetc: extract enetc_update_ptp_sync_msg() to handle PTP Sync packets Wei Fang
2025-08-19 15:31 ` Frank Li
2025-08-19 12:36 ` [PATCH v4 net-next 12/15] net: enetc: remove unnecessary CONFIG_FSL_ENETC_PTP_CLOCK check Wei Fang
2025-08-19 12:36 ` [PATCH v4 net-next 13/15] net: enetc: add PTP synchronization support for ENETC v4 Wei Fang
2025-08-19 15:34 ` Frank Li
2025-08-20 1:46 ` Wei Fang
2025-08-19 12:36 ` [PATCH v4 net-next 14/15] net: enetc: don't update sync packet checksum if checksum offload is used Wei Fang
2025-08-19 12:36 ` [PATCH v4 15/15] arm64: dts: imx95: add standard PCI device compatible string to NETC Timer Wei Fang
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=aKSOCbuKcwRkBe82@lizhi-Precision-Tower-5810 \
--to=frank.li@nxp.com \
--cc=andrew+netdev@lunn.ch \
--cc=claudiu.manoil@nxp.com \
--cc=conor+dt@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=festevam@gmail.com \
--cc=fushi.peng@nxp.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=robh@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=vadim.fedorenko@linux.dev \
--cc=vladimir.oltean@nxp.com \
--cc=wei.fang@nxp.com \
--cc=xiaoning.wang@nxp.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;
as well as URLs for NNTP newsgroup(s).