public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn•ch>
To: "Csókás Bence" <csokas.bence@prolan•hu>
Cc: netdev@vger•kernel.org, Richard Cochran <richardcochran@gmail•com>
Subject: Re: [PATCH] fec: Allow changing the PPS channel
Date: Wed, 3 Aug 2022 15:24:01 +0200	[thread overview]
Message-ID: <Yup28SWBze9i5TWV@lunn.ch> (raw)
In-Reply-To: <20220803112449.37309-1-csokas.bence@prolan.hu>

On Wed, Aug 03, 2022 at 01:24:49PM +0200, Csókás Bence wrote:
> Makes the PPS channel configurable via the Device Tree (on startup) and sysfs (run-time)
> 
> Signed-off-by: Csókás Bence <csokas.bence@prolan•hu>

Please also Cc: the PTP Maintainer for patches which touch PTP code:

Richard Cochran <richardcochran@gmail•com>

	Andrew


> ---
>  drivers/net/ethernet/freescale/fec_main.c | 37 +++++++++++++++++++++++
>  drivers/net/ethernet/freescale/fec_ptp.c  |  3 --
>  2 files changed, 37 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
> index 2c3266be20e9..7482f26cd2c7 100644
> --- a/drivers/net/ethernet/freescale/fec_main.c
> +++ b/drivers/net/ethernet/freescale/fec_main.c
> @@ -47,6 +47,7 @@
>  #include <linux/bitops.h>
>  #include <linux/io.h>
>  #include <linux/irq.h>
> +#include <linux/kobject.h>
>  #include <linux/clk.h>
>  #include <linux/crc32.h>
>  #include <linux/platform_device.h>
> @@ -3591,6 +3592,36 @@ static int fec_enet_init_stop_mode(struct fec_enet_private *fep,
>  	return ret;
>  }
>  
> +static ssize_t pps_ch_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
> +{
> +	struct device *dev = container_of(kobj, struct device, kobj);
> +	struct net_device *ndev = to_net_dev(dev);
> +	struct fec_enet_private *fep = netdev_priv(ndev);
> +
> +	return sprintf(buf, "%d", fep->pps_channel);
> +}
> +
> +static ssize_t pps_ch_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count)
> +{
> +	struct device *dev = container_of(kobj, struct device, kobj);
> +	struct net_device *ndev = to_net_dev(dev);
> +	struct fec_enet_private *fep = netdev_priv(ndev);
> +	int enable = fep->pps_enable;
> +	struct ptp_clock_request ptp_rq = { .type = PTP_CLK_REQ_PPS };
> +
> +	if (enable)
> +		fep->ptp_caps.enable(&fep->ptp_caps, &ptp_rq, 0);
> +
> +	kstrtoint(buf, 0, &fep->pps_channel);
> +
> +	if (enable)
> +		fep->ptp_caps.enable(&fep->ptp_caps, &ptp_rq, 1);
> +
> +	return count;
> +}
> +
> +struct kobj_attribute pps_ch_attr = __ATTR(pps_channel, 0660, pps_ch_show, pps_ch_store);
> +
>  static int
>  fec_probe(struct platform_device *pdev)
>  {
> @@ -3687,6 +3718,9 @@ fec_probe(struct platform_device *pdev)
>  		fep->phy_interface = interface;
>  	}
>  
> +	if (of_property_read_u32(np, "fsl,pps-channel", &fep->pps_channel))
> +		fep->pps_channel = 0;
> +
>  	fep->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
>  	if (IS_ERR(fep->clk_ipg)) {
>  		ret = PTR_ERR(fep->clk_ipg);
> @@ -3799,6 +3833,9 @@ fec_probe(struct platform_device *pdev)
>  	if (ret)
>  		goto failed_register;
>  
> +	if (sysfs_create_file(&ndev->dev.kobj, &pps_ch_attr.attr))
> +		pr_err("Cannot create pps_channel sysfs file\n");
> +
>  	device_init_wakeup(&ndev->dev, fep->wol_flag &
>  			   FEC_WOL_HAS_MAGIC_PACKET);
>  
> diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c
> index 69dfed4de4ef..a5077eff305b 100644
> --- a/drivers/net/ethernet/freescale/fec_ptp.c
> +++ b/drivers/net/ethernet/freescale/fec_ptp.c
> @@ -86,8 +86,6 @@
>  #define FEC_CC_MULT	(1 << 31)
>  #define FEC_COUNTER_PERIOD	(1 << 31)
>  #define PPS_OUPUT_RELOAD_PERIOD	NSEC_PER_SEC
> -#define FEC_CHANNLE_0		0
> -#define DEFAULT_PPS_CHANNEL	FEC_CHANNLE_0
>  
>  /**
>   * fec_ptp_enable_pps
> @@ -112,7 +110,6 @@ static int fec_ptp_enable_pps(struct fec_enet_private *fep, uint enable)
>  	if (fep->pps_enable == enable)
>  		return 0;
>  
> -	fep->pps_channel = DEFAULT_PPS_CHANNEL;
>  	fep->reload_period = PPS_OUPUT_RELOAD_PERIOD;
>  
>  	spin_lock_irqsave(&fep->tmreg_lock, flags);
> -- 
> 2.25.1
> 

  reply	other threads:[~2022-08-03 13:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-03 11:24 [PATCH] fec: Allow changing the PPS channel Csókás Bence
2022-08-03 13:24 ` Andrew Lunn [this message]
2022-08-03 15:16 ` Jakub Kicinski
  -- strict thread matches above, loose matches on Subject: below --
2022-08-08 13:15 Csókás Bence
2022-08-08 14:12 ` Richard Cochran
2022-08-09  7:36   ` Csókás Bence
2022-08-09 20:52     ` Richard Cochran

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=Yup28SWBze9i5TWV@lunn.ch \
    --to=andrew@lunn$(echo .)ch \
    --cc=csokas.bence@prolan$(echo .)hu \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=richardcochran@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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