Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1725677ybh; Fri, 13 Mar 2020 06:23:51 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtAcfZPatCyP8plLQmpTK/yV1QDltC5ar1AbxS33AXQAqKnkGg6SxVR8oIuR9mDhi/btLaK X-Received: by 2002:aca:7213:: with SMTP id p19mr6730727oic.44.1584105831038; Fri, 13 Mar 2020 06:23:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584105831; cv=none; d=google.com; s=arc-20160816; b=OM/zZHIWR06NlZmgEkoYl+mNRK5wNxTIpqt5tBY0jmy4jKeNnTOiWdlAYfBjplZDUL JrEfeX2HHnMZlWLO+ETyUQ5iAdigriUddp5zzE9FR9YvT2HFY30bMD4r4dl8Fb+Fai3r qMwsXwtw48G2OFQqkWbD88kg4gABiDMrhSHn0XBIQ+eyqBlNAjyY082Ec9tkFxneaakb +08M8MLaVOlMiliXrTS+9htjk3AHbQnIGPehavq26CONk/27ue+2CGh0aqEwhnntA/yJ pPeJlK3ATGikZlqvD734+kVFZ1V1zXj/3G7ROi8RKHKG/fNOaRFRzuin9Krb0H1NX7kN x1vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=6/dkHrk4+Y54pn3T4xbphw6p1RfZlO3W3eLRMonp144=; b=uFuGC3en4D/rnO6NJASjgbjEB/EZi3Pvykf+VmtaBXThcd59b/uoPV9ponu+1SN48w OenmR/nYkPzpa9Hr4GAtDL+fHR7k2N+TKuW0VTLNtnkD3PmAORaVXTd00CxGFll3MkEZ Gibj0k/2eVmtiMCNvDehd6cBeEfpcKV6ppqdQkLtLoUY3dRQ5IiTCM8exTgPdP+cSAfG lGKHN0SVsFpZUcV+gATb28SbI5HUIFRlcgCHyAstMtO/JjbsXnIV3hc6LIRmNz37Xdkp dgT1XU8ogD/7rG3DjrxcIUQM1M2MHeEaNaL9axvouxPPfRcvfJ8r08GdTo5+aRo5mPx9 UE2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IC7Xx9ew; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k22si4756521otn.272.2020.03.13.06.23.30; Fri, 13 Mar 2020 06:23:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IC7Xx9ew; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726733AbgCMNXF (ORCPT + 99 others); Fri, 13 Mar 2020 09:23:05 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:38118 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726526AbgCMNXF (ORCPT ); Fri, 13 Mar 2020 09:23:05 -0400 Received: by mail-pg1-f194.google.com with SMTP id x7so4993538pgh.5 for ; Fri, 13 Mar 2020 06:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6/dkHrk4+Y54pn3T4xbphw6p1RfZlO3W3eLRMonp144=; b=IC7Xx9ewIt/V0KM6SuO5NohLTsEnq5ZGyAdfL7/1dwmlkQO12ItWOs9kZPn7SbV9Ox nrQPtsv+4MCKRge/PwMfpWCWu3loesZC5V4v8QT7faBN44JJn+P8HNcSg+I2mxBOQ/je ADjBnG4IM4crvrp+Tm+GGibSZjEBYKlosxj30wl9iKPb1j4vzIBy4j7H5U5W5TWnLEpp JM+mbmHLrYDuBnv8FJer7NM2vufzJ09ShJj5q5xnZWbyusYWsMrCmam93GMVyvVR1wVJ y38ZOhPEZM+/0Peg8KhOBappNiRlFPBDObQCoWaWK6XTwOA4PaQC2u80+FpvK55f5OKh OYKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6/dkHrk4+Y54pn3T4xbphw6p1RfZlO3W3eLRMonp144=; b=VdasGs0H34peDQVoJhLU50vk8w4AeCsp7jE7E3MdSrF3rVZtengeSYdjvvZq2Sa/Qv 9Kg9AMnBXDOH2Otkeyeb2D6/lIY8ncZsKgDs0tlA0S1SI1sf21y1pBlcpOSm9s/nv78u koUa4Uw4q2RwbzW/nNiAKALPJQhOD53eF0NmKLfqcVPuZKLJXBE2P/cgK6+pt/Z2ToSX 9pCKlvGewTIx+mof9MPvYdsVezjYbUB5PGvRTrCJZo6Rw45how6ToXB5n/e2FCHSOhDi kGFj+GfRY9vR6jA/ft8NkncxrsaBUe3Qinra6emK1Q0tgFuB4TxNmx7RJ27UCfzSUZsM 65gg== X-Gm-Message-State: ANhLgQ1q0jR7D1THn3rGCFNtzYyaX1D035i/Kc+2kbGRzI9gu8M68l+O TJjY81g+BfKG9m1JpTGgyXM= X-Received: by 2002:a63:af53:: with SMTP id s19mr12759490pgo.175.1584105782492; Fri, 13 Mar 2020 06:23:02 -0700 (PDT) Received: from nj08008nbu.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id y9sm21490296pgo.80.2020.03.13.06.22.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Mar 2020 06:23:02 -0700 (PDT) From: Kevin Tang To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, sean@poorly.run, airlied@linux.ie, daniel@ffwll.ch, robh+dt@kernel.org, mark.rutland@arm.com, kevin3.tang@gmail.com Cc: orsonzhai@gmail.com, baolin.wang@linaro.org, zhang.lyra@gmail.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH RFC v5 2/6] drm/sprd: add Unisoc's drm kms master Date: Fri, 13 Mar 2020 21:22:43 +0800 Message-Id: <1584105767-11963-3-git-send-email-kevin3.tang@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1584105767-11963-1-git-send-email-kevin3.tang@gmail.com> References: <1584105767-11963-1-git-send-email-kevin3.tang@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: 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 internel peripherals through libdrm or libkms, it's test ok by modetest (DRM/KMS test tool) and Android HWComposer. Cc: Orson Zhai Cc: Baolin Wang Cc: Chunyan Zhang Signed-off-by: Kevin Tang --- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/sprd/Kconfig | 12 +++ drivers/gpu/drm/sprd/Makefile | 5 + drivers/gpu/drm/sprd/sprd_drm.c | 226 ++++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/sprd/sprd_drm.h | 16 +++ 6 files changed, 262 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 diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index d0aa6cf..ce76a4d 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -389,6 +389,8 @@ source "drivers/gpu/drm/aspeed/Kconfig" source "drivers/gpu/drm/mcde/Kconfig" +source "drivers/gpu/drm/sprd/Kconfig" + # Keep legacy drivers last menuconfig DRM_LEGACY diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 6493088..2178577 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -122,3 +122,4 @@ obj-$(CONFIG_DRM_LIMA) += lima/ obj-$(CONFIG_DRM_PANFROST) += panfrost/ obj-$(CONFIG_DRM_ASPEED_GFX) += aspeed/ obj-$(CONFIG_DRM_MCDE) += mcde/ +obj-$(CONFIG_DRM_SPRD) += sprd/ diff --git a/drivers/gpu/drm/sprd/Kconfig b/drivers/gpu/drm/sprd/Kconfig new file mode 100644 index 0000000..b189a54 --- /dev/null +++ b/drivers/gpu/drm/sprd/Kconfig @@ -0,0 +1,12 @@ +config DRM_SPRD + tristate "DRM Support for Unisoc SoCs Platform" + depends on ARCH_SPRD || COMPILE_TEST + depends on DRM && OF + select DRM_KMS_HELPER + select DRM_GEM_CMA_HELPER + select DRM_KMS_CMA_HELPER + select DRM_MIPI_DSI + help + Choose this option if you have a Unisoc chipsets. + If M is selected the module will be called sprd-drm. + diff --git a/drivers/gpu/drm/sprd/Makefile b/drivers/gpu/drm/sprd/Makefile new file mode 100644 index 0000000..86d95d9 --- /dev/null +++ b/drivers/gpu/drm/sprd/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +subdir-ccflags-y += -I$(srctree)/$(src) + +obj-y := sprd_drm.o diff --git a/drivers/gpu/drm/sprd/sprd_drm.c b/drivers/gpu/drm/sprd/sprd_drm.c new file mode 100644 index 0000000..4706185 --- /dev/null +++ b/drivers/gpu/drm/sprd/sprd_drm.c @@ -0,0 +1,226 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020 Unisoc Inc. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#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_init(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_VMAP_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 drm_device *drm; + struct sprd_drm *sprd; + int err; + + drm = drm_dev_alloc(&sprd_drm_drv, dev); + if (IS_ERR(drm)) + return PTR_ERR(drm); + + dev_set_drvdata(dev, drm); + + sprd = devm_kzalloc(drm->dev, sizeof(*sprd), GFP_KERNEL); + if (!sprd) + err = -ENOMEM; + + drm->dev_private = sprd; + + sprd_drm_mode_config_init(drm); + + /* bind and init sub drivers */ + err = component_bind_all(drm->dev, drm); + if (err) { + DRM_ERROR("failed to bind all component.\n"); + goto err_dc_cleanup; + } + + /* vblank init */ + err = drm_vblank_init(drm, drm->mode_config.num_crtc); + if (err) { + DRM_ERROR("failed to initialize vblank.\n"); + goto err_unbind_all; + } + /* with irq_enabled = true, we can use the vblank feature. */ + drm->irq_enabled = true; + + /* 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); + + err = drm_dev_register(drm, 0); + if (err < 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); +err_dc_cleanup: + drm_mode_config_cleanup(drm); + return err; +} + +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); + + drm_mode_config_cleanup(drm); + + component_unbind_all(drm->dev, drm); + drm->dev_private = NULL; + dev_set_drvdata(dev, NULL); + + drm_dev_put(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) +{ + int ret; + + ret = dma_set_mask_and_coherent(&pdev->dev, ~0); + if (ret) { + DRM_ERROR("dma_set_mask_and_coherent failed (%d)\n", ret); + return ret; + } + + 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 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) +{ + int ret; + + ret = platform_register_drivers(sprd_drm_drivers, + ARRAY_SIZE(sprd_drm_drivers)); + return ret; +} + +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 "); +MODULE_AUTHOR("Kevin Tang "); +MODULE_DESCRIPTION("Unisoc DRM KMS Master Driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/gpu/drm/sprd/sprd_drm.h b/drivers/gpu/drm/sprd/sprd_drm.h new file mode 100644 index 0000000..edf0881 --- /dev/null +++ b/drivers/gpu/drm/sprd/sprd_drm.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2020 Unisoc Inc. + */ + +#ifndef _SPRD_DRM_H_ +#define _SPRD_DRM_H_ + +#include +#include + +struct sprd_drm { + struct drm_device *drm; +}; + +#endif /* _SPRD_DRM_H_ */ -- 2.7.4