From: Jacopo Mondi <jacopo+renesas@jmondi.org>
To: laurent.pinchart@ideasonboard.com,
kieran.bingham+renesas@ideasonboard.com, airlied@linux.ie,
daniel@ffwll.ch
Cc: Jacopo Mondi <jacopo+renesas@jmondi.org>,
koji.matsuoka.xm@renesas.com, muroya@ksk.co.jp,
VenkataRajesh.Kalakodima@in.bosch.com,
Harsha.ManjulaMallikarjun@in.bosch.com,
linux-renesas-soc@vger.kernel.org,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: [PATCH 14/20] drm: rcar-du: Add support for CMM
Date: Thu, 6 Jun 2019 16:22:14 +0200 [thread overview]
Message-ID: <20190606142220.1392-15-jacopo+renesas@jmondi.org> (raw)
In-Reply-To: <20190606142220.1392-1-jacopo+renesas@jmondi.org>
Add a driver for the R-Car Display Unit Color Correction Module.
Each DU output channel is provided with a CMM unit to perform image
enhancement and color correction.
Add support for CMM through a driver that supports configuration of
the 1-dimensional LUT table. More advanced CMM feature could be
implemented on top of this basic one.
Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
---
drivers/gpu/drm/rcar-du/Kconfig | 7 +
drivers/gpu/drm/rcar-du/Makefile | 1 +
drivers/gpu/drm/rcar-du/rcar_cmm.c | 197 +++++++++++++++++++++++++++++
drivers/gpu/drm/rcar-du/rcar_cmm.h | 38 ++++++
4 files changed, 243 insertions(+)
create mode 100644 drivers/gpu/drm/rcar-du/rcar_cmm.c
create mode 100644 drivers/gpu/drm/rcar-du/rcar_cmm.h
diff --git a/drivers/gpu/drm/rcar-du/Kconfig b/drivers/gpu/drm/rcar-du/Kconfig
index 1529849e217e..539d232790d1 100644
--- a/drivers/gpu/drm/rcar-du/Kconfig
+++ b/drivers/gpu/drm/rcar-du/Kconfig
@@ -13,6 +13,13 @@ config DRM_RCAR_DU
Choose this option if you have an R-Car chipset.
If M is selected the module will be called rcar-du-drm.
+config DRM_RCAR_CMM
+ bool "R-Car DU Color Management Module (CMM) Support"
+ depends on DRM && OF
+ depends on DRM_RCAR_DU
+ help
+ Enable support for R-Car Color Management Module (CMM).
+
config DRM_RCAR_DW_HDMI
tristate "R-Car DU Gen3 HDMI Encoder Support"
depends on DRM && OF
diff --git a/drivers/gpu/drm/rcar-du/Makefile b/drivers/gpu/drm/rcar-du/Makefile
index 6c2ed9c46467..4d1187ccc3e5 100644
--- a/drivers/gpu/drm/rcar-du/Makefile
+++ b/drivers/gpu/drm/rcar-du/Makefile
@@ -15,6 +15,7 @@ rcar-du-drm-$(CONFIG_DRM_RCAR_LVDS) += rcar_du_of.o \
rcar-du-drm-$(CONFIG_DRM_RCAR_VSP) += rcar_du_vsp.o
rcar-du-drm-$(CONFIG_DRM_RCAR_WRITEBACK) += rcar_du_writeback.o
+obj-$(CONFIG_DRM_RCAR_CMM) += rcar_cmm.o
obj-$(CONFIG_DRM_RCAR_DU) += rcar-du-drm.o
obj-$(CONFIG_DRM_RCAR_DW_HDMI) += rcar_dw_hdmi.o
obj-$(CONFIG_DRM_RCAR_LVDS) += rcar_lvds.o
diff --git a/drivers/gpu/drm/rcar-du/rcar_cmm.c b/drivers/gpu/drm/rcar-du/rcar_cmm.c
new file mode 100644
index 000000000000..5d9d917b91f4
--- /dev/null
+++ b/drivers/gpu/drm/rcar-du/rcar_cmm.c
@@ -0,0 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * rcar_cmm.c -- R-Car Display Unit Color Management Module
+ *
+ * Copyright (C) 2019 Jacopo Mondi <jacopo+renesas@jmondi.org>
+ */
+
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+
+#include <drm/drm_atomic.h>
+
+#include "rcar_cmm.h"
+
+#define CM2_LUT_CTRL 0x00
+#define CM2_LUT_CTRL_EN BIT(0)
+#define CM2_LUT_TBLA 0x600
+
+struct rcar_cmm {
+ struct clk *clk;
+ void __iomem *base;
+ bool enabled;
+
+ /* LUT table scratch buffer. */
+ struct {
+ bool restore;
+ unsigned int size;
+ uint32_t table[CMM_GAMMA_LUT_SIZE];
+ } lut;
+};
+
+static inline int rcar_cmm_read(struct rcar_cmm *rcmm, u32 reg)
+{
+ return ioread32(rcmm->base + reg);
+}
+
+static inline void rcar_cmm_write(struct rcar_cmm *rcmm, u32 reg, u32 data)
+{
+ iowrite32(data, rcmm->base + reg);
+}
+
+int rcar_cmm_setup(struct platform_device *pdev, struct rcar_cmm_config *config)
+{
+ struct rcar_cmm *rcmm = platform_get_drvdata(pdev);
+ unsigned int i;
+
+ if (config->lut.size > CMM_GAMMA_LUT_SIZE)
+ return -EINVAL;
+
+ /*
+ * As cmm_setup is called by atomic commit tail helper, it might be
+ * called before the enabling the CRTC (which calls cmm_enable()).
+ *
+ * Store the LUT table entries in the scratch buffer to be later
+ * programmed at enable time.
+ */
+ if (!rcmm->enabled) {
+ if (!config->lut.enable)
+ return 0;
+
+ for (i = 0; i < config->lut.size; ++i) {
+ struct drm_color_lut *lut = &config->lut.table[i];
+
+ rcmm->lut.table[i] = (lut->red & 0xff) << 16 |
+ (lut->green & 0xff) << 8 |
+ (lut->blue & 0xff);
+ }
+
+ rcmm->lut.restore = true;
+ rcmm->lut.size = config->lut.size;
+
+ return 0;
+ }
+
+ if (rcar_cmm_read(rcmm, CM2_LUT_CTRL) & CM2_LUT_CTRL_EN &&
+ !config->lut.enable) {
+ rcar_cmm_write(rcmm, CM2_LUT_CTRL, 0);
+ return 0;
+ }
+
+ /* Enable LUT and program the new gamma table values. */
+ rcar_cmm_write(rcmm, CM2_LUT_CTRL, CM2_LUT_CTRL_EN);
+ for (i = 0; i < config->lut.size; ++i) {
+ struct drm_color_lut *lut = &config->lut.table[i];
+ u32 val = (lut->red & 0xff) << 16 | (lut->green & 0xff) << 8 |
+ (lut->blue & 0xff);
+
+ rcar_cmm_write(rcmm, CM2_LUT_TBLA + i * 4, val);
+ }
+
+ return 0;
+}
+
+int rcar_cmm_enable(struct platform_device *pdev)
+{
+ struct rcar_cmm *rcmm = platform_get_drvdata(pdev);
+ unsigned int i;
+ int ret;
+
+ if (rcmm->enabled)
+ return 0;
+
+ ret = clk_prepare_enable(rcmm->clk);
+ if (ret)
+ return ret;
+
+ /* Apply the LUT table values saved at cmm_setup time. */
+ if (rcmm->lut.restore) {
+ rcar_cmm_write(rcmm, CM2_LUT_CTRL, CM2_LUT_CTRL_EN);
+ for (i = 0; i < rcmm->lut.size; ++i)
+ rcar_cmm_write(rcmm, CM2_LUT_TBLA + i * 4,
+ rcmm->lut.table[i]);
+
+ rcmm->lut.restore = false;
+ rcmm->lut.size = 0;
+ }
+
+ rcmm->enabled = true;
+
+ return 0;
+}
+
+void rcar_cmm_disable(struct platform_device *pdev)
+{
+ struct rcar_cmm *rcmm = platform_get_drvdata(pdev);
+
+ rcar_cmm_write(rcmm, CM2_LUT_CTRL, 0);
+
+ clk_disable_unprepare(rcmm->clk);
+
+ rcmm->lut.restore = false;
+ rcmm->lut.size = 0;
+ rcmm->enabled = false;
+}
+
+static int rcar_cmm_probe(struct platform_device *pdev)
+{
+ struct rcar_cmm *rcmm;
+ struct resource *res;
+ resource_size_t size;
+
+ rcmm = devm_kzalloc(&pdev->dev, sizeof(*rcmm), GFP_KERNEL);
+ if (!rcmm)
+ return -ENOMEM;
+
+ platform_set_drvdata(pdev, rcmm);
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ size = resource_size(res);
+ if (!devm_request_mem_region(&pdev->dev, res->start, size,
+ dev_name(&pdev->dev))) {
+ dev_err(&pdev->dev,
+ "can't request region for resource %pR\n", res);
+ return -EBUSY;
+ }
+
+ rcmm->base = devm_ioremap_nocache(&pdev->dev, res->start, size);
+ if (IS_ERR(rcmm->base))
+ return PTR_ERR(rcmm->base);
+
+ rcmm->clk = devm_clk_get(&pdev->dev, NULL);
+ if (IS_ERR(rcmm->clk)) {
+ dev_err(&pdev->dev, "Failed to get CMM clock");
+ return PTR_ERR(rcmm->clk);
+ }
+
+ rcmm->lut.restore = false;
+ rcmm->lut.size = 0;
+ rcmm->enabled = false;
+
+ return 0;
+}
+
+static const struct of_device_id rcar_cmm_of_table[] = {
+ { .compatible = "renesas,cmm-gen3" },
+ { .compatible = "renesas,cmm-gen2" },
+ { },
+};
+
+MODULE_DEVICE_TABLE(of, rcar_cmm_of_table);
+
+static struct platform_driver rcar_cmm_platform_driver = {
+ .probe = rcar_cmm_probe,
+ .driver = {
+ .name = "rcar-cmm",
+ .of_match_table = rcar_cmm_of_table,
+ },
+};
+
+module_platform_driver(rcar_cmm_platform_driver);
+
+MODULE_AUTHOR("Jacopo Mondi <jacopo+renesas@jmondi.org");
+MODULE_DESCRIPTION("Renesas R-Car CMM Driver");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/gpu/drm/rcar-du/rcar_cmm.h b/drivers/gpu/drm/rcar-du/rcar_cmm.h
new file mode 100644
index 000000000000..da61a145dc5c
--- /dev/null
+++ b/drivers/gpu/drm/rcar-du/rcar_cmm.h
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * rcar_cmm.h -- R-Car Display Unit Color Management Module
+ *
+ * Copyright (C) 2019 Jacopo Mondi <jacopo+renesas@jmondi.org>
+ */
+
+#ifndef __RCAR_CMM_H__
+#define __RCAR_CMM_H__
+
+#include <linux/platform_device.h>
+
+#define CMM_GAMMA_LUT_SIZE 256
+
+struct drm_color_lut;
+
+/**
+ * struct rcar_cmm_config - CMM configuration
+ *
+ * @lut: 1D-LUT configuration
+ * @lut.enable: 1D-LUT enable flag
+ * @lut.table: 1D-LUT table entries.
+ * @lut.size 1D-LUT number of entries. Max is 256
+ */
+struct rcar_cmm_config {
+ struct {
+ bool enable;
+ struct drm_color_lut *table;
+ unsigned int size;
+ } lut;
+};
+
+int rcar_cmm_enable(struct platform_device *);
+void rcar_cmm_disable(struct platform_device *);
+
+int rcar_cmm_setup(struct platform_device *, struct rcar_cmm_config *);
+
+#endif /* __RCAR_CMM_H__ */
--
2.21.0
next prev parent reply other threads:[~2019-06-06 14:22 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-06 14:22 [PATCH 00/20] drm: rcar-du: Add Color Management Module (CMM) Jacopo Mondi
2019-06-06 14:22 ` [PATCH 01/20] dt-bindings: display: renesas,cmm: Add R-Car CMM documentation Jacopo Mondi
2019-06-06 16:52 ` Laurent Pinchart
2019-06-06 18:06 ` Geert Uytterhoeven
2019-06-06 20:19 ` Sergei Shtylyov
2019-06-06 14:22 ` [PATCH 02/20] dt-bindings: display, renesas,du: Document cmms property Jacopo Mondi
2019-06-06 16:52 ` Laurent Pinchart
2019-06-06 14:22 ` [PATCH 03/20] dt-bindings: display, renesas,du: Update 'vsps' in example Jacopo Mondi
2019-06-06 16:53 ` Laurent Pinchart
2019-06-06 20:00 ` Geert Uytterhoeven
2019-06-07 11:36 ` Laurent Pinchart
2019-06-06 14:22 ` [PATCH 04/20] clk: renesas: r8a7796: Add CMM clocks Jacopo Mondi
2019-06-06 14:22 ` [PATCH 05/20] clk: renesas: r8a7795: " Jacopo Mondi
2019-06-06 16:58 ` Laurent Pinchart
2019-06-06 18:18 ` Jacopo Mondi
2019-06-12 7:41 ` Geert Uytterhoeven
2019-06-06 14:22 ` [PATCH 06/20] clk: renesas: r8a77965: " Jacopo Mondi
2019-06-06 16:59 ` Laurent Pinchart
2019-06-12 7:43 ` Geert Uytterhoeven
2019-06-06 14:22 ` [PATCH 07/20] clk: renesas: r8a77990: " Jacopo Mondi
2019-06-06 17:00 ` Laurent Pinchart
2019-06-12 7:43 ` Geert Uytterhoeven
2019-06-06 14:22 ` [PATCH 08/20] clk: renesas: r8a77995: " Jacopo Mondi
2019-06-06 17:00 ` Laurent Pinchart
2019-06-12 7:44 ` Geert Uytterhoeven
2019-06-06 14:22 ` [PATCH 09/20] arm64: dts: renesas: r8a7796: Add CMM units Jacopo Mondi
2019-06-06 17:04 ` Laurent Pinchart
2019-06-06 14:22 ` [PATCH 10/20] arm64: dts: renesas: r8a7795: " Jacopo Mondi
2019-06-06 17:06 ` Laurent Pinchart
2019-06-06 14:22 ` [PATCH 11/20] arm64: dts: renesas: r8a77965: " Jacopo Mondi
2019-06-06 17:06 ` Laurent Pinchart
2019-06-06 14:22 ` [PATCH 12/20] arm64: dts: renesas: r8a77990: " Jacopo Mondi
2019-06-06 17:07 ` Laurent Pinchart
2019-06-06 14:22 ` [PATCH 13/20] arm64: dts: renesas: r8a77995: " Jacopo Mondi
2019-06-06 17:08 ` Laurent Pinchart
2019-06-06 14:22 ` Jacopo Mondi [this message]
2019-06-07 11:35 ` [PATCH 14/20] drm: rcar-du: Add support for CMM Laurent Pinchart
2019-06-07 11:44 ` Laurent Pinchart
2019-06-07 12:18 ` Laurent Pinchart
2019-06-14 8:54 ` Jacopo Mondi
2019-06-06 14:22 ` [PATCH 15/20] drm: rcar-du: Claim CMM support for Gen3 SoCs Jacopo Mondi
2019-06-07 11:38 ` Laurent Pinchart
2019-06-06 14:22 ` [PATCH 16/20] drm: rcar-du: kms: Collect CMM instances Jacopo Mondi
2019-06-07 11:49 ` Laurent Pinchart
2019-06-06 14:22 ` [PATCH 17/20] drm: rcar-du: crtc: Enable and disable CMMs Jacopo Mondi
2019-06-07 11:51 ` Laurent Pinchart
2019-06-06 14:22 ` [PATCH 18/20] drm: rcar-du: group: Enable DU's CMM extension Jacopo Mondi
2019-06-07 11:55 ` Laurent Pinchart
2019-06-06 14:22 ` [PATCH 19/20] drm: rcar-du: crtc: Register GAMMA_LUT properties Jacopo Mondi
2019-06-07 12:03 ` Laurent Pinchart
2019-06-14 8:15 ` Jacopo Mondi
2019-06-14 8:42 ` Daniel Vetter
2019-06-14 9:27 ` Jacopo Mondi
2019-06-14 14:47 ` Daniel Vetter
2019-06-06 14:22 ` [PATCH 20/20] drm: rcar-du: kms: Update CMM in atomic commit tail Jacopo Mondi
2019-06-07 12:06 ` Laurent Pinchart
2019-06-14 8:19 ` Jacopo Mondi
2019-09-12 23:39 ` Laurent Pinchart
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=20190606142220.1392-15-jacopo+renesas@jmondi.org \
--to=jacopo+renesas@jmondi.org \
--cc=Harsha.ManjulaMallikarjun@in.bosch.com \
--cc=VenkataRajesh.Kalakodima@in.bosch.com \
--cc=airlied@linux.ie \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=kieran.bingham+renesas@ideasonboard.com \
--cc=koji.matsuoka.xm@renesas.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=muroya@ksk.co.jp \
/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).