Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp738383lqb; Wed, 29 May 2024 09:07:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVnanFIW5GDB++frqiP3H2QWid1URmLLn/sAhAI9kJw06a9maKX0UVlbuu+4qmk6+j3DuXOiidzlRBEhMhOTLOKA5UYNxNZHLnjSJLKCw== X-Google-Smtp-Source: AGHT+IFWece3vj2kIUEuYOh4rSsgNXf3PxUDTi1qMDt/JezEndR15cm4tRG0v/xkbcnf9KswUKRR X-Received: by 2002:a17:902:ecc3:b0:1f4:96aa:f45d with SMTP id d9443c01a7336-1f496aaf716mr98340605ad.22.1716998840268; Wed, 29 May 2024 09:07:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716998840; cv=pass; d=google.com; s=arc-20160816; b=SYlNpy3bovznpzsDdg58ufBf/Ju6r3a4Q9WfwP5Enrl9uzAnCwRIgyFZL7je7UFlYI oObN9Q7wcEj1JBzVNaCrk8Q6clNT9SuswpTZOV+RW7/FSqAU8N5YvtPZ9SU5BHp07UeI XzH6gScEqJMhwk4B1YePa2kbxqmXW7m7aHwGvczO5eKys9ETJyT33+aOlW+DmpqujPa0 LOSQjXZvn0nI4br6Wkm3j/F+LmDPJCz66lxBJEqDmt/MQcQGK+epMQErRBzRVz78DgoY psAHBOcNueaYKydR5goA909V6FQYGodXd02ghjNkXuYbsTDHJSAD47VguAxbRvHYNvJ8 9K5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=feedback-id:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:subject:date:from:dkim-signature; bh=nwXt6q8QKspJwmhkWLeD3CLZmgPMizmWsw7PtC72yaI=; fh=O31swR33Q9BCrCgZsims0e0hEnEA7XKhc6flmHI4BT8=; b=dZWXRF+MNXGUsTRnVXciOkXpHHjuglrqt/ulVz8WKpV8ay8XyGRuhXdugTu9KyR9fJ 3dfPITMfv2mI375nQa9/lUYJFMsJRg4OyppwNEmAOkrnx5drC/Gt7pv4iMdIjZOm81Tq /48vTLM770DSzKZb5WyoxxWYpXPu7k7rh3z4hw524pB506USYi8Flg2+PL65dDqIuEs0 KGWSa4P/cTXPEIgMIlpCcnPFE4Gab3I8F0nqfyHQtRWENHI/j4+sRx2nb//1Dtj8+bNE wt3op9nCM20KbiZmPClawp4I18jlmv7EFA8Aeoqip1LqlWiRCM9rTU6Hy2yef/IQDZCW 9y1g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm2 header.b=Ub05n4wz; arc=pass (i=1 spf=pass spfdomain=rts-flowmailer.siemens.com dkim=pass dkdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of linux-kernel+bounces-194413-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194413-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6bdb187dc64si650653a12.874.2024.05.29.09.07.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 09:07:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194413-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@siemens.com header.s=fm2 header.b=Ub05n4wz; arc=pass (i=1 spf=pass spfdomain=rts-flowmailer.siemens.com dkim=pass dkdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of linux-kernel+bounces-194413-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194413-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AB2BE285F04 for ; Wed, 29 May 2024 16:06:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 66E70187322; Wed, 29 May 2024 16:05:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=siemens.com header.i=diogo.ivo@siemens.com header.b="Ub05n4wz" Received: from mta-65-227.siemens.flowmailer.net (mta-65-227.siemens.flowmailer.net [185.136.65.227]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9899B1836FB for ; Wed, 29 May 2024 16:05:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.136.65.227 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716998745; cv=none; b=qxI5C1lme2gbEbKamhR5FBFVSDyc3wPjXNbj414KjKt3TwskfN7XNVf7a7Lf4kRX7cpNvV/sbADyN9EWbVhw4FikqKwGRooU/CT4WO62TR+dWukQMmkURgwSXn9X0i20S+3kAUPHO3GPWNFoPRcAtLPSdP4By5QXTZjVF3LVkPU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716998745; c=relaxed/simple; bh=GBHTWr2BnrN47pHjde4zU2Ymt2L9Uyv/LPS9yMcrrpQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qfJUiyuHwB2qfpMycDYWvl67TIkXnFjQQuRzs0b/O5aHnUNbYdHkhkd7vTnlakz3PP9ONaybx18cKjyoS/N+6X7aoL8JC6/2hVXWVfVrdpAoPqDHh+03m5PLnb8LCxZBhEZBMe88hNsUON1EqM8ab8XyzuJEN6mS8hhLhX5WPoo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=siemens.com; spf=pass smtp.mailfrom=rts-flowmailer.siemens.com; dkim=pass (1024-bit key) header.d=siemens.com header.i=diogo.ivo@siemens.com header.b=Ub05n4wz; arc=none smtp.client-ip=185.136.65.227 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=siemens.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rts-flowmailer.siemens.com Received: by mta-65-227.siemens.flowmailer.net with ESMTPSA id 202405291605367a5e7de430fadb1513 for ; Wed, 29 May 2024 18:05:36 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm2; d=siemens.com; i=diogo.ivo@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=nwXt6q8QKspJwmhkWLeD3CLZmgPMizmWsw7PtC72yaI=; b=Ub05n4wzAPstphetgUBoyH9OsOW1oxLs8CCqs3WasDCip2xIEI6gd7+vCXobNZFCmuNsDq DeNKGRm1H5sACHL4jgVMPuDmu1UOSW5jtGo89bCGHdURV44B2bYfJDvDoMYAu3K7qkVUiaBj OkjDaDlDcFk0kpT6G00tXTReV62TI=; From: Diogo Ivo Date: Wed, 29 May 2024 17:05:11 +0100 Subject: [PATCH 2/3] net: ti: icss-iep: Enable compare events Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240529-iep-v1-2-7273c07592d3@siemens.com> References: <20240529-iep-v1-0-7273c07592d3@siemens.com> In-Reply-To: <20240529-iep-v1-0-7273c07592d3@siemens.com> To: MD Danish Anwar , Roger Quadros , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jan Kiszka Cc: linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Diogo Ivo X-Developer-Signature: v=1; a=ed25519-sha256; t=1716998732; l=4374; i=diogo.ivo@siemens.com; s=20240529; h=from:subject:message-id; bh=GBHTWr2BnrN47pHjde4zU2Ymt2L9Uyv/LPS9yMcrrpQ=; b=CBoxiMoLa+EbsUCvAE0tkPjV2/mnvh7/5mbTG4DrmbNhVn/xV6vxoaYZtb8ftR6Rnv9Y5/DSH YaBM0ITea7wAdUJOI0/x2wGTDnkPQFX57+6z3uojexZgE3P+4S+62Cj X-Developer-Key: i=diogo.ivo@siemens.com; a=ed25519; pk=BRGXhMh1q5KDlZ9y2B8SodFFY8FGupal+NMtJPwRpUQ= X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-1320519:519-21489:flowmailer 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. Signed-off-by: Diogo Ivo --- drivers/net/ethernet/ti/icssg/icss_iep.c | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/drivers/net/ethernet/ti/icssg/icss_iep.c b/drivers/net/ethernet/ti/icssg/icss_iep.c index 3025e9c18970..8337508ce8f0 100644 --- a/drivers/net/ethernet/ti/icssg/icss_iep.c +++ b/drivers/net/ethernet/ti/icssg/icss_iep.c @@ -17,6 +17,7 @@ #include #include #include +#include #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,55 @@ 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); + struct ptp_clock_event pevent; + unsigned int val; + u64 ns, ns_next; + + spin_lock(&iep->irq_lock); + + ns = readl(iep->base + iep->plat_data->reg_offs[ICSS_IEP_CMP1_REG0]); + if (iep->plat_data->flags & ICSS_IEP_64BIT_COUNTER_SUPPORT) { + val = readl(iep->base + iep->plat_data->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 + iep->plat_data->reg_offs[ICSS_IEP_CMP1_REG0]); + if (iep->plat_data->flags & ICSS_IEP_64BIT_COUNTER_SUPPORT) + writel(upper_32_bits(ns_next), + iep->base + iep->plat_data->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; + unsigned int val; + + val = readl(iep->base + iep->plat_data->reg_offs[ICSS_IEP_CMP_STAT_REG]); + /* The driver only enables CMP1 */ + if (val & BIT(1)) { + /* Clear the event */ + writel(BIT(1), iep->base + iep->plat_data->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 +653,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 +830,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 +872,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; iep = devm_kzalloc(dev, sizeof(*iep), GFP_KERNEL); if (!iep) @@ -827,6 +883,21 @@ static int icss_iep_probe(struct platform_device *pdev) if (IS_ERR(iep->base)) return -ENODEV; + iep->cap_cmp_irq = platform_get_irq_byname_optional(pdev, "iep_cap_cmp"); + if (iep->cap_cmp_irq < 0) { + if (iep->cap_cmp_irq == -EPROBE_DEFER) + return iep->cap_cmp_irq; + iep->cap_cmp_irq = 0; + } else { + ret = devm_request_irq(dev, iep->cap_cmp_irq, + icss_iep_cap_cmp_irq, IRQF_TRIGGER_HIGH, + "iep_cap_cmp", iep); + if (ret) + return dev_err_probe(iep->dev, ret, + "Request irq failed for cap_cmp\n"); + 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); -- 2.45.1