[net-next 7/9] net: ethernet: ravb: Add callback for gPTP clock index

From: Niklas Söderlund

Date: Wed Jun 10 2026 - 06:35:03 EST


Prepare for adding Gen4 support which have an optional external gPTP
clock. Add a callback to get the clock index and use it to determine if
the device shall report gPTP support.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@xxxxxxxxxxxx>
---
drivers/net/ethernet/renesas/ravb.h | 2 ++
drivers/net/ethernet/renesas/ravb_main.c | 19 +++++++++++++++++--
2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h
index f063f4ba5714..caad95a9c3c5 100644
--- a/drivers/net/ethernet/renesas/ravb.h
+++ b/drivers/net/ethernet/renesas/ravb.h
@@ -1042,6 +1042,7 @@ struct ravb_ptp {
* critical points in the RAVB driver.
*
* @probe: Probe the gPTP clock
+ * @clock_index: Get the PTP clock index, if any
* @set_config_mode: Enter config mode
* @dmac_start: Called when the DMAC starts
* @dmac_stop: Called when the DMAC stops
@@ -1050,6 +1051,7 @@ struct ravb_ptp {
*/
struct ravb_gptp_info {
int (*probe)(struct net_device *ndev);
+ int (*clock_index)(struct net_device *ndev);
int (*set_config_mode)(struct net_device *ndev);
void (*dmac_start)(struct net_device *ndev);
void (*dmac_stop)(struct net_device *ndev);
diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index 85020c943e10..4b0d06fb5f4c 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -1773,8 +1773,13 @@ static int ravb_get_ts_info(struct net_device *ndev,
{
struct ravb_private *priv = netdev_priv(ndev);
const struct ravb_hw_info *hw_info = priv->info;
+ int index = -1;

- if (hw_info->ptp) {
+ if (hw_info->ptp && hw_info->ptp->clock_index)
+ index = hw_info->ptp->clock_index(ndev);
+
+ /* Only advertise ptp clock if present. */
+ if (index >= 0) {
info->so_timestamping =
SOF_TIMESTAMPING_TX_SOFTWARE |
SOF_TIMESTAMPING_TX_HARDWARE |
@@ -1785,7 +1790,7 @@ static int ravb_get_ts_info(struct net_device *ndev,
(1 << HWTSTAMP_FILTER_NONE) |
(1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
(1 << HWTSTAMP_FILTER_ALL);
- info->phc_index = ptp_clock_index(priv->ptp.clock);
+ info->phc_index = index;
}

return 0;
@@ -2650,6 +2655,13 @@ static int ravb_gen2_ptp_probe(struct net_device *ndev)
return ravb_compute_gti(ndev, priv->clk);
}

+static int ravb_gen2_ptp_clock_index(struct net_device *ndev)
+{
+ struct ravb_private *priv = netdev_priv(ndev);
+
+ return ptp_clock_index(priv->ptp.clock);
+}
+
static int ravb_gen2_ptp_set_config_mode(struct net_device *ndev)
{
int ret;
@@ -2666,6 +2678,7 @@ static int ravb_gen2_ptp_set_config_mode(struct net_device *ndev)

static const struct ravb_gptp_info ravb_gen2_ptp_info = {
.probe = ravb_gen2_ptp_probe,
+ .clock_index = ravb_gen2_ptp_clock_index,
.set_config_mode = ravb_gen2_ptp_set_config_mode,
.dmac_start = ravb_ptp_init,
.dmac_stop = ravb_ptp_stop,
@@ -2703,6 +2716,7 @@ static int ravb_gen3_ptp_set_config_mode(struct net_device *ndev)

static const struct ravb_gptp_info ravb_gen3_ptp_info = {
.probe = ravb_gen2_ptp_probe,
+ .clock_index = ravb_gen2_ptp_clock_index,
.set_config_mode = ravb_gen3_ptp_set_config_mode,
.ndev_open = ravb_ptp_init,
.ndev_close = ravb_ptp_stop,
@@ -2775,6 +2789,7 @@ static int ravb_rzv2m_ptp_probe(struct net_device *ndev)

static const struct ravb_gptp_info ravb_rzv2m_ptp_info = {
.probe = ravb_rzv2m_ptp_probe,
+ .clock_index = ravb_gen2_ptp_clock_index,
.set_config_mode = ravb_gen2_ptp_set_config_mode,
.dmac_start = ravb_ptp_init,
.dmac_stop = ravb_ptp_stop,
--
2.54.0