From patchwork Sun Feb 13 14:16:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 12744615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ADDFEC4332F for ; Sun, 13 Feb 2022 14:17:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 47D9610E3A6; Sun, 13 Feb 2022 14:17:01 +0000 (UTC) Received: from 189.cn (ptr.189.cn [183.61.185.101]) by gabe.freedesktop.org (Postfix) with ESMTP id AF3D010E393 for ; Sun, 13 Feb 2022 14:16:57 +0000 (UTC) HMM_SOURCE_IP: 10.64.8.41:34274.536114013 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.41]) by 189.cn (HERMES) with SMTP id 56E571001C8; Sun, 13 Feb 2022 22:16:54 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-b7fbf7d79-9vctg with ESMTP id 5d4a8a72a11d40c7b1881991bcd97961 for mripard@kernel.org; Sun, 13 Feb 2022 22:16:56 CST X-Transaction-ID: 5d4a8a72a11d40c7b1881991bcd97961 X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 From: Sui Jingfeng <15330273260@189.cn> To: Maxime Ripard , Thomas Zimmermann , Roland Scheidegger , Zack Rusin , Christian Gmeiner , David Airlie , Daniel Vetter , Rob Herring , Thomas Bogendoerfer , Dan Carpenter , Krzysztof Kozlowski , Andrey Zhizhikin , Sam Ravnborg , "David S . Miller" , Jiaxun Yang , Lucas Stach , Maarten Lankhorst , Ilia Mirkin , Qing Zhang , Li Yi , suijingfeng Subject: [PATCH v7 1/7] drm/lsdc: add drm driver for loongson display controller Date: Sun, 13 Feb 2022 22:16:43 +0800 Message-Id: <20220213141649.1115987-2-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220213141649.1115987-1-15330273260@189.cn> References: <20220213141649.1115987-1-15330273260@189.cn> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, kernel test robot , Randy Dunlap , linux-mips@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Maxime Ripard Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: suijingfeng There is a display controller in loongson's LS2K1000 SoC and LS7A1000 bridge chip, the DC is a PCI device in those chips. It has two display pipes but with only one hardware cursor. Each way has a DVO interface which provide RGB888 signals, vertical & horizontal synchronisations, data enable and the pixel clock. Each CRTC is able to scanout from 1920x1080 resolution at 60Hz. The maxmium resolution is 2048x2048 according to the hardware spec. Loongson display controllers are simple which require scanout buffers to be physically contiguous. LS2K1000 is a SOC, Only system memory is available. Therefore CMA helper based driver is intended to be use, although it is possible to use VRAM helper based solution by carving out part of system memory as VRAM. On LS7A1000/LS7A2000 bridge chip, the DC is equipped with a dedicated video memory which is typically 64MB or more. In this case, VRAM helper based solution which scanout from local VRAM is reconmended to use. It is reliable to use for massive production, but CMA based helper solution is still usable on ls7a1000 and ls7a2000, at the price of the CRTC must access the FB in RAM through the PCIe bus and HT3.0 bus. This causes continuous traffic on the bus regardless of whether the FB image is updating or not. Sadly, it suffer from screen flickering under RAM pressure on LS7A1000. Luckily, It show extremely good condition on LS7A2000 even under stressapptest, Maybe the hardware engineer resolve this issue. Integrating two distict helpers based driver into one piece allow code sharing. We have also implemented demage update on top of CMA helper which copy the demaged region from the shadow framebuffer in system RAM to the real framebuffer in VRAM manually. This is intend to overcome the screen flicking issue on LS7A1000, but the performance is not good. Using "lsdc.dirty_update=1" in the kernel commmand line if you would like to have a try. For LS7A1000, there are 4 dedicated GPIOs whose control register is located at the DC register space, They are used to emulate two way i2c. One for DVO0, another for DVO1. This is the reason why this driver is not switch to drm bridge framework yet. LS2K1000 and LS2K0500 SoC don't have such GPIO hardwared, they grab i2c adapter from other module, either general purpose GPIO emulated i2c or hardware i2c adapter. Drm bridge and drm panel driver for the external encoder is suitable for those SoC. We have already implemented this on our downstream 4.19.190 kernel. But due to the GPIO, PWM and I2C device driver support for LS2K1000 is not upstreamed yet, this driver still can be use to bring the graphic environment up by providing display timings or similar things in the device tree. The DC in LS7A1000 has only one hardware cursor, we simply let the two CRTC share it. The DC in LS7A2000 have two cursor, two built-in hdmi encoder and one transparent vga encoder and more, surport for LS7A2000 is on the way. In short, we have built-in gpio emulated i2c support, we also have hardware cursor support. LS7A2000 The kind of tiny drivers in drm/tiny is not suitable for us. +------+ +-----------------------------------+ | DDR4 | | +-------------------+ | +------+ | | PCIe Root complex | LS7A1000 | || MC0 | +--++---------++----+ | +----------+ HT 3.0 | || || | | LS3A4000 |<-------->| +---++---+ +--++--+ +---------+ +------+ | CPU |<-------->| | GC1000 | | LSDC |<-->| DDR3 MC |<->| VRAM | +----------+ | +--------+ +-+--+-+ +---------+ +------+ || MC1 +---------------|--|----------------+ +------+ | | | DDR4 | +-------+ DVO0 | | DVO1 +------+ +------+ VGA <--|ADV7125|<--------+ +-------->|TFP410|--> DVI/HDMI +-------+ +------+ The above picture give a simple usage of LS7A1000, note that the encoder is not necessary adv7125 or tfp410, it is a choice of the downstream board manufacturer. Other candicate encoders can be ch7034b, sil9022 and ite66121 lt8618 etc. Besides, the DC in both ls2k1000 and ls7k1000 has the same of PCI vendor id and pci device id. Both is 0x0014:0x7a06, the reverison id is also same. This is the firmware engineer's mistake, but such firmware and various boards ship with such firmware already released. We choose to deduce the chip's identification from information provided by device tree. For lsdc, there is only a 1:1 mapping of encoders and connectors. v2: fixup warnings reported by kernel test robot v3: fix more grammar mistakes in Kconfig reported by Randy Dunlap and give more details about lsdc. v4: 1) Add dts required and explain why device tree is required. 2) Give more description about lsdc and vram helper base driver. 3) Fix warnings reported by kernel test robot. 4) Introduce stride_alignment member into struct lsdc_chip_desc, the stride alignment is 256 bytes for ls7a1000, ls2k1000 and ls2k0500. But ls7a2000 improve it to 32 bytes, for extend the support for the device on coming. v5: 1) using writel and readl replace writeq and readq, to fix kernel test robot report build error on other archtecture 2) set default fb format to XRGB8888 at crtc reset time. 3) fix typos. v6: 1) Explain why we are not switch to drm dridge subsystem on ls2k1000. 2) Explain why tiny drm driver is not suitable for us. 3) Give a short description of the trival dirty uppdate implement based on CMA helper. 4) code clean up v7: 1) Remove select I2C_GPIO and I2C_LS2X in Kconfig, it is not ready now 2) Licensing issues are fixed suggested by Krzysztof Kozlowski. 3) lsdc_pixpll_print() is removed, part of it move to debugfs. 4) Set prefer_shadow to true if vram based driver is in using. 5) Replace double blank lines with single line in all files 6) Verbose cmd line parameter is replaced with drm_dbg() 7) All warnnings reported by ./scripts/checkpatch.pl --strict are fixed 8) Get edid from dtb support is removed as suggested by Maxime Ripard 9) Fix typos and various improvement Reported-by: Dan Carpenter Reported-by: Krzysztof Kozlowski Reported-by: Maxime Ripard Reported-by: Randy Dunlap Reported-by: kernel test robot Signed-off-by: suijingfeng Signed-off-by: Sui Jingfeng <15330273260@189.cn> --- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/lsdc/Kconfig | 39 ++ drivers/gpu/drm/lsdc/Makefile | 13 + drivers/gpu/drm/lsdc/lsdc_connector.c | 334 +++++++++++ drivers/gpu/drm/lsdc/lsdc_connector.h | 38 ++ drivers/gpu/drm/lsdc/lsdc_crtc.c | 341 +++++++++++ drivers/gpu/drm/lsdc/lsdc_drv.c | 776 ++++++++++++++++++++++++++ drivers/gpu/drm/lsdc/lsdc_drv.h | 217 +++++++ drivers/gpu/drm/lsdc/lsdc_encoder.c | 54 ++ drivers/gpu/drm/lsdc/lsdc_i2c.c | 198 +++++++ drivers/gpu/drm/lsdc/lsdc_i2c.h | 40 ++ drivers/gpu/drm/lsdc/lsdc_irq.c | 60 ++ drivers/gpu/drm/lsdc/lsdc_irq.h | 20 + drivers/gpu/drm/lsdc/lsdc_plane.c | 572 +++++++++++++++++++ drivers/gpu/drm/lsdc/lsdc_pll.c | 580 +++++++++++++++++++ drivers/gpu/drm/lsdc/lsdc_pll.h | 90 +++ drivers/gpu/drm/lsdc/lsdc_regs.h | 202 +++++++ 18 files changed, 3577 insertions(+) create mode 100644 drivers/gpu/drm/lsdc/Kconfig create mode 100644 drivers/gpu/drm/lsdc/Makefile create mode 100644 drivers/gpu/drm/lsdc/lsdc_connector.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_connector.h create mode 100644 drivers/gpu/drm/lsdc/lsdc_crtc.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_drv.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_drv.h create mode 100644 drivers/gpu/drm/lsdc/lsdc_encoder.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_i2c.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_i2c.h create mode 100644 drivers/gpu/drm/lsdc/lsdc_irq.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_irq.h create mode 100644 drivers/gpu/drm/lsdc/lsdc_plane.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_pll.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_pll.h create mode 100644 drivers/gpu/drm/lsdc/lsdc_regs.h diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index dfdd3ec5f793..18de1485e2ed 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -405,6 +405,8 @@ source "drivers/gpu/drm/gud/Kconfig" source "drivers/gpu/drm/sprd/Kconfig" +source "drivers/gpu/drm/lsdc/Kconfig" + config DRM_HYPERV tristate "DRM Support for Hyper-V synthetic video device" depends on DRM && PCI && MMU && HYPERV diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 8675c2af7ae1..2c5a76ced323 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -133,3 +133,4 @@ obj-y += xlnx/ obj-y += gud/ obj-$(CONFIG_DRM_HYPERV) += hyperv/ obj-$(CONFIG_DRM_SPRD) += sprd/ +obj-$(CONFIG_DRM_LSDC) += lsdc/ diff --git a/drivers/gpu/drm/lsdc/Kconfig b/drivers/gpu/drm/lsdc/Kconfig new file mode 100644 index 000000000000..30e976f4f0f7 --- /dev/null +++ b/drivers/gpu/drm/lsdc/Kconfig @@ -0,0 +1,39 @@ +# SPDX-License-Identifier: GPL-2.0 + +config DRM_LSDC + tristate "DRM Support for loongson's display controller" + depends on DRM && PCI + depends on MACH_LOONGSON64 || LOONGARCH || MIPS || COMPILE_TEST + select OF + select CMA if HAVE_DMA_CONTIGUOUS + select DMA_CMA if HAVE_DMA_CONTIGUOUS + select DRM_KMS_HELPER + select DRM_KMS_FB_HELPER + select DRM_GEM_CMA_HELPER + select VIDEOMODE_HELPERS + default m + help + This is a KMS driver for the display controller in the LS7A1000 + bridge chip and LS2K1000 SoC. The display controller has two + display pipes and it is a PCI device. + When using this driver on LS2K1000/LS2K0500 SoC, its framebuffer + is located at system memory. + If "M" is selected, the module will be called lsdc. + + If in doubt, say "Y". + +config DRM_LSDC_VRAM_DRIVER + bool "vram helper based device driver support" + depends on DRM_LSDC + select DRM_VRAM_HELPER + default y + help + The LS7A1000 bridge chip has dedicated video RAM, When using this + driver on LS7A1000 + LS3A3000/LS3A4000/LS3A5000 platform, the VRAM + helper based solution is intended to be use by default. Select this + option if you would like to encapsulate this driver mode. If you + don't select this option and/or append "lsdc.use_vram_helper=0" at + the kernel command line, Then, This driver mode will be disabled, + This driver will just fall back to CMA helper based mode. + + If in doubt, say "Y". diff --git a/drivers/gpu/drm/lsdc/Makefile b/drivers/gpu/drm/lsdc/Makefile new file mode 100644 index 000000000000..7472c4ed53ff --- /dev/null +++ b/drivers/gpu/drm/lsdc/Makefile @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0 + +lsdc-y := \ + lsdc_drv.o \ + lsdc_crtc.o \ + lsdc_irq.o \ + lsdc_plane.o \ + lsdc_pll.o \ + lsdc_i2c.o \ + lsdc_encoder.o \ + lsdc_connector.o + +obj-$(CONFIG_DRM_LSDC) += lsdc.o diff --git a/drivers/gpu/drm/lsdc/lsdc_connector.c b/drivers/gpu/drm/lsdc/lsdc_connector.c new file mode 100644 index 000000000000..00af6e270ebf --- /dev/null +++ b/drivers/gpu/drm/lsdc/lsdc_connector.c @@ -0,0 +1,334 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KMS driver for Loongson display controller + * + * Copyright (C) 2020-2022, Sui Jingfeng <15330273260@189.cn> + * + */ + +/* + * Authors: + * Sui Jingfeng + */ + +#include +#include +#include +#include +#include + +#include