All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: linux-arm-kernel@lists.infradead.org,
	Imre Kaloz <kaloz@openwrt.org>,
	Krzysztof Halasa <khalasa@piap.pl>
Cc: Linus Walleij <linus.walleij@linaro.org>
Subject: [PATCH 25/30 v2] soc: ixp4xx: qmgr: Pass resources
Date: Thu, 21 Feb 2019 16:44:53 +0100	[thread overview]
Message-ID: <20190221154458.23763-26-linus.walleij@linaro.org> (raw)
In-Reply-To: <20190221154458.23763-1-linus.walleij@linaro.org>

Instead of using hardcoded base address implicitly
obtained through <linux/io.h>, pass the physical base
for the QMGR block as a memory resource and remap
it in the driver.

Also pass the two IRQs as resources and obtain them
in the driver.

Use devm_* accessors and simplify the error path in the
process. Drop memory region request as this is done by
the devm_ioremap* functions.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/mach-ixp4xx/common.c                 | 25 +++++--
 .../mach-ixp4xx/include/mach/ixp4xx-regs.h    |  2 -
 drivers/soc/ixp4xx/ixp4xx-qmgr.c              | 71 +++++++++----------
 3 files changed, 55 insertions(+), 43 deletions(-)

diff --git a/arch/arm/mach-ixp4xx/common.c b/arch/arm/mach-ixp4xx/common.c
index 07c3cb312a92..cc5f15679d29 100644
--- a/arch/arm/mach-ixp4xx/common.c
+++ b/arch/arm/mach-ixp4xx/common.c
@@ -66,11 +66,6 @@ static struct map_desc ixp4xx_io_desc[] __initdata = {
 		.pfn		= __phys_to_pfn(IXP4XX_PCI_CFG_BASE_PHYS),
 		.length		= IXP4XX_PCI_CFG_REGION_SIZE,
 		.type		= MT_DEVICE
-	}, {	/* Queue Manager */
-		.virtual	= (unsigned long)IXP4XX_QMGR_BASE_VIRT,
-		.pfn		= __phys_to_pfn(IXP4XX_QMGR_BASE_PHYS),
-		.length		= IXP4XX_QMGR_REGION_SIZE,
-		.type		= MT_DEVICE
 	},
 };
 
@@ -176,9 +171,29 @@ static struct platform_device ixp4xx_npe_device = {
 	.resource       = ixp4xx_npe_resources,
 };
 
+static struct resource ixp4xx_qmgr_resources[] = {
+	{
+		.start = IXP4XX_QMGR_BASE_PHYS,
+		.end = IXP4XX_QMGR_BASE_PHYS + 0x3fff,
+		.flags = IORESOURCE_MEM,
+	},
+	{
+		.start = IRQ_IXP4XX_QM1,
+		.end = IRQ_IXP4XX_QM1,
+		.flags = IORESOURCE_IRQ,
+	},
+	{
+		.start = IRQ_IXP4XX_QM2,
+		.end = IRQ_IXP4XX_QM2,
+		.flags = IORESOURCE_IRQ,
+	},
+};
+
 static struct platform_device ixp4xx_qmgr_device = {
 	.name           = "ixp4xx-qmgr",
 	.id             = -1,
+	.num_resources  = ARRAY_SIZE(ixp4xx_qmgr_resources),
+	.resource       = ixp4xx_qmgr_resources,
 };
 
 static struct platform_device *ixp4xx_devices[] __initdata = {
diff --git a/arch/arm/mach-ixp4xx/include/mach/ixp4xx-regs.h b/arch/arm/mach-ixp4xx/include/mach/ixp4xx-regs.h
index f5d5b258c3f7..588b76651085 100644
--- a/arch/arm/mach-ixp4xx/include/mach/ixp4xx-regs.h
+++ b/arch/arm/mach-ixp4xx/include/mach/ixp4xx-regs.h
@@ -43,8 +43,6 @@
  * Queue Manager
  */
 #define IXP4XX_QMGR_BASE_PHYS		0x60000000
-#define IXP4XX_QMGR_BASE_VIRT		IOMEM(0xFEF15000)
-#define IXP4XX_QMGR_REGION_SIZE		0x00004000
 
 /*
  * Peripheral space, including debug UART. Must be section-aligned so that
diff --git a/drivers/soc/ixp4xx/ixp4xx-qmgr.c b/drivers/soc/ixp4xx/ixp4xx-qmgr.c
index f3775346e007..64572f2d6ff0 100644
--- a/drivers/soc/ixp4xx/ixp4xx-qmgr.c
+++ b/drivers/soc/ixp4xx/ixp4xx-qmgr.c
@@ -16,13 +16,9 @@
 #include <linux/platform_device.h>
 #include <linux/soc/ixp4xx/qmgr.h>
 
-/* FIXME: get rid of these static assigments */
-#define IRQ_IXP4XX_BASE		16
-#define IRQ_IXP4XX_QM1		(IRQ_IXP4XX_BASE + 3)
-#define IRQ_IXP4XX_QM2		(IRQ_IXP4XX_BASE + 4)
-
-static struct qmgr_regs __iomem *qmgr_regs = IXP4XX_QMGR_BASE_VIRT;
-static struct resource *mem_res;
+static struct qmgr_regs __iomem *qmgr_regs;
+static int qmgr_irq_1;
+static int qmgr_irq_2;
 static spinlock_t qmgr_lock;
 static u32 used_sram_bitmap[4]; /* 128 16-dword pages */
 static void (*irq_handlers[QUEUES])(void *pdev);
@@ -190,7 +186,7 @@ static irqreturn_t qmgr_irq2_a0(int irq, void *pdev)
 
 static irqreturn_t qmgr_irq(int irq, void *pdev)
 {
-	int i, half = (irq == IRQ_IXP4XX_QM1 ? 0 : 1);
+	int i, half = (irq == qmgr_irq_1 ? 0 : 1);
 	u32 req_bitmap = __raw_readl(&qmgr_regs->irqstat[half]);
 
 	if (!req_bitmap)
@@ -381,12 +377,25 @@ static int ixp4xx_qmgr_probe(struct platform_device *pdev)
 {
 	int i, err;
 	irq_handler_t handler1, handler2;
+	struct device *dev = &pdev->dev;
+	struct resource *res;
+	int irq1, irq2;
 
-	mem_res = request_mem_region(IXP4XX_QMGR_BASE_PHYS,
-				     IXP4XX_QMGR_REGION_SIZE,
-				     "IXP4xx Queue Manager");
-	if (mem_res == NULL)
-		return -EBUSY;
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -ENODEV;
+	qmgr_regs = devm_ioremap_resource(dev, res);
+	if (!qmgr_regs)
+		return -ENOMEM;
+
+	irq1 = platform_get_irq(pdev, 0);
+	if (irq1 <= 0)
+		return irq1 ? irq1 : -EINVAL;
+	qmgr_irq_1 = irq1;
+	irq2 = platform_get_irq(pdev, 1);
+	if (irq2 <= 0)
+		return irq2 ? irq2 : -EINVAL;
+	qmgr_irq_2 = irq2;
 
 	/* reset qmgr registers */
 	for (i = 0; i < 4; i++) {
@@ -411,43 +420,33 @@ static int ixp4xx_qmgr_probe(struct platform_device *pdev)
 	} else
 		handler1 = handler2 = qmgr_irq;
 
-	err = request_irq(IRQ_IXP4XX_QM1, handler1, 0, "IXP4xx Queue Manager",
-			  NULL);
+	err = devm_request_irq(dev, irq1, handler1, 0, "IXP4xx Queue Manager",
+			       NULL);
 	if (err) {
-		printk(KERN_ERR "qmgr: failed to request IRQ%i (%i)\n",
-		       IRQ_IXP4XX_QM1, err);
-		goto error_irq;
+		dev_err(dev, "failed to request IRQ%i (%i)\n",
+			irq1, err);
+		return err;
 	}
 
-	err = request_irq(IRQ_IXP4XX_QM2, handler2, 0, "IXP4xx Queue Manager",
-			  NULL);
+	err = devm_request_irq(dev, irq2, handler2, 0, "IXP4xx Queue Manager",
+			       NULL);
 	if (err) {
-		printk(KERN_ERR "qmgr: failed to request IRQ%i (%i)\n",
-		       IRQ_IXP4XX_QM2, err);
-		goto error_irq2;
+		dev_err(dev, "failed to request IRQ%i (%i)\n",
+			irq2, err);
+		return err;
 	}
 
 	used_sram_bitmap[0] = 0xF; /* 4 first pages reserved for config */
 	spin_lock_init(&qmgr_lock);
 
-	printk(KERN_INFO "IXP4xx Queue Manager initialized.\n");
+	dev_info(dev, "IXP4xx Queue Manager initialized.\n");
 	return 0;
-
-error_irq2:
-	free_irq(IRQ_IXP4XX_QM1, NULL);
-error_irq:
-	release_mem_region(IXP4XX_QMGR_BASE_PHYS, IXP4XX_QMGR_REGION_SIZE);
-	return err;
 }
 
 static int ixp4xx_qmgr_remove(struct platform_device *pdev)
 {
-	free_irq(IRQ_IXP4XX_QM1, NULL);
-	free_irq(IRQ_IXP4XX_QM2, NULL);
-	synchronize_irq(IRQ_IXP4XX_QM1);
-	synchronize_irq(IRQ_IXP4XX_QM2);
-	release_mem_region(IXP4XX_QMGR_BASE_PHYS, IXP4XX_QMGR_REGION_SIZE);
-
+	synchronize_irq(qmgr_irq_1);
+	synchronize_irq(qmgr_irq_2);
 	return 0;
 }
 
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2019-02-21 15:49 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-21 15:44 [PATCH 00/30 v2] ARM: ixp4xx: Modernize and DT support Linus Walleij
2019-02-21 15:44 ` [PATCH 01/30 v2] ARM: ixp4xx: Convert to MULTI_IRQ_HANDLER Linus Walleij
2019-02-21 15:44 ` [PATCH 02/30 v2] ARM: ixp4xx: Pass IRQ resource to beeper Linus Walleij
2019-02-21 15:44 ` [PATCH 03/30 v2] ARM: ixp4xx: Convert to SPARSE_IRQ Linus Walleij
2019-02-21 15:44 ` [PATCH 04/30 v2] irqchip: Add driver for IXP4xx Linus Walleij
2019-02-22  9:51   ` Marc Zyngier
2019-02-21 15:44 ` [PATCH 05/30 v2] gpio: ixp4xx: Add driver for the IXP4xx GPIO Linus Walleij
2019-02-21 15:44 ` [PATCH 06/30 v2] ARM: ixp4xx: Switch to use new IRQ+GPIO drivers Linus Walleij
2019-02-22  9:51   ` Marc Zyngier
2019-02-21 15:44 ` [PATCH 07/30 v2] clocksource/drivers/ixp4xx: Add driver Linus Walleij
2019-02-21 20:54   ` Daniel Lezcano
2019-03-03  9:35     ` Linus Walleij
2019-02-21 15:44 ` [PATCH 08/30 v2] ARM: ixp4xx: Switch to use new timer driver Linus Walleij
2019-02-22  8:38   ` Daniel Lezcano
2019-02-21 15:44 ` [PATCH 09/30 v2] irqchip: ixp4xx: Add DT bindings Linus Walleij
2019-02-21 15:44   ` Linus Walleij
2019-02-21 21:39   ` Rob Herring
2019-02-21 21:39     ` Rob Herring
2019-02-21 15:44 ` [PATCH 10/30 v2] irqchip: ixp4xx: Add OF initialization support Linus Walleij
2019-02-22  9:53   ` Marc Zyngier
2019-02-21 15:44 ` [PATCH 11/30 v2] clocksource/drivers/ixp4xx: Add DT bindings Linus Walleij
2019-02-21 15:44   ` Linus Walleij
2019-02-21 21:40   ` Rob Herring
2019-02-21 21:40     ` Rob Herring
2019-02-21 15:44 ` [PATCH 12/30 v2] clocksource/drivers/ixp4xx: Add OF initialization support Linus Walleij
2019-02-21 15:44 ` [PATCH 13/30 v2] gpio: ixp4xx: Add DT bindings Linus Walleij
2019-02-21 15:44   ` Linus Walleij
2019-02-21 15:44 ` [PATCH 14/30 v2] gpio: ixp4xx: Add OF probing support Linus Walleij
2019-02-21 15:44 ` [PATCH 15/30 v2] ARM: ixp4xx: Add DT bindings Linus Walleij
2019-02-21 15:44   ` Linus Walleij
2019-02-21 15:44 ` [PATCH 16/30 v2] ARM: ixp4xx: Add device tree boot support Linus Walleij
2019-02-21 15:44 ` [PATCH 17/30 v2] ARM: dts: Add some initial IXP4xx device trees Linus Walleij
2019-02-21 15:44 ` [PATCH 18/30 v2] ARM: ixp4xx: Move NPE and QMGR to drivers/soc Linus Walleij
2019-02-21 15:44 ` [PATCH 19/30 v2] ARM: ixp4xx: Move IXP4xx QMGR and NPE headers Linus Walleij
2019-02-21 15:44 ` [PATCH 20/30 v2] ARM: ixp4xx: Turn the NPE into a platform device Linus Walleij
2019-02-21 15:44 ` [PATCH 21/30 v2] ARM: ixp4xx: Turn the QMGR " Linus Walleij
2019-02-21 15:44 ` [PATCH 22/30 v2] soc: ixp4xx: npe: Pass addresses as resources Linus Walleij
2019-02-21 15:44 ` [PATCH 23/30 v2] soc: ixp4xx: Uninline several functions Linus Walleij
2019-02-21 15:44 ` [PATCH 24/30 v2] soc: ixp4xx: Remove unused functions Linus Walleij
2019-02-21 15:44 ` Linus Walleij [this message]
2019-02-21 15:44 ` [PATCH 26/30 v2] soc: ixp4xx: Add DT bindings for IXP4xx NPE Linus Walleij
2019-02-21 15:44   ` Linus Walleij
2019-02-21 21:48   ` Rob Herring
2019-02-21 21:48     ` Rob Herring
2019-02-22 10:37     ` Linus Walleij
2019-02-22 10:37       ` Linus Walleij
2019-02-21 15:44 ` [PATCH 27/30 v2] soc: ixp4xx: npe: Add DT probe code Linus Walleij
2019-02-21 15:44 ` [PATCH 28/30 v2] soc: ixp4xx: qmgr: Add DT bindings for IXP4xx qmgr Linus Walleij
2019-02-21 15:44   ` Linus Walleij
2019-02-21 22:00   ` Rob Herring
2019-02-21 22:00     ` Rob Herring
2019-02-21 15:44 ` [PATCH 29/30 v2] soc: ixp4xx: qmgr: Add DT probe code Linus Walleij
2019-02-21 15:44 ` [PATCH 30/30 v2] ARM: dts: Add queue manager and NPE to the IXP4xx DTSI Linus Walleij
2019-03-18  7:16 ` [PATCH 00/30 v2] ARM: ixp4xx: Modernize and DT support Krzysztof Hałasa
2019-03-18 22:16   ` Linus Walleij
2019-04-02 12:12     ` Krzysztof Hałasa

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=20190221154458.23763-26-linus.walleij@linaro.org \
    --to=linus.walleij@linaro.org \
    --cc=kaloz@openwrt.org \
    --cc=khalasa@piap.pl \
    --cc=linux-arm-kernel@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.