public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Wojciech Drewek <wojciech.drewek@intel.com>
To: Diogo Ivo <diogo.ivo@siemens.com>,
	MD Danish Anwar <danishanwar@ti.com>,
	Roger Quadros <rogerq@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	Richard Cochran <richardcochran@gmail.com>,
	Nishanth Menon <nm@ti.com>, Vignesh Raghavendra <vigneshr@ti.com>,
	"Tero Kristo" <kristo@kernel.org>, Rob Herring <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	"Jan Kiszka" <jan.kiszka@siemens.com>,
	Jacob Keller <jacob.e.keller@intel.com>,
	Simon Horman <horms@kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>, <netdev@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>
Subject: Re: [PATCH net-next v2 2/3] net: ti: icss-iep: Enable compare events
Date: Tue, 4 Jun 2024 16:23:18 +0200	[thread overview]
Message-ID: <00dab591-0521-4165-a5a5-216dc9aa8d08@intel.com> (raw)
In-Reply-To: <20240604-iep-v2-2-ea8e1c0a5686@siemens.com>



On 04.06.2024 15:15, Diogo Ivo wrote:
> The IEP module supports compare events, in which a value is written to a
> hardware register and when the IEP counter reaches the written value an
> interrupt is generated. Add handling for this interrupt in order to
> support PPS events.
> 
> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
> Signed-off-by: Diogo Ivo <diogo.ivo@siemens.com>
> ---

Reviewed-by: Wojciech Drewek <wojciech.drewek@intel.com>

>  drivers/net/ethernet/ti/icssg/icss_iep.c | 74 ++++++++++++++++++++++++++++++++
>  1 file changed, 74 insertions(+)
> 
> diff --git a/drivers/net/ethernet/ti/icssg/icss_iep.c b/drivers/net/ethernet/ti/icssg/icss_iep.c
> index 3025e9c18970..b076be9c527c 100644
> --- a/drivers/net/ethernet/ti/icssg/icss_iep.c
> +++ b/drivers/net/ethernet/ti/icssg/icss_iep.c
> @@ -17,6 +17,7 @@
>  #include <linux/timekeeping.h>
>  #include <linux/interrupt.h>
>  #include <linux/of_irq.h>
> +#include <linux/workqueue.h>
>  
>  #include "icss_iep.h"
>  
> @@ -122,6 +123,7 @@ struct icss_iep {
>  	int cap_cmp_irq;
>  	u64 period;
>  	u32 latch_enable;
> +	struct work_struct work;
>  };
>  
>  /**
> @@ -571,6 +573,57 @@ static int icss_iep_perout_enable(struct icss_iep *iep,
>  	return ret;
>  }
>  
> +static void icss_iep_cap_cmp_work(struct work_struct *work)
> +{
> +	struct icss_iep *iep = container_of(work, struct icss_iep, work);
> +	const u32 *reg_offs = iep->plat_data->reg_offs;
> +	struct ptp_clock_event pevent;
> +	unsigned int val;
> +	u64 ns, ns_next;
> +
> +	spin_lock(&iep->irq_lock);
> +
> +	ns = readl(iep->base + reg_offs[ICSS_IEP_CMP1_REG0]);
> +	if (iep->plat_data->flags & ICSS_IEP_64BIT_COUNTER_SUPPORT) {
> +		val = readl(iep->base + reg_offs[ICSS_IEP_CMP1_REG1]);
> +		ns |= (u64)val << 32;
> +	}
> +	/* set next event */
> +	ns_next = ns + iep->period;
> +	writel(lower_32_bits(ns_next),
> +	       iep->base + reg_offs[ICSS_IEP_CMP1_REG0]);
> +	if (iep->plat_data->flags & ICSS_IEP_64BIT_COUNTER_SUPPORT)
> +		writel(upper_32_bits(ns_next),
> +		       iep->base + reg_offs[ICSS_IEP_CMP1_REG1]);
> +
> +	pevent.pps_times.ts_real = ns_to_timespec64(ns);
> +	pevent.type = PTP_CLOCK_PPSUSR;
> +	pevent.index = 0;
> +	ptp_clock_event(iep->ptp_clock, &pevent);
> +	dev_dbg(iep->dev, "IEP:pps ts: %llu next:%llu:\n", ns, ns_next);
> +
> +	spin_unlock(&iep->irq_lock);
> +}
> +
> +static irqreturn_t icss_iep_cap_cmp_irq(int irq, void *dev_id)
> +{
> +	struct icss_iep *iep = (struct icss_iep *)dev_id;
> +	const u32 *reg_offs = iep->plat_data->reg_offs;
> +	unsigned int val;
> +
> +	val = readl(iep->base + reg_offs[ICSS_IEP_CMP_STAT_REG]);
> +	/* The driver only enables CMP1 */
> +	if (val & BIT(1)) {
> +		/* Clear the event */
> +		writel(BIT(1), iep->base + reg_offs[ICSS_IEP_CMP_STAT_REG]);
> +		if (iep->pps_enabled || iep->perout_enabled)
> +			schedule_work(&iep->work);
> +		return IRQ_HANDLED;
> +	}
> +
> +	return IRQ_NONE;
> +}
> +
>  static int icss_iep_pps_enable(struct icss_iep *iep, int on)
>  {
>  	struct ptp_clock_request rq;
> @@ -602,6 +655,8 @@ static int icss_iep_pps_enable(struct icss_iep *iep, int on)
>  		ret = icss_iep_perout_enable_hw(iep, &rq.perout, on);
>  	} else {
>  		ret = icss_iep_perout_enable_hw(iep, &rq.perout, on);
> +		if (iep->cap_cmp_irq)
> +			cancel_work_sync(&iep->work);
>  	}
>  
>  	if (!ret)
> @@ -777,6 +832,8 @@ int icss_iep_init(struct icss_iep *iep, const struct icss_iep_clockops *clkops,
>  	if (iep->ops && iep->ops->perout_enable) {
>  		iep->ptp_info.n_per_out = 1;
>  		iep->ptp_info.pps = 1;
> +	} else if (iep->cap_cmp_irq) {
> +		iep->ptp_info.pps = 1;
>  	}
>  
>  	if (iep->ops && iep->ops->extts_enable)
> @@ -817,6 +874,7 @@ static int icss_iep_probe(struct platform_device *pdev)
>  	struct device *dev = &pdev->dev;
>  	struct icss_iep *iep;
>  	struct clk *iep_clk;
> +	int ret, irq;
>  
>  	iep = devm_kzalloc(dev, sizeof(*iep), GFP_KERNEL);
>  	if (!iep)
> @@ -827,6 +885,22 @@ static int icss_iep_probe(struct platform_device *pdev)
>  	if (IS_ERR(iep->base))
>  		return -ENODEV;
>  
> +	irq = platform_get_irq_byname_optional(pdev, "iep_cap_cmp");
> +	if (irq == -EPROBE_DEFER)
> +		return irq;
> +
> +	if (irq > 0) {
> +		ret = devm_request_irq(dev, irq, icss_iep_cap_cmp_irq,
> +				       IRQF_TRIGGER_HIGH, "iep_cap_cmp", iep);
> +		if (ret) {
> +			dev_info(iep->dev, "cap_cmp irq request failed: %x\n",
> +				 ret);
> +		} else {
> +			iep->cap_cmp_irq = irq;
> +			INIT_WORK(&iep->work, icss_iep_cap_cmp_work);
> +		}
> +	}
> +
>  	iep_clk = devm_clk_get(dev, NULL);
>  	if (IS_ERR(iep_clk))
>  		return PTR_ERR(iep_clk);
> 

  reply	other threads:[~2024-06-04 14:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-04 13:15 [PATCH net-next v2 0/3] Enable PTP timestamping/PPS for AM65x SR1.0 devices Diogo Ivo
2024-06-04 13:15 ` [PATCH net-next v2 1/3] net: ti: icssg-prueth: Enable PTP timestamping support for " Diogo Ivo
2024-06-04 14:19   ` Wojciech Drewek
2024-06-04 13:15 ` [PATCH net-next v2 2/3] net: ti: icss-iep: Enable compare events Diogo Ivo
2024-06-04 14:23   ` Wojciech Drewek [this message]
2024-06-06 10:32   ` Paolo Abeni
2024-06-06 13:28     ` Diogo Ivo
2024-06-06 13:49       ` Paolo Abeni
2024-06-06 15:43         ` Diogo Ivo
2024-06-04 13:15 ` [PATCH net-next v2 3/3] arm64: dts: ti: iot2050: Add IEP interrupts for SR1.0 devices Diogo Ivo

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=00dab591-0521-4165-a5a5-216dc9aa8d08@intel.com \
    --to=wojciech.drewek@intel.com \
    --cc=conor+dt@kernel.org \
    --cc=danishanwar@ti.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=diogo.ivo@siemens.com \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jacob.e.keller@intel.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kristo@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=robh@kernel.org \
    --cc=rogerq@kernel.org \
    --cc=vigneshr@ti.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