From: Liu Ying <victor.liu@nxp.com>
To: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org
Cc: p.zabel@pengutronix.de, airlied@gmail.com, daniel@ffwll.ch,
maarten.lankhorst@linux.intel.com, mripard@kernel.org,
tzimmermann@suse.de, robh@kernel.org, krzk+dt@kernel.org,
conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de,
kernel@pengutronix.de, festevam@gmail.com, tglx@linutronix.de,
vkoul@kernel.org, kishon@kernel.org, aisheng.dong@nxp.com,
agx@sigxcpu.org, francesco@dolcini.it, frank.li@nxp.com
Subject: [PATCH v2 08/16] drm/imx: Add i.MX8qxp Display Controller interrupt controller
Date: Fri, 12 Jul 2024 17:32:35 +0800 [thread overview]
Message-ID: <20240712093243.2108456-9-victor.liu@nxp.com> (raw)
In-Reply-To: <20240712093243.2108456-1-victor.liu@nxp.com>
i.MX8qxp Display Controller has a built-in interrupt controller to support
Enable/Status/Preset/Clear interrupt bit. Add driver for it.
Signed-off-by: Liu Ying <victor.liu@nxp.com>
---
v2:
* No change.
drivers/gpu/drm/imx/dc/Kconfig | 1 +
drivers/gpu/drm/imx/dc/Makefile | 2 +-
drivers/gpu/drm/imx/dc/dc-drv.c | 1 +
drivers/gpu/drm/imx/dc/dc-drv.h | 1 +
drivers/gpu/drm/imx/dc/dc-ic.c | 249 ++++++++++++++++++++++++++++++++
5 files changed, 253 insertions(+), 1 deletion(-)
create mode 100644 drivers/gpu/drm/imx/dc/dc-ic.c
diff --git a/drivers/gpu/drm/imx/dc/Kconfig b/drivers/gpu/drm/imx/dc/Kconfig
index 32d7471c49d0..b66b815fbdf1 100644
--- a/drivers/gpu/drm/imx/dc/Kconfig
+++ b/drivers/gpu/drm/imx/dc/Kconfig
@@ -1,5 +1,6 @@
config DRM_IMX8_DC
tristate "Freescale i.MX8 Display Controller Graphics"
depends on DRM && COMMON_CLK && OF && (ARCH_MXC || COMPILE_TEST)
+ select GENERIC_IRQ_CHIP
help
enable Freescale i.MX8 Display Controller(DC) graphics support
diff --git a/drivers/gpu/drm/imx/dc/Makefile b/drivers/gpu/drm/imx/dc/Makefile
index 2942ae6fd5bd..1ce3e8a8db22 100644
--- a/drivers/gpu/drm/imx/dc/Makefile
+++ b/drivers/gpu/drm/imx/dc/Makefile
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
imx8-dc-drm-objs := dc-cf.o dc-de.o dc-drv.o dc-ed.o dc-fg.o dc-fl.o dc-fu.o \
- dc-fw.o dc-lb.o dc-pe.o dc-tc.o
+ dc-fw.o dc-ic.o dc-lb.o dc-pe.o dc-tc.o
obj-$(CONFIG_DRM_IMX8_DC) += imx8-dc-drm.o
diff --git a/drivers/gpu/drm/imx/dc/dc-drv.c b/drivers/gpu/drm/imx/dc/dc-drv.c
index 7c64acc863ad..fd68861f770a 100644
--- a/drivers/gpu/drm/imx/dc/dc-drv.c
+++ b/drivers/gpu/drm/imx/dc/dc-drv.c
@@ -15,6 +15,7 @@ static struct platform_driver * const dc_drivers[] = {
&dc_fg_driver,
&dc_fl_driver,
&dc_fw_driver,
+ &dc_ic_driver,
&dc_lb_driver,
&dc_pe_driver,
&dc_tc_driver,
diff --git a/drivers/gpu/drm/imx/dc/dc-drv.h b/drivers/gpu/drm/imx/dc/dc-drv.h
index c687a36b8153..3b11f4862c6c 100644
--- a/drivers/gpu/drm/imx/dc/dc-drv.h
+++ b/drivers/gpu/drm/imx/dc/dc-drv.h
@@ -25,6 +25,7 @@ extern struct platform_driver dc_de_driver;
extern struct platform_driver dc_fg_driver;
extern struct platform_driver dc_fl_driver;
extern struct platform_driver dc_fw_driver;
+extern struct platform_driver dc_ic_driver;
extern struct platform_driver dc_lb_driver;
extern struct platform_driver dc_pe_driver;
extern struct platform_driver dc_tc_driver;
diff --git a/drivers/gpu/drm/imx/dc/dc-ic.c b/drivers/gpu/drm/imx/dc/dc-ic.c
new file mode 100644
index 000000000000..8540a0414b39
--- /dev/null
+++ b/drivers/gpu/drm/imx/dc/dc-ic.c
@@ -0,0 +1,249 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2024 NXP
+ */
+
+#include <linux/clk.h>
+#include <linux/component.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/irqchip/chained_irq.h>
+#include <linux/irqdomain.h>
+#include <linux/of.h>
+#include <linux/of_irq.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+
+#include <drm/drm_managed.h>
+
+#include "dc-drv.h"
+
+#define USERINTERRUPTMASK(n) (0x8 + 4 * (n))
+#define INTERRUPTENABLE(n) (0x10 + 4 * (n))
+#define INTERRUPTCLEAR(n) (0x20 + 4 * (n))
+#define INTERRUPTSTATUS(n) (0x28 + 4 * (n))
+#define USERINTERRUPTENABLE(n) (0x40 + 4 * (n))
+#define USERINTERRUPTCLEAR(n) (0x50 + 4 * (n))
+#define USERINTERRUPTSTATUS(n) (0x58 + 4 * (n))
+
+#define IRQ_COUNT 49
+#define IRQ_RESERVED 35
+#define REG_NUM 2
+
+struct dc_ic_data {
+ void __iomem *regs;
+ struct clk *clk_axi;
+ int irq[IRQ_COUNT];
+ struct irq_domain *domain;
+};
+
+struct dc_ic_entry {
+ struct dc_ic_data *data;
+ int irq;
+};
+
+static void dc_ic_irq_handler(struct irq_desc *desc)
+{
+ struct dc_ic_entry *entry = irq_desc_get_handler_data(desc);
+ struct dc_ic_data *data = entry->data;
+ unsigned int virq;
+ u32 status;
+
+ chained_irq_enter(irq_desc_get_chip(desc), desc);
+
+ status = readl(data->regs + USERINTERRUPTSTATUS(entry->irq / 32));
+ status &= readl(data->regs + USERINTERRUPTENABLE(entry->irq / 32));
+
+ if (status & BIT(entry->irq % 32)) {
+ virq = irq_linear_revmap(data->domain, entry->irq);
+ if (virq)
+ generic_handle_irq(virq);
+ }
+
+ chained_irq_exit(irq_desc_get_chip(desc), desc);
+}
+
+static const unsigned long unused_irq[REG_NUM] = {0x00000000, 0xfffe0008};
+
+static int
+dc_ic_bind(struct device *dev, struct device *master, void *master_data)
+{
+ struct platform_device *pdev = to_platform_device(dev);
+ struct dc_drm_device *dc_drm = master_data;
+ struct dc_ic_entry *entry;
+ struct irq_chip_generic *gc;
+ struct dc_ic_data *data;
+ struct irq_chip_type *ct;
+ int i, ret;
+
+ data = drmm_kzalloc(&dc_drm->base, sizeof(*data), GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
+
+ entry = drmm_kcalloc(&dc_drm->base, IRQ_COUNT, sizeof(*entry),
+ GFP_KERNEL);
+ if (!entry)
+ return -ENOMEM;
+
+ data->regs = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(data->regs)) {
+ dev_err(dev, "failed to initialize reg\n");
+ return PTR_ERR(data->regs);
+ }
+
+ data->clk_axi = devm_clk_get(dev, NULL);
+ if (IS_ERR(data->clk_axi))
+ return dev_err_probe(dev, PTR_ERR(data->clk_axi),
+ "failed to get AXI clock\n");
+
+ dev_set_drvdata(dev, data);
+
+ ret = devm_pm_runtime_enable(dev);
+ if (ret)
+ return ret;
+
+ ret = pm_runtime_resume_and_get(dev);
+ if (ret < 0) {
+ dev_err(dev, "failed to get runtime PM sync: %d\n", ret);
+ return ret;
+ }
+
+ for (i = 0; i < REG_NUM; i++) {
+ /* mask and clear all interrupts */
+ writel(0x0, data->regs + USERINTERRUPTENABLE(i));
+ writel(0x0, data->regs + INTERRUPTENABLE(i));
+ writel(0xffffffff, data->regs + USERINTERRUPTCLEAR(i));
+ writel(0xffffffff, data->regs + INTERRUPTCLEAR(i));
+
+ /* set all interrupts to user mode */
+ writel(0xffffffff, data->regs + USERINTERRUPTMASK(i));
+ }
+
+ data->domain = irq_domain_add_linear(dev->of_node, IRQ_COUNT,
+ &irq_generic_chip_ops, data);
+ if (!data->domain) {
+ dev_err(dev, "failed to create IRQ domain\n");
+ pm_runtime_put(dev);
+ return -ENOMEM;
+ }
+ irq_domain_set_pm_device(data->domain, &pdev->dev);
+
+ ret = irq_alloc_domain_generic_chips(data->domain, 32, 1, "DC",
+ handle_level_irq, 0, 0, 0);
+ if (ret) {
+ dev_err(dev, "failed to alloc generic IRQ chips: %d\n", ret);
+ irq_domain_remove(data->domain);
+ pm_runtime_put(dev);
+ return ret;
+ }
+
+ for (i = 0; i < IRQ_COUNT; i += 32) {
+ gc = irq_get_domain_generic_chip(data->domain, i);
+ gc->reg_base = data->regs;
+ gc->unused = unused_irq[i / 32];
+ ct = gc->chip_types;
+ ct->chip.irq_ack = irq_gc_ack_set_bit;
+ ct->chip.irq_mask = irq_gc_mask_clr_bit;
+ ct->chip.irq_unmask = irq_gc_mask_set_bit;
+ ct->regs.ack = USERINTERRUPTCLEAR(i / 32);
+ ct->regs.mask = USERINTERRUPTENABLE(i / 32);
+ }
+
+ for (i = 0; i < IRQ_COUNT; i++) {
+ /* skip the reserved IRQ */
+ if (i == IRQ_RESERVED)
+ continue;
+
+ data->irq[i] = irq_of_parse_and_map(dev->of_node, i);
+
+ entry[i].data = data;
+ entry[i].irq = i;
+
+ irq_set_chained_handler_and_data(data->irq[i],
+ dc_ic_irq_handler, &entry[i]);
+ }
+
+ return 0;
+}
+
+static void
+dc_ic_unbind(struct device *dev, struct device *master, void *master_data)
+{
+ struct dc_ic_data *data = dev_get_drvdata(dev);
+ int i;
+
+ for (i = 0; i < IRQ_COUNT; i++) {
+ if (i == IRQ_RESERVED)
+ continue;
+
+ irq_set_chained_handler_and_data(data->irq[i], NULL, NULL);
+ }
+
+ irq_domain_remove(data->domain);
+
+ pm_runtime_put_sync(dev);
+}
+
+static const struct component_ops dc_ic_ops = {
+ .bind = dc_ic_bind,
+ .unbind = dc_ic_unbind,
+};
+
+static int dc_ic_probe(struct platform_device *pdev)
+{
+ int ret;
+
+ ret = component_add(&pdev->dev, &dc_ic_ops);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret,
+ "failed to add component\n");
+
+ return 0;
+}
+
+static void dc_ic_remove(struct platform_device *pdev)
+{
+ component_del(&pdev->dev, &dc_ic_ops);
+}
+
+static int dc_ic_runtime_suspend(struct device *dev)
+{
+ struct dc_ic_data *data = dev_get_drvdata(dev);
+
+ clk_disable_unprepare(data->clk_axi);
+
+ return 0;
+}
+
+static int dc_ic_runtime_resume(struct device *dev)
+{
+ struct dc_ic_data *data = dev_get_drvdata(dev);
+ int ret;
+
+ ret = clk_prepare_enable(data->clk_axi);
+ if (ret)
+ dev_err(dev, "failed to enable AXI clock: %d\n", ret);
+
+ return ret;
+}
+
+static const struct dev_pm_ops dc_ic_pm_ops = {
+ SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
+ pm_runtime_force_resume)
+ RUNTIME_PM_OPS(dc_ic_runtime_suspend, dc_ic_runtime_resume, NULL)
+};
+
+static const struct of_device_id dc_ic_dt_ids[] = {
+ { .compatible = "fsl,imx8qxp-dc-intc", },
+ { /* sentinel */ }
+};
+
+struct platform_driver dc_ic_driver = {
+ .probe = dc_ic_probe,
+ .remove_new = dc_ic_remove,
+ .driver = {
+ .name = "imx8-dc-intc",
+ .of_match_table = dc_ic_dt_ids,
+ .pm = pm_sleep_ptr(&dc_ic_pm_ops),
+ },
+};
--
2.34.1
next prev parent reply other threads:[~2024-07-12 9:25 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-12 9:32 [PATCH v2 00/16] Add Freescale i.MX8qxp Display Controller support Liu Ying
2024-07-12 9:32 ` [PATCH v2 01/16] dt-bindings: display: imx: Add some i.MX8qxp Display Controller processing units Liu Ying
2024-07-22 22:38 ` Rob Herring
2024-07-23 9:49 ` Liu Ying
2024-07-12 9:32 ` [PATCH v2 02/16] dt-bindings: display: imx: Add i.MX8qxp Display Controller display engine Liu Ying
2024-07-22 22:57 ` Rob Herring
2024-07-23 9:51 ` Liu Ying
2024-07-12 9:32 ` [PATCH v2 03/16] dt-bindings: display: imx: Add i.MX8qxp Display Controller pixel engine Liu Ying
2024-07-12 9:32 ` [PATCH v2 04/16] dt-bindings: interrupt-controller: Add i.MX8qxp Display Controller interrupt controller Liu Ying
2024-07-22 23:06 ` Rob Herring (Arm)
2024-07-12 9:32 ` [PATCH v2 05/16] dt-bindings: display: imx: Add i.MX8qxp Display Controller Liu Ying
2024-07-12 9:32 ` [PATCH v2 06/16] drm/imx: Add i.MX8qxp Display Controller display engine Liu Ying
2024-07-27 16:11 ` Dmitry Baryshkov
2024-07-30 6:25 ` Liu Ying
2024-07-31 11:54 ` Dmitry Baryshkov
2024-08-05 3:23 ` Liu Ying
2024-07-12 9:32 ` [PATCH v2 07/16] drm/imx: Add i.MX8qxp Display Controller pixel engine Liu Ying
2024-07-27 16:13 ` Dmitry Baryshkov
2024-07-30 6:55 ` Liu Ying
2024-07-30 7:44 ` Krzysztof Kozlowski
2024-07-30 9:42 ` Liu Ying
2024-07-30 10:20 ` Krzysztof Kozlowski
2024-07-31 5:53 ` Liu Ying
2024-07-12 9:32 ` Liu Ying [this message]
2024-07-12 9:32 ` [PATCH v2 09/16] drm/imx: Add i.MX8qxp Display Controller KMS Liu Ying
2024-07-12 9:55 ` Markus Elfring
2024-07-27 16:30 ` Dmitry Baryshkov
2024-07-30 8:31 ` Liu Ying
2024-07-31 13:51 ` Dmitry Baryshkov
2024-08-05 5:01 ` Liu Ying
2024-07-12 9:32 ` [PATCH v2 10/16] MAINTAINERS: Add maintainer for i.MX8qxp Display Controller Liu Ying
2024-07-12 9:32 ` [DO NOT MERGE PATCH v2 11/16] dt-bindings: phy: mixel,mipi-dsi-phy: Allow assigned-clock* properties Liu Ying
2024-07-22 23:09 ` Rob Herring
2024-07-23 10:00 ` Liu Ying
2024-07-12 9:32 ` [DO NOT MERGE PATCH v2 12/16] dt-bindings: firmware: imx: Add SCU controlled display pixel link nodes Liu Ying
2024-07-12 9:32 ` [DO NOT MERGE PATCH v2 13/16] arm64: dts: imx8qxp: Add display controller subsystem Liu Ying
2024-07-12 9:32 ` [DO NOT MERGE PATCH v2 14/16] arm64: dts: imx8qxp: Add MIPI-LVDS combo subsystems Liu Ying
2024-07-12 9:32 ` [DO NOT MERGE PATCH v2 15/16] arm64: dts: imx8qxp-mek: Enable display controller Liu Ying
2024-07-12 9:32 ` [DO NOT MERGE PATCH v2 16/16] arm64: dts: imx8qxp-mek: Add MX8-DLVDS-LCD1 display module support Liu Ying
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=20240712093243.2108456-9-victor.liu@nxp.com \
--to=victor.liu@nxp.com \
--cc=agx@sigxcpu.org \
--cc=airlied@gmail.com \
--cc=aisheng.dong@nxp.com \
--cc=conor+dt@kernel.org \
--cc=daniel@ffwll.ch \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=festevam@gmail.com \
--cc=francesco@dolcini.it \
--cc=frank.li@nxp.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=kishon@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=robh@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=tglx@linutronix.de \
--cc=tzimmermann@suse.de \
--cc=vkoul@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 NNTP newsgroup(s).