Skip to contentSkip to conversation

Add Unisoc's drm kms module

PATCH Superseded Kevin Tang 4 participants 14 messages Oct 25, 2021 – Dec 3, 2021

Subsystems (4)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Kevin Tang

author
#0 lore raw

v7 cover Add Unisoc's drm kms module

ChangeList:
RFC v1:
1. only upstream modeset and atomic at first commit.
2. remove some unused code;
3. use alpha and blend_mode properties;
3. add yaml support;
4. remove auto-adaptive panel driver;
5. bugfix

RFC v2:
1. add sprd crtc and plane module for KMS, preparing for multi crtc&encoder
2. remove gem drivers, use generic CMA handlers
3. remove redundant "module_init", all the sub modules loading by KMS

RFC v3:
1. multi crtc&encoder design have problem, so rollback to v1

RFC v4:
1. update to gcc-linaro-7.5.0
2. update to Linux 5.6-rc3
3. remove pm_runtime support
4. add COMPILE_TEST, remove unused kconfig
5. "drm_dev_put" on drm_unbind
6. fix some naming convention issue
7. remove semaphore lock for crtc flip
8. remove static variables

RFC v5:
1. optimize encoder and connector code implementation
2. use "platform_get_irq" and "platform_get_resource"
3. drop useless function return type, drop unless debug log
4. custom properties should be separate, so drop it
5. use DRM_XXX replase pr_xxx
6. drop dsi&dphy hal callback ops
7. drop unless callback ops checking
8. add comments for sprd dpu structure

RFC v6:
1. Access registers via readl/writel
2. Checking for unsupported KMS properties (format, rotation, blend_mode, etc) on plane_check ops
3. Remove always true checks for dpu core ops

RFC v7:
1. Fix DTC unit name warnings
2. Fix the problem of maintainers
3. Call drmm_mode_config_init to mode config init
4. Embed drm_device in sprd_drm and use devm_drm_dev_alloc
5. Replace DRM_XXX with drm_xxx on KMS module, but not suitable for other subsystems
6. Remove plane_update stuff, dpu handles all the HW update in crtc->atomic_flush
7. Dsi&Dphy Code structure adjustment, all move to "sprd/"

v0:
1. Remove dpu_core_ops stuff layer for sprd drtc driver, but dpu_layer need to keeping. Because all the HW update in crtc->atomic_flush, we need temporary storage all layers for the dpu pageflip of atomic_flush.
2. Add ports subnode with port@X.

v1:
1. Remove dphy and dsi graph binding, merge the dphy driver into the dsi.
2. Add commit messages for Unisoc's virtual nodes.

v2:
1. Use drm_xxx to replace all DRM_XXX.
2. Use kzalloc to replace devm_kzalloc for sprd_dsi/sprd_dpu structure init.
3. Remove dpu_core_ops midlayer.

v3:
1. Remove dpu_layer midlayer and commit layers by aotmic_update

v4:
1. Move the devm_drm_dev_alloc to master_ops->bind function.
2. The managed drmm_mode_config_init() it is no longer necessary for drivers to explicitly call drm_mode_config_cleanup, so delete it.
3. Use drmm_helpers to allocate crtc ,planes and encoder.
4. Move allocate crtc ,planes, encoder to bind funtion.
5. Move rotation enum definitions to crtc layer reg bitfields.

v5:
1. Remove subdir-ccflgas-y for Makefile.
2. Keep the selects sorted by alphabet for Kconfig.
3. Fix the checkpatch warnings.
4. Use mode_set_nofb instead of mode_valid callback.
5. Follow the OF-Graph bindings, use of_graph_get_port_by_id instead of of_parse_phandle.
6. Use zpos to represent the layer position.
7. Rebase to last drm misc branch.
8. Remove panel_in port for dsi node.
9. Drop the dsi ip file prefix.
10. Add Signed-off-by for dsi&dphy patch.
11. Use the mode_flags of mipi_dsi_device to setup crtc DPI and EDPI mode.

v6:
1. Disable and clear interrupts before register dpu IRQ
2. Init dpi config used by crtc_state->adjusted_mode on mode_set_nofb
3. Remove enable_irq and disable_irq function call.
4. Remove drm_format_info function call.
5. Redesign the way to access the dsi register.
6. Reduce the dsi_context member variables.

v7:
1. Fix codeing style issue by checkpatch.
2. Drop the pll registers structure define.
3. Use bridge API instead of drm panel API.
4. Register mipi_dsi_host on probe phase;
5. Remove iommu error interrupt handling function.
6. Remove some unused function.

Kevin Tang (6):
dt-bindings: display: add Unisoc's drm master bindings drm/sprd: add Unisoc's drm kms master
dt-bindings: display: add Unisoc's dpu bindings drm/sprd: add Unisoc's drm display controller driver
dt-bindings: display: add Unisoc's mipi dsi controller bindings drm/sprd: add Unisoc's drm mipi dsi&dphy driver

 .../display/sprd/sprd,display-subsystem.yaml  |   64 +
 .../display/sprd/sprd,sharkl3-dpu.yaml        |   77 ++
 .../display/sprd/sprd,sharkl3-dsi-host.yaml   |   88 ++
 drivers/gpu/drm/Kconfig                       |    2 +
 drivers/gpu/drm/Makefile                      |    1 +
 drivers/gpu/drm/sprd/Kconfig                  |   13 +
 drivers/gpu/drm/sprd/Makefile                 |    6 +
 drivers/gpu/drm/sprd/megacores_pll.c          |  305 +++++
 drivers/gpu/drm/sprd/sprd_dpu.c               |  884 ++++++++++++++
 drivers/gpu/drm/sprd/sprd_dpu.h               |  109 ++
 drivers/gpu/drm/sprd/sprd_drm.c               |  205 ++++
 drivers/gpu/drm/sprd/sprd_drm.h               |   19 +
 drivers/gpu/drm/sprd/sprd_dsi.c               | 1065 +++++++++++++++++
 drivers/gpu/drm/sprd/sprd_dsi.h               |  126 ++
 14 files changed, 2964 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/sprd/sprd,display-subsystem.yaml
 create mode 100644 Documentation/devicetree/bindings/display/sprd/sprd,sharkl3-dpu.yaml
 create mode 100644 Documentation/devicetree/bindings/display/sprd/sprd,sharkl3-dsi-host.yaml
 create mode 100644 drivers/gpu/drm/sprd/Kconfig
 create mode 100644 drivers/gpu/drm/sprd/Makefile
 create mode 100644 drivers/gpu/drm/sprd/megacores_pll.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_dpu.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_dpu.h
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.h
 create mode 100644 drivers/gpu/drm/sprd/sprd_dsi.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_dsi.h
Signature · 1 line
2.29.0
author
#1 lore raw

PATCH v7 1/6 dt-bindings: display: add Unisoc's drm master bindings

From: Kevin Tang <[email protected]>

The Unisoc DRM master device is a virtual device needed to list all DPU devices or other display interface nodes that comprise the graphics subsystem

Unisoc's display pipeline have several components as below description, multi display controllers and corresponding physical interfaces.
For different display scenarios, dpu0 and dpu1 maybe binding to different encoder.

E.g:
dpu0 and dpu1 both binding to DSI for dual mipi-dsi display; dpu0 binding to DSI for primary display, and dpu1 binding to DP for external display;

---
 .../display/sprd/sprd,display-subsystem.yaml  | 64 +++++++++++++++++++
 1 file changed, 64 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/sprd/sprd,display-subsystem.yaml
Documentation/devicetree/bindings/display/sprd/sprd,display-subsystem.yaml new file +64 -0
new file mode 100644
index 000000000..3d107e943
@@ -0,0 +1,64 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/sprd/sprd,display-subsystem.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Unisoc DRM master device
+
+maintainers:
+  - Kevin Tang <[email protected]>
+
+description: |
+  The Unisoc DRM master device is a virtual device needed to list all
+  DPU devices or other display interface nodes that comprise the
+  graphics subsystem.
+
+  Unisoc's display pipeline have several components as below description,
+  multi display controllers and corresponding physical interfaces.
+  For different display scenarios, dpu0 and dpu1 maybe binding to different
+  encoder.
+
+  E.g:
+  dpu0 and dpu1 both binding to DSI for dual mipi-dsi display;
+  dpu0 binding to DSI for primary display, and dpu1 binding to DP for external display;
+
+          +-----------------------------------------+
+          |                                         |
+          |                            +---------+  |
+  +----+  |   +----+    +---------+    |DPHY/CPHY|  |   +------+
+  |    +----->+dpu0+--->+MIPI|DSI +--->+Combo    +----->+Panel0|
+  |AXI |  |   +----+    +---------+    +---------+  |   +------+
+  |    |  |                  ^                      |
+  |    |  |                  |                      |
+  |    |  |      +-----------+                      |
+  |    |  |      |                                  |
+  |APB |  |   +--+-+    +-----------+    +---+      |   +------+
+  |    +----->+dpu1+--->+DisplayPort+--->+PHY+--------->+Panel1|
+  |    |  |   +----+    +-----------+    +---+      |   +------+
+  +----+  |                                         |
+          +-----------------------------------------+
+
+properties:
+  compatible:
+    const: sprd,display-subsystem
+
+  ports:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    description:
+      Should contain a list of phandles pointing to display interface port
+      of DPU devices.
+
+required:
+  - compatible
+  - ports
+
+additionalProperties: false
+
+examples:
+  - |
+    display-subsystem {
+        compatible = "sprd,display-subsystem";
+        ports = <&dpu_out>;
+    };
+
Signature · 1 line
2.29.0
author
#2 lore raw

PATCH v7 2/6 drm/sprd: add Unisoc's drm kms master

In reply to Kevin Tang

Adds drm support for the Unisoc's display subsystem.

This is drm kms driver, this driver provides support for the application framework in Android, Yocto and more.

Application framework can access Unisoc's display internal peripherals through libdrm or libkms, it's test ok by modetest (DRM/KMS test tool) and Android HWComposer.

Cc Orson Zhai <[email protected]>
Cc Chunyan Zhang <[email protected]>

v4:
- Move the devm_drm_dev_alloc to master_ops->bind function.
- The managed drmm_mode_config_init() it is no longer necessary for drivers to explicitly call drm_mode_config_cleanup, so delete it.

v5:
- Remove subdir-ccflgas-y for Makefile.
- Keep the selects sorted by alphabet for Kconfig.

---
 drivers/gpu/drm/Kconfig         |   2 +
 drivers/gpu/drm/Makefile        |   1 +
 drivers/gpu/drm/sprd/Kconfig    |  11 ++
 drivers/gpu/drm/sprd/Makefile   |   3 +
 drivers/gpu/drm/sprd/sprd_drm.c | 203 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sprd/sprd_drm.h |  16 +++
 6 files changed, 236 insertions(+)
 create mode 100644 drivers/gpu/drm/sprd/Kconfig
 create mode 100644 drivers/gpu/drm/sprd/Makefile
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.h
drivers/gpu/drm/Kconfig +2 -0
index 2a926d0de..8220be1b5 100644
@@ -380,6 +380,8 @@ source "drivers/gpu/drm/xlnx/Kconfig"
 
 source "drivers/gpu/drm/gud/Kconfig"
 
+source "drivers/gpu/drm/sprd/Kconfig"
+
 config DRM_HYPERV
 	tristate "DRM Support for Hyper-V synthetic video device"
 	depends on DRM && PCI && MMU && HYPERV
drivers/gpu/drm/Makefile +1 -0
index 0dff40bb8..ec2756806 100644
@@ -127,3 +127,4 @@ obj-$(CONFIG_DRM_TIDSS) += tidss/
 obj-y			+= xlnx/
 obj-y			+= gud/
 obj-$(CONFIG_DRM_HYPERV) += hyperv/
+obj-$(CONFIG_DRM_SPRD) += sprd/
drivers/gpu/drm/sprd/Kconfig new file +11 -0
new file mode 100644
index 000000000..726c3e76d
@@ -0,0 +1,11 @@
+config DRM_SPRD
+	tristate "DRM Support for Unisoc SoCs Platform"
+	depends on ARCH_SPRD || COMPILE_TEST
+	depends on DRM && OF
+	select DRM_GEM_CMA_HELPER
+	select DRM_KMS_CMA_HELPER
+	select DRM_KMS_HELPER
+	help
+	  Choose this option if you have a Unisoc chipset.
+	  If M is selected the module will be called sprd_drm.
+
drivers/gpu/drm/sprd/Makefile new file +3 -0
new file mode 100644
index 000000000..9850f00b8
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-y := sprd_drm.o
drivers/gpu/drm/sprd/sprd_drm.c new file +203 -0

203 lines not on this page · raw message

drivers/gpu/drm/sprd/sprd_drm.h new file +16 -0
new file mode 100644
index 000000000..9781fd591
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 Unisoc Inc.
+ */
+
+#ifndef _SPRD_DRM_H_
+#define _SPRD_DRM_H_
+
+#include <drm/drm_atomic.h>
+#include <drm/drm_print.h>
+
+struct sprd_drm {
+	struct drm_device drm;
+};
+
+#endif /* _SPRD_DRM_H_ */
Signature · 1 line
2.29.0
#3 lore raw

Re: [PATCH v7 2/6] drm/sprd: add Unisoc's drm kms master

Quoted 300 lines · Kevin Tang

Adds drm support for the Unisoc's display subsystem.

This is drm kms driver, this driver provides support for the application framework in Android, Yocto and more.

Application framework can access Unisoc's display internal peripherals through libdrm or libkms, it's test ok by modetest (DRM/KMS test tool) and Android HWComposer.

Cc Orson Zhai <[email protected]>
Cc Chunyan Zhang <[email protected]>

v4:
- Move the devm_drm_dev_alloc to master_ops->bind function.
- The managed drmm_mode_config_init() it is no longer necessary for drivers to explicitly call drm_mode_config_cleanup, so delete it.

v5:
- Remove subdir-ccflgas-y for Makefile.
- Keep the selects sorted by alphabet for Kconfig.

---
 drivers/gpu/drm/Kconfig         |   2 +
 drivers/gpu/drm/Makefile        |   1 +
 drivers/gpu/drm/sprd/Kconfig    |  11 ++
 drivers/gpu/drm/sprd/Makefile   |   3 +
 drivers/gpu/drm/sprd/sprd_drm.c | 203 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sprd/sprd_drm.h |  16 +++
 6 files changed, 236 insertions(+)
 create mode 100644 drivers/gpu/drm/sprd/Kconfig
 create mode 100644 drivers/gpu/drm/sprd/Makefile
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.h
drivers/gpu/drm/Kconfig +2 -0
index 2a926d0de..8220be1b5 100644
@@ -380,6 +380,8 @@ source "drivers/gpu/drm/xlnx/Kconfig"
 
 source "drivers/gpu/drm/gud/Kconfig"
 
+source "drivers/gpu/drm/sprd/Kconfig"
+
 config DRM_HYPERV
 	tristate "DRM Support for Hyper-V synthetic video device"
 	depends on DRM && PCI && MMU && HYPERV
drivers/gpu/drm/Makefile +1 -0
index 0dff40bb8..ec2756806 100644
@@ -127,3 +127,4 @@ obj-$(CONFIG_DRM_TIDSS) += tidss/
 obj-y			+= xlnx/
 obj-y			+= gud/
 obj-$(CONFIG_DRM_HYPERV) += hyperv/
+obj-$(CONFIG_DRM_SPRD) += sprd/
drivers/gpu/drm/sprd/Kconfig new file +11 -0
new file mode 100644
index 000000000..726c3e76d
@@ -0,0 +1,11 @@
+config DRM_SPRD
+	tristate "DRM Support for Unisoc SoCs Platform"
+	depends on ARCH_SPRD || COMPILE_TEST
+	depends on DRM && OF
+	select DRM_GEM_CMA_HELPER
+	select DRM_KMS_CMA_HELPER
+	select DRM_KMS_HELPER
+	help
+	  Choose this option if you have a Unisoc chipset.
+	  If M is selected the module will be called sprd_drm.
+
drivers/gpu/drm/sprd/Makefile new file +3 -0
new file mode 100644
index 000000000..9850f00b8
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-y := sprd_drm.o
drivers/gpu/drm/sprd/sprd_drm.c new file +203 -0
new file mode 100644
index 000000000..bb87f28f2
@@ -0,0 +1,203 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 Unisoc Inc.
+ */
+
+#include <linux/component.h>
+#include <linux/dma-mapping.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of_graph.h>
+#include <linux/of_platform.h>
+
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_drv.h>
+#include <drm/drm_gem_cma_helper.h>
+#include <drm/drm_gem_framebuffer_helper.h>
+#include <drm/drm_of.h>
+#include <drm/drm_probe_helper.h>
+#include <drm/drm_vblank.h>
+
+#include "sprd_drm.h"
+
+#define DRIVER_NAME	"sprd"
+#define DRIVER_DESC	"Spreadtrum SoCs' DRM Driver"
+#define DRIVER_DATE	"20200201"
+#define DRIVER_MAJOR	1
+#define DRIVER_MINOR	0
+
+static const struct drm_mode_config_helper_funcs sprd_drm_mode_config_helper = {
+	.atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
+};
+
+static const struct drm_mode_config_funcs sprd_drm_mode_config_funcs = {
+	.fb_create = drm_gem_fb_create,
+	.atomic_check = drm_atomic_helper_check,
+	.atomic_commit = drm_atomic_helper_commit,
+};
+
+static void sprd_drm_mode_config_init(struct drm_device *drm)
+{
+	drm->mode_config.min_width = 0;
+	drm->mode_config.min_height = 0;
+	drm->mode_config.max_width = 8192;
+	drm->mode_config.max_height = 8192;
+	drm->mode_config.allow_fb_modifiers = true;
+
+	drm->mode_config.funcs = &sprd_drm_mode_config_funcs;
+	drm->mode_config.helper_private = &sprd_drm_mode_config_helper;
+}
+
+DEFINE_DRM_GEM_CMA_FOPS(sprd_drm_fops);
+
+static struct drm_driver sprd_drm_drv = {
+	.driver_features	= DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
+	.fops			= &sprd_drm_fops,
+
+	/* GEM Operations */
+	DRM_GEM_CMA_DRIVER_OPS,
+
+	.name			= DRIVER_NAME,
+	.desc			= DRIVER_DESC,
+	.date			= DRIVER_DATE,
+	.major			= DRIVER_MAJOR,
+	.minor			= DRIVER_MINOR,
+};
+
+static int sprd_drm_bind(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct drm_device *drm;
+	struct sprd_drm *sprd;
+	int ret;
+
+	sprd = devm_drm_dev_alloc(dev, &sprd_drm_drv, struct sprd_drm, drm);
+	if (IS_ERR(sprd))
+		return PTR_ERR(sprd);
+
+	drm = &sprd->drm;
+	platform_set_drvdata(pdev, drm);
+
+	ret = drmm_mode_config_init(drm);
+	if (ret)
+		return ret;
+
+	sprd_drm_mode_config_init(drm);
+
+	/* bind and init sub drivers */
+	ret = component_bind_all(drm->dev, drm);
+	if (ret) {
+		drm_err(drm, "failed to bind all component.\n");
+		return ret;
+	}
+
+	/* vblank init */
+	ret = drm_vblank_init(drm, drm->mode_config.num_crtc);
+	if (ret) {
+		drm_err(drm, "failed to initialize vblank.\n");
+		goto err_unbind_all;
+	}
+
+	/* reset all the states of crtc/plane/encoder/connector */
+	drm_mode_config_reset(drm);
+
+	/* init kms poll for handling hpd */
+	drm_kms_helper_poll_init(drm);
+
+	ret = drm_dev_register(drm, 0);
+	if (ret < 0)
+		goto err_kms_helper_poll_fini;
+
+	return 0;
+
+err_kms_helper_poll_fini:
+	drm_kms_helper_poll_fini(drm);
+err_unbind_all:
+	component_unbind_all(drm->dev, drm);
+	return ret;
+}
+
+static void sprd_drm_unbind(struct device *dev)
+{
+	struct drm_device *drm = dev_get_drvdata(dev);
+
+	drm_dev_unregister(drm);
+
+	drm_kms_helper_poll_fini(drm);
+
+	component_unbind_all(drm->dev, drm);
+}
+
+static const struct component_master_ops drm_component_ops = {
+	.bind = sprd_drm_bind,
+	.unbind = sprd_drm_unbind,
+};
+
+static int compare_of(struct device *dev, void *data)
+{
+	return dev->of_node == data;
+}
+
+static int sprd_drm_probe(struct platform_device *pdev)
+{
+	return drm_of_component_probe(&pdev->dev, compare_of, &drm_component_ops);
+}
+
+static int sprd_drm_remove(struct platform_device *pdev)
+{
+	component_master_del(&pdev->dev, &drm_component_ops);
+	return 0;
+}
+
+static void sprd_drm_shutdown(struct platform_device *pdev)
+{
+	struct drm_device *drm = platform_get_drvdata(pdev);
+
+	if (!drm) {
+		drm_warn(drm, "drm device is not available, no shutdown\n");
+		return;
+	}
+
+	drm_atomic_helper_shutdown(drm);
+}
+
+static const struct of_device_id drm_match_table[] = {
+	{ .compatible = "sprd,display-subsystem", },
+	{ /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, drm_match_table);
+
+static struct platform_driver sprd_drm_driver = {
+	.probe = sprd_drm_probe,
+	.remove = sprd_drm_remove,
+	.shutdown = sprd_drm_shutdown,
+	.driver = {
+		.name = "sprd-drm-drv",
+		.of_match_table = drm_match_table,
+	},
+};
+
+static struct platform_driver *sprd_drm_drivers[]  = {
+	&sprd_drm_driver,
+};
+
+static int __init sprd_drm_init(void)
+{
+	return platform_register_drivers(sprd_drm_drivers,
+					ARRAY_SIZE(sprd_drm_drivers));
+}
+
+static void __exit sprd_drm_exit(void)
+{
+	platform_unregister_drivers(sprd_drm_drivers,
+				    ARRAY_SIZE(sprd_drm_drivers));
+}
+
+module_init(sprd_drm_init);
+module_exit(sprd_drm_exit);
+
+MODULE_AUTHOR("Leon He <[email protected]>");
+MODULE_AUTHOR("Kevin Tang <[email protected]>");
+MODULE_DESCRIPTION("Unisoc DRM KMS Master Driver");
+MODULE_LICENSE("GPL v2");
drivers/gpu/drm/sprd/sprd_drm.h new file +4 -0
new file mode 100644
index 000000000..9781fd591
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 Unisoc Inc.
+ */

drivers/gpu/drm/sprd/sprd_drm.h line 14

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_drm.h new file +10 -0
+
+#ifndef _SPRD_DRM_H_
+#define _SPRD_DRM_H_
+
+#include <drm/drm_atomic.h>
+#include <drm/drm_print.h>
+
+struct sprd_drm {
+	struct drm_device drm;
+};

I've seen this in the patch adding sprd_plane too, are you planning to extend both structs?

~Maarten

author
#4 lore raw

Re: [PATCH v7 2/6] drm/sprd: add Unisoc's drm kms master

Quoted 315 lines · Maarten Lankhorst <[email protected]> 于2021年11月26日周五 22:03写道:
Quoted 300 lines · Kevin Tang

Adds drm support for the Unisoc's display subsystem.

This is drm kms driver, this driver provides support for the application framework in Android, Yocto and more.

Application framework can access Unisoc's display internal peripherals through libdrm or libkms, it's test ok by modetest (DRM/KMS test tool) and Android HWComposer.

Cc Orson Zhai <[email protected]>
Cc Chunyan Zhang <[email protected]>

v4:
- Move the devm_drm_dev_alloc to master_ops->bind function.
- The managed drmm_mode_config_init() it is no longer necessary for drivers to explicitly call drm_mode_config_cleanup, so delete it.

v5:
- Remove subdir-ccflgas-y for Makefile.
- Keep the selects sorted by alphabet for Kconfig.

---
 drivers/gpu/drm/Kconfig         |   2 +
 drivers/gpu/drm/Makefile        |   1 +
 drivers/gpu/drm/sprd/Kconfig    |  11 ++
 drivers/gpu/drm/sprd/Makefile   |   3 +
 drivers/gpu/drm/sprd/sprd_drm.c | 203 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sprd/sprd_drm.h |  16 +++
 6 files changed, 236 insertions(+)
 create mode 100644 drivers/gpu/drm/sprd/Kconfig
 create mode 100644 drivers/gpu/drm/sprd/Makefile
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.h
drivers/gpu/drm/Kconfig +2 -0
index 2a926d0de..8220be1b5 100644
@@ -380,6 +380,8 @@ source "drivers/gpu/drm/xlnx/Kconfig"
 
 source "drivers/gpu/drm/gud/Kconfig"
 
+source "drivers/gpu/drm/sprd/Kconfig"
+
 config DRM_HYPERV
      tristate "DRM Support for Hyper-V synthetic video device"
      depends on DRM && PCI && MMU && HYPERV
drivers/gpu/drm/Makefile +1 -0
index 0dff40bb8..ec2756806 100644
@@ -127,3 +127,4 @@ obj-$(CONFIG_DRM_TIDSS) += tidss/
 obj-y                        += xlnx/
 obj-y                        += gud/
 obj-$(CONFIG_DRM_HYPERV) += hyperv/
+obj-$(CONFIG_DRM_SPRD) += sprd/
drivers/gpu/drm/sprd/Kconfig new file +11 -0
new file mode 100644
index 000000000..726c3e76d
@@ -0,0 +1,11 @@
+config DRM_SPRD
+     tristate "DRM Support for Unisoc SoCs Platform"
+     depends on ARCH_SPRD || COMPILE_TEST
+     depends on DRM && OF
+     select DRM_GEM_CMA_HELPER
+     select DRM_KMS_CMA_HELPER
+     select DRM_KMS_HELPER
+     help
+       Choose this option if you have a Unisoc chipset.
+       If M is selected the module will be called sprd_drm.
+
drivers/gpu/drm/sprd/Makefile new file +3 -0
new file mode 100644
index 000000000..9850f00b8
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-y := sprd_drm.o
drivers/gpu/drm/sprd/sprd_drm.c new file +203 -0
new file mode 100644
index 000000000..bb87f28f2
@@ -0,0 +1,203 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 Unisoc Inc.
+ */
+
+#include <linux/component.h>
+#include <linux/dma-mapping.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of_graph.h>
+#include <linux/of_platform.h>
+
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_drv.h>
+#include <drm/drm_gem_cma_helper.h>
+#include <drm/drm_gem_framebuffer_helper.h>
+#include <drm/drm_of.h>
+#include <drm/drm_probe_helper.h>
+#include <drm/drm_vblank.h>
+
+#include "sprd_drm.h"
+
+#define DRIVER_NAME  "sprd"
+#define DRIVER_DESC  "Spreadtrum SoCs' DRM Driver"
+#define DRIVER_DATE  "20200201"
+#define DRIVER_MAJOR 1
+#define DRIVER_MINOR 0
+
+static const struct drm_mode_config_helper_funcs sprd_drm_mode_config_helper = {
+     .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
+};
+
+static const struct drm_mode_config_funcs sprd_drm_mode_config_funcs = {
+     .fb_create = drm_gem_fb_create,
+     .atomic_check = drm_atomic_helper_check,
+     .atomic_commit = drm_atomic_helper_commit,
+};
+
+static void sprd_drm_mode_config_init(struct drm_device *drm)
+{
+     drm->mode_config.min_width = 0;
+     drm->mode_config.min_height = 0;
+     drm->mode_config.max_width = 8192;
+     drm->mode_config.max_height = 8192;
+     drm->mode_config.allow_fb_modifiers = true;
+
+     drm->mode_config.funcs = &sprd_drm_mode_config_funcs;
+     drm->mode_config.helper_private = &sprd_drm_mode_config_helper;
+}
+
+DEFINE_DRM_GEM_CMA_FOPS(sprd_drm_fops);
+
+static struct drm_driver sprd_drm_drv = {
+     .driver_features        = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
+     .fops                   = &sprd_drm_fops,
+
+     /* GEM Operations */
+     DRM_GEM_CMA_DRIVER_OPS,
+
+     .name                   = DRIVER_NAME,
+     .desc                   = DRIVER_DESC,
+     .date                   = DRIVER_DATE,
+     .major                  = DRIVER_MAJOR,
+     .minor                  = DRIVER_MINOR,
+};
+
+static int sprd_drm_bind(struct device *dev)
+{
+     struct platform_device *pdev = to_platform_device(dev);
+     struct drm_device *drm;
+     struct sprd_drm *sprd;
+     int ret;
+
+     sprd = devm_drm_dev_alloc(dev, &sprd_drm_drv, struct sprd_drm, drm);
+     if (IS_ERR(sprd))
+             return PTR_ERR(sprd);
+
+     drm = &sprd->drm;
+     platform_set_drvdata(pdev, drm);
+
+     ret = drmm_mode_config_init(drm);
+     if (ret)
+             return ret;
+
+     sprd_drm_mode_config_init(drm);
+
+     /* bind and init sub drivers */
+     ret = component_bind_all(drm->dev, drm);
+     if (ret) {
+             drm_err(drm, "failed to bind all component.\n");
+             return ret;
+     }
+
+     /* vblank init */
+     ret = drm_vblank_init(drm, drm->mode_config.num_crtc);
+     if (ret) {
+             drm_err(drm, "failed to initialize vblank.\n");
+             goto err_unbind_all;
+     }
+
+     /* reset all the states of crtc/plane/encoder/connector */
+     drm_mode_config_reset(drm);
+
+     /* init kms poll for handling hpd */
+     drm_kms_helper_poll_init(drm);
+
+     ret = drm_dev_register(drm, 0);
+     if (ret < 0)
+             goto err_kms_helper_poll_fini;
+
+     return 0;
+
+err_kms_helper_poll_fini:
+     drm_kms_helper_poll_fini(drm);
+err_unbind_all:
+     component_unbind_all(drm->dev, drm);
+     return ret;
+}
+
+static void sprd_drm_unbind(struct device *dev)
+{
+     struct drm_device *drm = dev_get_drvdata(dev);
+
+     drm_dev_unregister(drm);
+
+     drm_kms_helper_poll_fini(drm);
+
+     component_unbind_all(drm->dev, drm);
+}
+
+static const struct component_master_ops drm_component_ops = {
+     .bind = sprd_drm_bind,
+     .unbind = sprd_drm_unbind,
+};
+
+static int compare_of(struct device *dev, void *data)
+{
+     return dev->of_node == data;
+}
+
+static int sprd_drm_probe(struct platform_device *pdev)
+{
+     return drm_of_component_probe(&pdev->dev, compare_of, &drm_component_ops);
+}
+
+static int sprd_drm_remove(struct platform_device *pdev)
+{
+     component_master_del(&pdev->dev, &drm_component_ops);
+     return 0;
+}
+
+static void sprd_drm_shutdown(struct platform_device *pdev)
+{
+     struct drm_device *drm = platform_get_drvdata(pdev);
+
+     if (!drm) {
+             drm_warn(drm, "drm device is not available, no shutdown\n");
+             return;
+     }
+
+     drm_atomic_helper_shutdown(drm);
+}
+
+static const struct of_device_id drm_match_table[] = {
+     { .compatible = "sprd,display-subsystem", },
+     { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, drm_match_table);
+
+static struct platform_driver sprd_drm_driver = {
+     .probe = sprd_drm_probe,
+     .remove = sprd_drm_remove,
+     .shutdown = sprd_drm_shutdown,
+     .driver = {
+             .name = "sprd-drm-drv",
+             .of_match_table = drm_match_table,
+     },
+};
+
+static struct platform_driver *sprd_drm_drivers[]  = {
+     &sprd_drm_driver,
+};
+
+static int __init sprd_drm_init(void)
+{
+     return platform_register_drivers(sprd_drm_drivers,
+                                     ARRAY_SIZE(sprd_drm_drivers));
+}
+
+static void __exit sprd_drm_exit(void)
+{
+     platform_unregister_drivers(sprd_drm_drivers,
+                                 ARRAY_SIZE(sprd_drm_drivers));
+}
+
+module_init(sprd_drm_init);
+module_exit(sprd_drm_exit);
+
+MODULE_AUTHOR("Leon He <[email protected]>");
+MODULE_AUTHOR("Kevin Tang <[email protected]>");
+MODULE_DESCRIPTION("Unisoc DRM KMS Master Driver");
+MODULE_LICENSE("GPL v2");
drivers/gpu/drm/sprd/sprd_drm.h new file +4 -0
new file mode 100644
index 000000000..9781fd591
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 Unisoc Inc.
+ */

drivers/gpu/drm/sprd/sprd_drm.h line 14

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_drm.h new file +10 -0
+
+#ifndef _SPRD_DRM_H_
+#define _SPRD_DRM_H_
+
+#include <drm/drm_atomic.h>
+#include <drm/drm_print.h>
+
+struct sprd_drm {
+     struct drm_device drm;
+};

I've seen this in the patch adding sprd_plane too, are you planning to extend both structs?

Quoted 2 lines

~Maarten

Hi Maarten,
Yes, after the basic version is merged, we will continue to expand these two structures

author
#5 lore raw

PATCH v7 3/6 dt-bindings: display: add Unisoc's dpu bindings

In reply to Kevin Tang

From: Kevin Tang <[email protected]>

DPU (Display Processor Unit) is the Display Controller for the Unisoc SoCs which transfers the image data from a video memory buffer to an internal LCD interface.

---
 .../display/sprd/sprd,sharkl3-dpu.yaml        | 77 +++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/sprd/sprd,sharkl3-dpu.yaml
Documentation/devicetree/bindings/display/sprd/sprd,sharkl3-dpu.yaml new file +77 -0
new file mode 100644
index 000000000..4ebea60b8
@@ -0,0 +1,77 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/sprd/sprd,sharkl3-dpu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Unisoc Sharkl3 Display Processor Unit (DPU)
+
+maintainers:
+  - Kevin Tang <[email protected]>
+
+description: |
+  DPU (Display Processor Unit) is the Display Controller for the Unisoc SoCs
+  which transfers the image data from a video memory buffer to an internal
+  LCD interface.
+
+properties:
+  compatible:
+    const: sprd,sharkl3-dpu
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    minItems: 2
+
+  clock-names:
+    items:
+      - const: clk_src_128m
+      - const: clk_src_384m
+
+  power-domains:
+    maxItems: 1
+
+  iommus:
+    maxItems: 1
+
+  port:
+    type: object
+    description:
+      A port node with endpoint definitions as defined in
+      Documentation/devicetree/bindings/media/video-interfaces.txt.
+      That port should be the output endpoint, usually output to
+      the associated DSI.
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - port
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/sprd,sc9860-clk.h>
+    dpu: dpu@63000000 {
+        compatible = "sprd,sharkl3-dpu";
+        reg = <0x63000000 0x1000>;
+        interrupts = <GIC_SPI 46 IRQ_TYPE_LEVEL_HIGH>;
+        clock-names = "clk_src_128m", "clk_src_384m";
+
+        clocks = <&pll CLK_TWPLL_128M>,
+          <&pll CLK_TWPLL_384M>;
+
+        dpu_port: port {
+            dpu_out: endpoint {
+                remote-endpoint = <&dsi_in>;
+            };
+        };
+    };
Signature · 1 line
2.29.0
author
#6 lore raw

PATCH v7 4/6 drm/sprd: add Unisoc's drm display controller driver

In reply to Kevin Tang

Adds DPU(Display Processor Unit) support for the Unisoc's display subsystem.
It's support multi planes, scaler, rotation, PQ(Picture Quality) and more.

v2:
- Use drm_xxx to replace all DRM_XXX.
- Use kzalloc to replace devm_kzalloc for sprd_dpu structure init.

v3:
- Remove dpu_layer stuff layer and commit layers by aotmic_update

v4:
- Use drmm_helpers to allocate crtc and planes.
- Move rotation enum definitions to crtc layer reg bitfields.
- Move allocate crtc and planes to bind function.

v5:
- Fix the checkpatch warnings.
- Use mode_set_nofb instead of mode_valid callback.
- Follow the OF-Graph bindings, use of_graph_get_port_by_id instead of of_parse_phandle.
- Use zpos to represent the layer position.
- Rebase to last drm misc branch.

v6:
- Disable and clear interrupts before register dpu IRQ
- Init dpi config used by crtc_state->adjusted_mode on mode_set_nofb
- Remove enable_irq and disable_irq function call.
- Remove drm_format_info function call.

v7:
- Remove iommu error interrupt handling function.

Cc Orson Zhai <[email protected]>
Cc Chunyan Zhang <[email protected]>
---
 drivers/gpu/drm/sprd/Kconfig    |   1 +
 drivers/gpu/drm/sprd/Makefile   |   3 +-
 drivers/gpu/drm/sprd/sprd_dpu.c | 867 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sprd/sprd_dpu.h | 109 ++++
 drivers/gpu/drm/sprd/sprd_drm.c |   1 +
 drivers/gpu/drm/sprd/sprd_drm.h |   2 +
 6 files changed, 982 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/sprd/sprd_dpu.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_dpu.h
drivers/gpu/drm/sprd/Kconfig +1 -0
index 726c3e76d..37762c333 100644
@@ -5,6 +5,7 @@ config DRM_SPRD
 	select DRM_GEM_CMA_HELPER
 	select DRM_KMS_CMA_HELPER
 	select DRM_KMS_HELPER
+	select VIDEOMODE_HELPERS
 	help
 	  Choose this option if you have a Unisoc chipset.
 	  If M is selected the module will be called sprd_drm.
drivers/gpu/drm/sprd/Makefile +2 -1
index 9850f00b8..ab12b95e6 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
-obj-y := sprd_drm.o
+obj-y := sprd_drm.o \
+	sprd_dpu.o
drivers/gpu/drm/sprd/sprd_dpu.c new file +867 -0

867 lines not on this page · raw message

drivers/gpu/drm/sprd/sprd_dpu.h new file +109 -0

109 lines not on this page · raw message

drivers/gpu/drm/sprd/sprd_drm.c +1 -0
index bb87f28f2..59b9e54f7 100644
@@ -180,6 +180,7 @@ static struct platform_driver sprd_drm_driver = {
 
 static struct platform_driver *sprd_drm_drivers[]  = {
 	&sprd_drm_driver,
+	&sprd_dpu_driver,
 };
 
 static int __init sprd_drm_init(void)
drivers/gpu/drm/sprd/sprd_drm.h +2 -0
index 9781fd591..85d4a8b9f 100644
@@ -13,4 +13,6 @@ struct sprd_drm {
 	struct drm_device drm;
 };
 
+extern struct platform_driver sprd_dpu_driver;
+
 #endif /* _SPRD_DRM_H_ */
Signature · 1 line
2.29.0
Reviewed-by on v7 4/6
#7 lore raw

Re: [PATCH v7 4/6] drm/sprd: add Unisoc's drm display controller driver

Quoted 30 lines · Kevin Tang

Adds DPU(Display Processor Unit) support for the Unisoc's display subsystem.
It's support multi planes, scaler, rotation, PQ(Picture Quality) and more.

v2:
- Use drm_xxx to replace all DRM_XXX.
- Use kzalloc to replace devm_kzalloc for sprd_dpu structure init.

v3:
- Remove dpu_layer stuff layer and commit layers by aotmic_update

v4:
- Use drmm_helpers to allocate crtc and planes.
- Move rotation enum definitions to crtc layer reg bitfields.
- Move allocate crtc and planes to bind function.

v5:
- Fix the checkpatch warnings.
- Use mode_set_nofb instead of mode_valid callback.
- Follow the OF-Graph bindings, use of_graph_get_port_by_id instead of of_parse_phandle.
- Use zpos to represent the layer position.
- Rebase to last drm misc branch.

v6:
- Disable and clear interrupts before register dpu IRQ
- Init dpi config used by crtc_state->adjusted_mode on mode_set_nofb
- Remove enable_irq and disable_irq function call.
- Remove drm_format_info function call.

Quoted 6 lines

v7:
- Remove iommu error interrupt handling function.

Cc Orson Zhai <[email protected]>
Cc Chunyan Zhang <[email protected]>

Maxime

author
#8 lore raw

PATCH v7 5/6 dt-bindings: display: add Unisoc's mipi dsi controller bindings

In reply to Kevin Tang

From: Kevin Tang <[email protected]>

Adds MIPI DSI Controller
support for Unisoc's display subsystem.

v5:
- Remove panel_in port for dsi node.

---
 .../display/sprd/sprd,sharkl3-dsi-host.yaml   | 88 +++++++++++++++++++
 1 file changed, 88 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/sprd/sprd,sharkl3-dsi-host.yaml
Documentation/devicetree/bindings/display/sprd/sprd,sharkl3-dsi-host.yaml new file +88 -0
new file mode 100644
index 000000000..bc5594d18
@@ -0,0 +1,88 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/sprd/sprd,sharkl3-dsi-host.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Unisoc MIPI DSI Controller
+
+maintainers:
+  - Kevin Tang <[email protected]>
+
+properties:
+  compatible:
+    const: sprd,sharkl3-dsi-host
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 2
+
+  clocks:
+    minItems: 1
+
+  clock-names:
+    items:
+      - const: clk_src_96m
+
+  power-domains:
+    maxItems: 1
+
+  ports:
+    type: object
+
+    properties:
+      "#address-cells":
+        const: 1
+
+      "#size-cells":
+        const: 0
+
+      port@0:
+        type: object
+        description:
+          A port node with endpoint definitions as defined in
+          Documentation/devicetree/bindings/media/video-interfaces.txt.
+          That port should be the input endpoint, usually coming from
+          the associated DPU.
+
+    required:
+      - "#address-cells"
+      - "#size-cells"
+      - port@0
+
+    additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - ports
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/sprd,sc9860-clk.h>
+    dsi: dsi@63100000 {
+        compatible = "sprd,sharkl3-dsi-host";
+        reg = <0x63100000 0x1000>;
+        interrupts = <GIC_SPI 48 IRQ_TYPE_LEVEL_HIGH>,
+          <GIC_SPI 49 IRQ_TYPE_LEVEL_HIGH>;
+        clock-names = "clk_src_96m";
+        clocks = <&pll CLK_TWPLL_96M>;
+        ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+            port@0 {
+                reg = <0>;
+                dsi_in: endpoint {
+                    remote-endpoint = <&dpu_out>;
+                };
+            };
+        };
+    };
Signature · 1 line
2.29.0
author
#9 lore raw

PATCH v7 6/6 drm/sprd: add Unisoc's drm mipi dsi&dphy driver

In reply to Kevin Tang

Adds dsi host controller support for the Unisoc's display subsystem. Adds dsi phy support for the Unisoc's display subsystem. Only MIPI DSI Displays supported, DP/TV/HMDI will be support in the feature.

v1:
- Remove dphy and dsi graph binding, merge the dphy driver into the dsi.

v2:
- Use drm_xxx to replace all DRM_XXX.
- Use kzalloc to replace devm_kzalloc for sprd_dsi structure init.

v4:
- Use drmm_helpers to allocate encoder.
- Move allocate encoder and connector to bind function.

v5:
- Drop the dsi ip file prefix.
- Fix the checkpatch warnings.
- Add Signed-off-by for dsi&dphy patch.
- Use the mode_flags of mipi_dsi_device to setup crtc DPI and EDPI mode.

v6:
- Redesign the way to access the dsi register.
- Reduce the dsi_context member variables.

v7:
- Fix codeing style issue by checkpatch.
- Drop the pll registers structure define.
- Use bridge API instead of drm panel API.
- Register mipi_dsi_host on probe phase;
- Remove some unused function.

---
 drivers/gpu/drm/sprd/Kconfig         |    1 +
 drivers/gpu/drm/sprd/Makefile        |    4 +-
 drivers/gpu/drm/sprd/megacores_pll.c |  305 ++++++++
 drivers/gpu/drm/sprd/sprd_dpu.c      |   17 +
 drivers/gpu/drm/sprd/sprd_drm.c      |    1 +
 drivers/gpu/drm/sprd/sprd_drm.h      |    1 +
 drivers/gpu/drm/sprd/sprd_dsi.c      | 1065 ++++++++++++++++++++++++++
 drivers/gpu/drm/sprd/sprd_dsi.h      |  126 +++
 8 files changed, 1519 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/sprd/megacores_pll.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_dsi.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_dsi.h
drivers/gpu/drm/sprd/Kconfig +1 -0
index 37762c333..3edeaeca0 100644
@@ -5,6 +5,7 @@ config DRM_SPRD
 	select DRM_GEM_CMA_HELPER
 	select DRM_KMS_CMA_HELPER
 	select DRM_KMS_HELPER
+	select DRM_MIPI_DSI
 	select VIDEOMODE_HELPERS
 	help
 	  Choose this option if you have a Unisoc chipset.
drivers/gpu/drm/sprd/Makefile +3 -1
index ab12b95e6..73f96c459 100644
@@ -1,4 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-y := sprd_drm.o \
-	sprd_dpu.o
+	sprd_dpu.o \
+	sprd_dsi.o \
+	megacores_pll.o
drivers/gpu/drm/sprd/megacores_pll.c new file +305 -0

305 lines not on this page · raw message

drivers/gpu/drm/sprd/sprd_dpu.c +17 -0
index 1d10d0998..ce9691f50 100644
@@ -25,6 +25,7 @@
 
 #include "sprd_drm.h"
 #include "sprd_dpu.h"
+#include "sprd_dsi.h"
 
 /* Global control registers */
 #define REG_DPU_CTRL	0x04
@@ -618,9 +619,25 @@ static void sprd_crtc_mode_set_nofb(struct drm_crtc *crtc)
 {
 	struct sprd_dpu *dpu = to_sprd_crtc(crtc);
 	struct drm_display_mode *mode = &crtc->state->adjusted_mode;
+	struct drm_encoder *encoder;
+	struct mipi_dsi_device *slave;
+	struct sprd_dsi *dsi;
 
 	drm_display_mode_to_videomode(mode, &dpu->ctx.vm);
 
+	drm_for_each_encoder(encoder, crtc->dev) {
+		if (encoder->crtc != crtc)
+			continue;
+
+		dsi = encoder_to_dsi(encoder);
+		slave = dsi->slave;
+
+		if (slave->mode_flags & MIPI_DSI_MODE_VIDEO)
+			dpu->ctx.if_type = SPRD_DPU_IF_DPI;
+		else
+			dpu->ctx.if_type = SPRD_DPU_IF_EDPI;
+	}
+
 	sprd_dpi_init(dpu);
 }
 
drivers/gpu/drm/sprd/sprd_drm.c +1 -0
index 59b9e54f7..a077e2d4d 100644
@@ -181,6 +181,7 @@ static struct platform_driver sprd_drm_driver = {
 static struct platform_driver *sprd_drm_drivers[]  = {
 	&sprd_drm_driver,
 	&sprd_dpu_driver,
+	&sprd_dsi_driver,
 };
 
 static int __init sprd_drm_init(void)
drivers/gpu/drm/sprd/sprd_drm.h +1 -0
index 85d4a8b9f..95d1b972f 100644
@@ -14,5 +14,6 @@ struct sprd_drm {
 };
 
 extern struct platform_driver sprd_dpu_driver;
+extern struct platform_driver sprd_dsi_driver;
 
 #endif /* _SPRD_DRM_H_ */
drivers/gpu/drm/sprd/sprd_dsi.c new file +1065 -0

1,065 lines not on this page · raw message

drivers/gpu/drm/sprd/sprd_dsi.h new file +126 -0

126 lines not on this page · raw message

Signature · 1 line
2.29.0
#10 lore raw

Re: [PATCH v7 6/6] drm/sprd: add Unisoc's drm mipi dsi&dphy driver

Thank you for the patch! Yet something to improve:

Hi Kevin,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on robh/for-next]
[also build test ERROR on v5.15-rc7 next-20211025]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kevin-Tang/Add-Unisoc-s-drm-kms-module/20211025-173717
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
config: nios2-allyesconfig (attached as .config)
compiler: nios2-linux-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/99017a6a5c531e08eb995f84c148c9995a064143
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Kevin-Tang/Add-Unisoc-s-drm-kms-module/20211025-173717 git checkout 99017a6a5c531e08eb995f84c148c9995a064143
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=nios2

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

drivers/gpu/drm/sprd/sprd_dsi.c: In function 'sprd_dsi_bridge_init':

>> drivers/gpu/drm/sprd/sprd_dsi.c:938:29: error: implicit declaration of function 'devm_drm_of_get_bridge'; did you mean 'devm_drm_panel_bridge_add'? [-Werror=implicit-function-declaration]
     938 |         dsi->panel_bridge = devm_drm_of_get_bridge(dev, dev->of_node, 1, 0);
         |                             ^~~~~~~~~~~~~~~~~~~~~~
         |                             devm_drm_panel_bridge_add
>> drivers/gpu/drm/sprd/sprd_dsi.c:938:27: error: assignment to 'struct drm_bridge *' from 'int' makes pointer from integer without a cast [-Werror=int-conversion]
     938 |         dsi->panel_bridge = devm_drm_of_get_bridge(dev, dev->of_node, 1, 0);
         |                           ^
   At top level:
>> drivers/gpu/drm/sprd/sprd_dsi.c:853:39: error: 'sprd_encoder_funcs' defined but not used [-Werror=unused-const-variable=]
     853 | static const struct drm_encoder_funcs sprd_encoder_funcs = {
         |                                       ^~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

vim +938 drivers/gpu/drm/sprd/sprd_dsi.c

852

 > 853	static const struct drm_encoder_funcs sprd_encoder_funcs = {
   854		.destroy = drm_encoder_cleanup,
   855	};
   856	
   857	static int sprd_dsi_host_attach(struct mipi_dsi_host *host,
   858					struct mipi_dsi_device *slave)
   859	{
   860		struct sprd_dsi *dsi = host_to_dsi(host);
   861		struct dsi_context *ctx = &dsi->ctx;
   862	
   863		dsi->slave = slave;
   864	
   865		if (slave->mode_flags & MIPI_DSI_MODE_VIDEO)
   866			ctx->work_mode = DSI_MODE_VIDEO;
   867		else
   868			ctx->work_mode = DSI_MODE_CMD;
   869	
   870		if (slave->mode_flags & MIPI_DSI_MODE_VIDEO_BURST)
   871			ctx->burst_mode = VIDEO_BURST_WITH_SYNC_PULSES;
   872		else if (slave->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE)
   873			ctx->burst_mode = VIDEO_NON_BURST_WITH_SYNC_PULSES;
   874		else
   875			ctx->burst_mode = VIDEO_NON_BURST_WITH_SYNC_EVENTS;
   876	
   877		return 0;
   878	}
   879	
   880	static int sprd_dsi_host_detach(struct mipi_dsi_host *host,
   881					struct mipi_dsi_device *slave)
   882	{
   883		/* do nothing */
   884		return 0;
   885	}
   886	
   887	static ssize_t sprd_dsi_host_transfer(struct mipi_dsi_host *host,
   888					      const struct mipi_dsi_msg *msg)
   889	{
   890		struct sprd_dsi *dsi = host_to_dsi(host);
   891		const u8 *tx_buf = msg->tx_buf;
   892	
   893		if (msg->rx_buf && msg->rx_len) {
   894			u8 lsb = (msg->tx_len > 0) ? tx_buf[0] : 0;
   895			u8 msb = (msg->tx_len > 1) ? tx_buf[1] : 0;
   896	
   897			return sprd_dsi_rd_pkt(&dsi->ctx, msg->channel, msg->type,
   898					msb, lsb, msg->rx_buf, msg->rx_len);
   899		}
   900	
   901		if (msg->tx_buf && msg->tx_len)
   902			return sprd_dsi_wr_pkt(&dsi->ctx, msg->channel, msg->type,
   903						tx_buf, msg->tx_len);
   904	
   905		return 0;
   906	}
   907	
   908	static const struct mipi_dsi_host_ops sprd_dsi_host_ops = {
   909		.attach = sprd_dsi_host_attach,
   910		.detach = sprd_dsi_host_detach,
   911		.transfer = sprd_dsi_host_transfer,
   912	};
   913	
   914	static int sprd_dsi_encoder_init(struct sprd_dsi *dsi,
   915					 struct device *dev)
   916	{
   917		u32 crtc_mask;
   918	
   919		crtc_mask = drm_of_find_possible_crtcs(dsi->drm, dev->of_node);
   920		if (!crtc_mask) {
   921			drm_err(dsi->drm, "failed to find crtc mask\n");
   922			return -EINVAL;
   923		}
   924	
   925		drm_dbg(dsi->drm, "find possible crtcs: 0x%08x\n", crtc_mask);
   926	
   927		dsi->encoder.possible_crtcs = crtc_mask;
   928		drm_encoder_helper_add(&dsi->encoder, &sprd_encoder_helper_funcs);
   929	
   930		return 0;
   931	}
   932	
   933	static int sprd_dsi_bridge_init(struct sprd_dsi *dsi,
   934					struct device *dev)
   935	{
   936		int ret;
   937	
 > 938		dsi->panel_bridge = devm_drm_of_get_bridge(dev, dev->of_node, 1, 0);

939 if (IS_ERR(dsi->panel_bridge))
940 return PTR_ERR(dsi->panel_bridge);
941
942 ret = drm_bridge_attach(&dsi->encoder, dsi->panel_bridge, NULL, 0);
943 if (ret)
944 return ret;
945
946 return 0;
947 }
948

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#11 lore raw

Re: [PATCH v7 6/6] drm/sprd: add Unisoc's drm mipi dsi&dphy driver

In reply to Kevin Tang

drivers/gpu/drm/sprd/sprd_dpu.c static void sprd_crtc_mode_set_nofb(struct drm_crtc *crtc) · line 630

Quoted 13 lines · Kevin Tang
drivers/gpu/drm/sprd/sprd_dpu.c +6 -0
@@ -618,9 +619,25 @@ static void sprd_crtc_mode_set_nofb(struct drm_crtc *crtc)
 {
 	struct sprd_dpu *dpu = to_sprd_crtc(crtc);
 	struct drm_display_mode *mode = &crtc->state->adjusted_mode;
+	struct drm_encoder *encoder;
+	struct mipi_dsi_device *slave;
+	struct sprd_dsi *dsi;
 
 	drm_display_mode_to_videomode(mode, &dpu->ctx.vm);
 
+	drm_for_each_encoder(encoder, crtc->dev) {
+		if (encoder->crtc != crtc)
+			continue;

encoder->crtc is deprecated. You should be using encoder->drm_for_each_encoder_mask, using the encoder_mask in encoder->drm_crtc_state.

Quoted 6 lines
drivers/gpu/drm/sprd/sprd_dsi.c new file +6 -0
+static int sprd_dsi_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct sprd_dsi *dsi;
+
+	dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL);

drivers/gpu/drm/sprd/sprd_dsi.c line 1039

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_dsi.c new file +10 -0
+	if (!dsi)
+		return -ENOMEM;
+
+	dev_set_drvdata(dev, dsi);
+
+	dsi->host.ops = &sprd_dsi_host_ops;
+	dsi->host.dev = dev;
+	mipi_dsi_host_register(&dsi->host);
+
+	return component_add(&pdev->dev, &dsi_component_ops);

component_add must be run in the mipi_dsi_host.attach hook.

Maxime

author
#12 lore raw

Re: [PATCH v7 6/6] drm/sprd: add Unisoc's drm mipi dsi&dphy driver

Quoted 12 lines · Maxime Ripard <[email protected]> 于2021年12月3日周五 18:38写道:
Quoted 10 lines · Kevin Tang
drivers/gpu/drm/sprd/sprd_dpu.c +3 -0
@@ -618,9 +619,25 @@ static void sprd_crtc_mode_set_nofb(struct drm_crtc *crtc)
 {
      struct sprd_dpu *dpu = to_sprd_crtc(crtc);
      struct drm_display_mode *mode = &crtc->state->adjusted_mode;
+     struct drm_encoder *encoder;
+     struct mipi_dsi_device *slave;
+     struct sprd_dsi *dsi;
 
      drm_display_mode_to_videomode(mode, &dpu->ctx.vm);
 
Quoted 7 lines

drivers/gpu/drm/sprd/sprd_dpu.c static void sprd_crtc_mode_set_nofb(struct drm_crtc *crtc) · line 630

Quoted 3 lines
drivers/gpu/drm/sprd/sprd_dpu.c +3 -0
+     drm_for_each_encoder(encoder, crtc->dev) {
+             if (encoder->crtc != crtc)
+                     continue;

encoder->crtc is deprecated. You should be using encoder->drm_for_each_encoder_mask, using the encoder_mask in encoder->drm_crtc_state.

Use drm_for_each_encoder_mask to replace drm_for_each_encoder? like this:

drm_for_each_encoder_mask(encoder, crtc->dev, crtc->state->encoder_mask) {
    dsi = encoder_to_dsi(encoder);
    slave = dsi->slave;

    if (slave->mode_flags & MIPI_DSI_MODE_VIDEO)
        dpu->ctx.if_type = SPRD_DPU_IF_DPI;
    else
         dpu->ctx.if_type = SPRD_DPU_IF_EDPI;
}
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/sprd/sprd_dsi.c new file +10 -0
+static int sprd_dsi_probe(struct platform_device *pdev)
+{
+     struct device *dev = &pdev->dev;
+     struct sprd_dsi *dsi;
+
+     dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL);
+     if (!dsi)
+             return -ENOMEM;
+
+     dev_set_drvdata(dev, dsi);
Quoted 8 lines

drivers/gpu/drm/sprd/sprd_dsi.c line 1039

Quoted 6 lines
drivers/gpu/drm/sprd/sprd_dsi.c new file +6 -0
+
+     dsi->host.ops = &sprd_dsi_host_ops;
+     dsi->host.dev = dev;
+     mipi_dsi_host_register(&dsi->host);
+
+     return component_add(&pdev->dev, &dsi_component_ops);

component_add must be run in the mipi_dsi_host.attach hook.

Got it, will be fixed on patch v8.

Quoted 2 lines

Maxime

#13 lore raw

Re: [PATCH v7 6/6] drm/sprd: add Unisoc's drm mipi dsi&dphy driver

Quoted 22 lines · Kevin Tang
Quoted 12 lines · Maxime Ripard <[email protected]> 于2021年12月3日周五 18:38写道:
Quoted 10 lines · Kevin Tang
drivers/gpu/drm/sprd/sprd_dpu.c +3 -0
@@ -618,9 +619,25 @@ static void sprd_crtc_mode_set_nofb(struct drm_crtc *crtc)
 {
      struct sprd_dpu *dpu = to_sprd_crtc(crtc);
      struct drm_display_mode *mode = &crtc->state->adjusted_mode;
+     struct drm_encoder *encoder;
+     struct mipi_dsi_device *slave;
+     struct sprd_dsi *dsi;
 
      drm_display_mode_to_videomode(mode, &dpu->ctx.vm);
 
Quoted 7 lines

drivers/gpu/drm/sprd/sprd_dpu.c static void sprd_crtc_mode_set_nofb(struct drm_crtc *crtc) · line 630

Quoted 3 lines
drivers/gpu/drm/sprd/sprd_dpu.c +3 -0
+     drm_for_each_encoder(encoder, crtc->dev) {
+             if (encoder->crtc != crtc)
+                     continue;

encoder->crtc is deprecated. You should be using encoder->drm_for_each_encoder_mask, using the encoder_mask in encoder->drm_crtc_state.

Use drm_for_each_encoder_mask to replace drm_for_each_encoder? like this:

Quoted 9 lines
drm_for_each_encoder_mask(encoder, crtc->dev, crtc->state->encoder_mask) {
    dsi = encoder_to_dsi(encoder);
    slave = dsi->slave;

    if (slave->mode_flags & MIPI_DSI_MODE_VIDEO)
        dpu->ctx.if_type = SPRD_DPU_IF_DPI;
    else
         dpu->ctx.if_type = SPRD_DPU_IF_EDPI;
}

Yes

Maxime