Linux-SPI Archive mirror
 help / color / mirror / Atom feed
From: Eddie James <eajames@linux.ibm.com>
To: linux-fsi@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org,
	linux-spi@vger.kernel.org, broonie@kernel.org,
	andi.shyti@kernel.org, joel@jms.id.au, alistair@popple.id.au,
	jk@ozlabs.org, andrew@codeconstruct.com.au,
	linux-aspeed@lists.ozlabs.org, eajames@linux.ibm.com
Subject: [PATCH v3 24/40] fsi: aspeed: Add interrupt support
Date: Thu, 16 May 2024 13:18:51 -0500	[thread overview]
Message-ID: <20240516181907.3468796-25-eajames@linux.ibm.com> (raw)
In-Reply-To: <20240516181907.3468796-1-eajames@linux.ibm.com>

Handle slave interrupts and pass them to the FSI core.

Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
 drivers/fsi/fsi-master-aspeed.c          | 106 ++++++++++++++++++++++-
 include/trace/events/fsi_master_aspeed.h |  12 +++
 2 files changed, 115 insertions(+), 3 deletions(-)

diff --git a/drivers/fsi/fsi-master-aspeed.c b/drivers/fsi/fsi-master-aspeed.c
index eecd64bc29512..34f4c9e00e43d 100644
--- a/drivers/fsi/fsi-master-aspeed.c
+++ b/drivers/fsi/fsi-master-aspeed.c
@@ -6,6 +6,8 @@
 #include <linux/delay.h>
 #include <linux/fsi.h>
 #include <linux/io.h>
+#include <linux/irqchip/chained_irq.h>
+#include <linux/irqdomain.h>
 #include <linux/mfd/syscon.h>
 #include <linux/module.h>
 #include <linux/of.h>
@@ -25,11 +27,13 @@ struct fsi_master_aspeed_data {
 struct fsi_master_aspeed {
 	struct fsi_master	master;
 	spinlock_t		lock;	/* protect HW access */
+	struct irq_domain	*irq_domain;
 	struct device		*dev;
 	void __iomem		*base;
 	void __iomem		*ctrl;
 	struct clk		*clk;
 	struct gpio_desc	*cfam_reset_gpio;
+	u32			irq_mask;
 };
 
 #define to_fsi_master_aspeed(m) \
@@ -79,6 +83,11 @@ static const u32 fsi_base = 0xa0000000;
 #define STATUS_TIMEOUT		BIT(4)
 
 /* OPB_IRQ_MASK */
+#define FSI_MASTER_ERROR_IRQ	BIT(28)
+#define FSI_PORT_ERROR_IRQ	BIT(27)
+#define FSI_HOTPLUG_IRQ		BIT(26)
+#define FSI_REMOTE_SLV_IRQ(l)	(BIT(FSI_REMOTE_SLV_IRQ_BIT) << (l))
+#define FSI_REMOTE_SLV_IRQ_BIT	18
 #define OPB1_XFER_ACK_EN BIT(17)
 #define OPB0_XFER_ACK_EN BIT(16)
 
@@ -96,7 +105,7 @@ static const u32 fsi_base = 0xa0000000;
 #define OPB_RC_CTRL_OPB		BIT(18)	/* Access controller over OPB, not AHB (AST27xx+) */
 #define OPB_RC_XFER_ACK_EN	BIT(16)	/* Enable OPBx xfer ack bit without mask */
 #define OPB_RC_COUNT		GENMASK(15, 0)	/* Number of retries */
-#define OPB_RC_DEFAULT		0x10
+#define OPB_RC_DEFAULT		(OPB_RC_XFER_ACK_EN | 0x10)
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/fsi_master_aspeed.h>
@@ -322,11 +331,76 @@ static int aspeed_master_break(struct fsi_master *master, int link)
 	return aspeed_master_write(master, link, 0, addr, &cmd, 4);
 }
 
+static int aspeed_master_link_enable(struct fsi_master *master, int link, bool enable)
+{
+	struct fsi_master_aspeed *aspeed = to_fsi_master_aspeed(master);
+	unsigned long flags;
+	int rc;
+
+	spin_lock_irqsave(&aspeed->lock, flags);
+	if (enable) {
+		rc = fsi_master_link_enable(master, link, enable);
+		if (rc)
+			goto done;
+
+		aspeed->irq_mask |= FSI_REMOTE_SLV_IRQ(link);
+		writel(aspeed->irq_mask, aspeed->base + OPB_IRQ_MASK);
+	} else {
+		aspeed->irq_mask &= ~FSI_REMOTE_SLV_IRQ(link);
+		writel(aspeed->irq_mask, aspeed->base + OPB_IRQ_MASK);
+
+		rc = fsi_master_link_enable(master, link, enable);
+	}
+
+done:
+	spin_unlock_irqrestore(&aspeed->lock, flags);
+	return rc;
+}
+
+static irqreturn_t aspeed_master_irq(int irq, void *data)
+{
+	struct fsi_master_aspeed *aspeed = data;
+	unsigned long size = FSI_REMOTE_SLV_IRQ_BIT + aspeed->master.n_links;
+	unsigned long bit = FSI_REMOTE_SLV_IRQ_BIT;
+	unsigned long status;
+
+	status = readl(aspeed->base + OPB_IRQ_STATUS);
+	writel(0, aspeed->base + OPB_IRQ_MASK);
+
+	for_each_set_bit_from(bit, &status, size)
+		fsi_master_irq(&aspeed->master, aspeed->irq_domain, bit - FSI_REMOTE_SLV_IRQ_BIT);
+
+	writel(status, aspeed->base + OPB_IRQ_STATUS);
+	writel(0, aspeed->base + OPB_IRQ_STATUS);
+	writel(aspeed->irq_mask, aspeed->base + OPB_IRQ_MASK);
+
+	trace_fsi_master_aspeed_irq(status);
+	return IRQ_HANDLED;
+}
+
+static int aspeed_master_irqd_map(struct irq_domain *domain, unsigned int irq,
+				  irq_hw_number_t hwirq)
+{
+	struct fsi_master_aspeed *aspeed = domain->host_data;
+
+	irq_set_chip_and_handler(irq, &aspeed->master.irq_chip, handle_simple_irq);
+	irq_set_chip_data(irq, &aspeed->master);
+
+	return 0;
+}
+
+static const struct irq_domain_ops aspeed_master_irq_domain_ops = {
+	.map = aspeed_master_irqd_map,
+};
+
 static void aspeed_master_release(struct device *dev)
 {
 	struct fsi_master_aspeed *aspeed =
 		to_fsi_master_aspeed(to_fsi_master(dev));
 
+	if (aspeed->irq_domain)
+		irq_domain_remove(aspeed->irq_domain);
+
 	regmap_exit(aspeed->master.map);
 	kfree(aspeed);
 }
@@ -477,6 +551,7 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev)
 	struct resource *res;
 	unsigned int reg;
 	int rc, links;
+	int irq;
 
 	rc = tacoma_cabled_fsi_fixup(&pdev->dev);
 	if (rc) {
@@ -567,11 +642,12 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev)
 	aspeed->master.dev.of_node = of_node_get(dev_of_node(&pdev->dev));
 
 	aspeed->master.n_links = links;
-	aspeed->master.flags = FSI_MASTER_FLAG_RELA;
+	aspeed->master.flags = FSI_MASTER_FLAG_INTERRUPT | FSI_MASTER_FLAG_RELA;
 	aspeed->master.read = aspeed_master_read;
 	aspeed->master.write = aspeed_master_write;
 	aspeed->master.send_break = aspeed_master_break;
 	aspeed->master.term = aspeed_master_term;
+	aspeed->master.link_enable = aspeed_master_link_enable;
 
 	dev_set_drvdata(&pdev->dev, aspeed);
 
@@ -579,9 +655,30 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev)
 	if (rc)
 		goto err_regmap;
 
+	irq = platform_get_irq(pdev, 0);
+	if (irq > 0) {
+		unsigned int size = links * FSI_IRQ_COUNT;
+
+		aspeed->irq_domain = irq_domain_add_linear(aspeed->dev->of_node, size,
+							   &aspeed_master_irq_domain_ops, aspeed);
+		if (aspeed->irq_domain) {
+			rc = devm_request_irq(aspeed->dev, irq, aspeed_master_irq, 0,
+					      dev_name(aspeed->dev), aspeed);
+			if (rc) {
+				dev_warn(aspeed->dev, "failed to request irq:%d\n", irq);
+				irq_domain_remove(aspeed->irq_domain);
+				aspeed->irq_domain = NULL;
+			} else {
+				dev_info(aspeed->dev, "enabling interrupts irq:%d\n", irq);
+			}
+		} else {
+			dev_warn(aspeed->dev, "failed to create irq domain\n");
+		}
+	}
+
 	rc = fsi_master_register(&aspeed->master);
 	if (rc)
-		goto err_regmap;
+		goto err_irq;
 
 	/* At this point, fsi_master_register performs the device_initialize(),
 	 * and holds the sole reference on master.dev. This means the device
@@ -593,6 +690,9 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev)
 	get_device(&aspeed->master.dev);
 	return 0;
 
+err_irq:
+	if (aspeed->irq_domain)
+		irq_domain_remove(aspeed->irq_domain);
 err_regmap:
 	regmap_exit(aspeed->master.map);
 err_release:
diff --git a/include/trace/events/fsi_master_aspeed.h b/include/trace/events/fsi_master_aspeed.h
index 7eeecbfec7f09..dba1776334a0e 100644
--- a/include/trace/events/fsi_master_aspeed.h
+++ b/include/trace/events/fsi_master_aspeed.h
@@ -8,6 +8,18 @@
 
 #include <linux/tracepoint.h>
 
+TRACE_EVENT(fsi_master_aspeed_irq,
+	TP_PROTO(uint32_t status),
+	TP_ARGS(status),
+	TP_STRUCT__entry(
+		__field(uint32_t, status)
+	),
+	TP_fast_assign(
+		__entry->status = status;
+	),
+	TP_printk("status %08x", __entry->status)
+);
+
 TRACE_EVENT(fsi_master_aspeed_opb_xfer,
 	TP_PROTO(uint32_t addr, uint32_t size, uint32_t data, bool read),
 	TP_ARGS(addr, size, data, read),
-- 
2.39.3


  parent reply	other threads:[~2024-05-16 18:19 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-16 18:18 [PATCH v3 00/40] fsi: Add interrupt support Eddie James
2024-05-16 18:18 ` [PATCH v3 01/40] fsi: hub: Set master index to link number plus one Eddie James
2024-05-16 18:18 ` [PATCH v3 02/40] fsi: Move slave definitions to fsi-slave.h Eddie James
2024-05-16 18:18 ` [PATCH v3 03/40] fsi: Fix slave addressing after break command Eddie James
2024-05-16 18:18 ` [PATCH v3 04/40] fsi: Use a defined value for default echo delay Eddie James
2024-05-16 18:18 ` [PATCH v3 05/40] fsi: Calculate local bus clock frequency Eddie James
2024-05-16 18:18 ` [PATCH v3 06/40] fsi: core: Improve master read/write/error traces Eddie James
2024-05-16 18:18 ` [PATCH v3 07/40] fsi: core: Add slave error trace Eddie James
2024-05-16 18:18 ` [PATCH v3 08/40] fsi: core: Reset errors instead of clearing interrupts Eddie James
2024-05-16 18:18 ` [PATCH v3 09/40] fsi: aspeed: Add AST2700 support Eddie James
2024-05-16 18:18 ` [PATCH v3 10/40] fsi: core: Add slave spinlock Eddie James
2024-05-16 18:18 ` [PATCH v3 11/40] fsi: core: Allow cfam device type aliases Eddie James
2024-05-16 18:18 ` [PATCH v3 12/40] fsi: core: Add common regmap master functions Eddie James
2024-05-16 18:18 ` [PATCH v3 13/40] fsi: core: Disable relative addressing during scan Eddie James
2024-05-16 18:18 ` [PATCH v3 14/40] fsi: hub: Use common initialization and link enable Eddie James
2024-05-16 18:18 ` [PATCH v3 15/40] fsi: aspeed: " Eddie James
2024-05-16 18:18 ` [PATCH v3 16/40] fsi: aspeed: Remove cfam reset sysfs file in error path and remove Eddie James
2024-05-16 18:18 ` [PATCH v3 17/40] fsi: aspeed: Refactor trace functions Eddie James
2024-05-16 18:18 ` [PATCH v3 18/40] fsi: aspeed: Don't clear all IRQs during OPB transfers Eddie James
2024-05-16 18:18 ` [PATCH v3 19/40] fsi: aspeed: Only read result register for successful read Eddie James
2024-05-16 18:18 ` [PATCH v3 20/40] fsi: aspeed: Switch to spinlock Eddie James
2024-05-16 18:18 ` [PATCH v3 21/40] fsi: aspeed: Disable relative addressing and IPOLL for cfam reset Eddie James
2024-05-16 18:18 ` [PATCH v3 22/40] fsi: aspeed: Use common master error handler Eddie James
2024-05-16 18:18 ` [PATCH v3 23/40] fsi: core: Add interrupt support Eddie James
2024-05-17 20:41   ` kernel test robot
2024-05-16 18:18 ` Eddie James [this message]
2024-05-16 18:18 ` [PATCH v3 25/40] fsi: hub: " Eddie James
2024-05-16 18:18 ` [PATCH v3 26/40] i2c: fsi: Calculate clock divider from local bus frequency Eddie James
2024-05-16 18:18 ` [PATCH v3 27/40] i2c: fsi: Improve formatting Eddie James
2024-05-16 18:18 ` [PATCH v3 28/40] i2c: fsi: Change fsi_i2c_write_reg to accept data instead of a pointer Eddie James
2024-05-16 18:18 ` [PATCH v3 29/40] i2c: fsi: Remove list structure of ports Eddie James
2024-05-16 18:18 ` [PATCH v3 30/40] i2c: fsi: Define a function to check status error bits Eddie James
2024-05-16 18:18 ` [PATCH v3 31/40] i2c: fsi: Add boolean for skip stop command on abort Eddie James
2024-05-16 18:18 ` [PATCH v3 32/40] i2c: fsi: Add interrupt support Eddie James
2024-05-16 18:19 ` [PATCH v3 33/40] fsi: hub master: Reset hub master after errors Eddie James
2024-05-16 18:19 ` [PATCH v3 34/40] fsi: core: Add master register read-only sysfs Eddie James
2024-05-16 18:19 ` [PATCH v3 35/40] fsi: core: Add slave " Eddie James
2024-05-16 18:19 ` [PATCH v3 36/40] fsi: i2cr: Adjust virtual CFAM ID to match Odyssey chip Eddie James
2024-05-16 18:19 ` [PATCH v3 37/40] fsi: core: Add different types of CFAM Eddie James
2024-05-17 12:38   ` kernel test robot
2024-05-17 15:49   ` kernel test robot
2024-05-18  1:03   ` kernel test robot
2024-05-16 18:19 ` [PATCH v3 38/40] spi: fsi: Calculate clock divider from local bus frequency Eddie James
2024-05-16 18:24   ` Mark Brown
2024-05-16 18:19 ` [PATCH v3 39/40] ARM: dts: aspeed: P10 and tacoma: Set FSI clock frequency Eddie James
2024-05-16 18:19 ` [PATCH v3 40/40] ARM: dts: aspeed: P10: Bump SPI max frequencies Eddie James

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=20240516181907.3468796-25-eajames@linux.ibm.com \
    --to=eajames@linux.ibm.com \
    --cc=alistair@popple.id.au \
    --cc=andi.shyti@kernel.org \
    --cc=andrew@codeconstruct.com.au \
    --cc=broonie@kernel.org \
    --cc=jk@ozlabs.org \
    --cc=joel@jms.id.au \
    --cc=linux-aspeed@lists.ozlabs.org \
    --cc=linux-fsi@lists.ozlabs.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).