From patchwork Sun Jan 30 06:04:12 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: 12729747 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 F3ABBC433EF for ; Sun, 30 Jan 2022 06:04:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1002310E8AE; Sun, 30 Jan 2022 06:04:31 +0000 (UTC) Received: from 189.cn (ptr.189.cn [183.61.185.103]) by gabe.freedesktop.org (Postfix) with ESMTP id 8668110E789 for ; Sun, 30 Jan 2022 06:04:23 +0000 (UTC) HMM_SOURCE_IP: 10.64.8.31:42436.1478280989 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.31]) by 189.cn (HERMES) with SMTP id AC540100208; Sun, 30 Jan 2022 14:04:21 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-b7fbf7d79-bwdqx with ESMTP id abf9b21fcb5b4b819ba7b20ec9778ed9 for l.stach@pengutronix.de; Sun, 30 Jan 2022 14:04:22 CST X-Transaction-ID: abf9b21fcb5b4b819ba7b20ec9778ed9 X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Maarten Lankhorst , Maxime Ripard , Roland Scheidegger , Zack Rusin , Christian Gmeiner , David Airlie , Daniel Vetter , Rob Herring , Thomas Bogendoerfer , Krzysztof Kozlowski , Andrey Zhizhikin , Sam Ravnborg , suijingfeng Subject: [PATCH v2 1/1] drm/lsdc: add drm driver for loongson display controller Date: Sun, 30 Jan 2022 14:04:12 +0800 Message-Id: <20220130060412.12100-2-15330273260@189.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220130060412.12100-1-15330273260@189.cn> References: <20220130060412.12100-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: linux-mips@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org 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, and the DC in those chip is a PCI device. This display controller have two display pipes but with only one hardware cursor. This display controller is uncommon outside of china, it don't have rich document either. This patch try to provided a minimal support for this display controller which is for graphic environment bring up. Hope the code can speak for itself. For ls7a1000, there are 4 gpios who register is located at dc register space which is used to emulation i2c. LS2K1000 and LS2K0500 SoC don't have those hardware, they use general purpose gpio or hardware i2c to serve this purpose. LS2K1000 is a double core 1.0Ghz mips64r2 compatible SoC[1]. LS7A1000 is a bridge chip made by Loongson corporation which act as north and/or south bridge of loongson's desktop and server level processor. It is equivalent to RS780E or something like that. More details can be read from its user manual[2]. This bridge chip is typically use with LS3A3000, LS3A4000 and LS3A5000 cpu. LS3A3000 is 4 core 1.45gHz mips64r2 compatible cpu. LS3A4000 is 4 core 1.8gHz mips64r5 compatible cpu. LS3A5000 is 4 core 2.5gHz loongarch cpu[3]. [1] https://wiki.debian.org/InstallingDebianOn/Lemote/Loongson2K1000 [2] https://loongson.github.io/LoongArch-Documentation/Loongson-7A1000-usermanual-EN.html [3] https://loongson.github.io/LoongArch-Documentation/Loongson-3A5000-usermanual-EN.html 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 | 38 ++ drivers/gpu/drm/lsdc/Makefile | 15 + drivers/gpu/drm/lsdc/lsdc_connector.c | 439 ++++++++++++++ drivers/gpu/drm/lsdc/lsdc_connector.h | 60 ++ drivers/gpu/drm/lsdc/lsdc_crtc.c | 438 ++++++++++++++ drivers/gpu/drm/lsdc/lsdc_drv.c | 824 ++++++++++++++++++++++++++ drivers/gpu/drm/lsdc/lsdc_drv.h | 214 +++++++ drivers/gpu/drm/lsdc/lsdc_encoder.c | 79 +++ drivers/gpu/drm/lsdc/lsdc_i2c.c | 220 +++++++ drivers/gpu/drm/lsdc/lsdc_i2c.h | 61 ++ drivers/gpu/drm/lsdc/lsdc_irq.c | 77 +++ drivers/gpu/drm/lsdc/lsdc_irq.h | 37 ++ drivers/gpu/drm/lsdc/lsdc_plane.c | 694 ++++++++++++++++++++++ drivers/gpu/drm/lsdc/lsdc_pll.c | 605 +++++++++++++++++++ drivers/gpu/drm/lsdc/lsdc_pll.h | 109 ++++ drivers/gpu/drm/lsdc/lsdc_regs.h | 242 ++++++++ 18 files changed, 4155 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..f470892ddf60 --- /dev/null +++ b/drivers/gpu/drm/lsdc/Kconfig @@ -0,0 +1,38 @@ +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 + select BACKLIGHT_PWM if CPU_LOONGSON2K + select I2C_GPIO if CPU_LOONGSON2K + select I2C_LS2X if CPU_LOONGSON2K + default m + help + This is a KMS driver for the display controller in the LS7A1000 + bridge chip and LS2K1000 SoC. The display controller have 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 + When using this driver on LS7A1000 + LS3A3000/LS3A4000/LS3A5000 + platform, the LS7A1000 bridge chip have dedicated video RAM. + Pass lsdc.use_vram_helper = 1 to the kernel cmd line will enable + this driver mode and then the framebuffer will located at the + VRAM at the price of losing PRIME support. + + 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..342990654478 --- /dev/null +++ b/drivers/gpu/drm/lsdc/Makefile @@ -0,0 +1,15 @@ +# +# Makefile for the lsdc drm device driver. +# + +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..7c527c62a3f0 --- /dev/null +++ b/drivers/gpu/drm/lsdc/lsdc_connector.c @@ -0,0 +1,439 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2020 Loongson Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ + +/* + * Authors: + * Sui Jingfeng + */ + +#include +#include +#include +#include +#include +#include + +#include