Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp306891pxb; Wed, 3 Feb 2021 06:11:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJytMQdeMzarpGfT9KlriBHKRrM5cVzbqNPPWn2ywtrelWUxpk0GX/p7gnyZdCRbZ34B/XpD X-Received: by 2002:aa7:dd49:: with SMTP id o9mr3105692edw.14.1612361483944; Wed, 03 Feb 2021 06:11:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612361483; cv=none; d=google.com; s=arc-20160816; b=vtIyJBp/swESZ99eBv23pHxZwnreVDAT1i3jOim1nqjKbOIdGknr87e+qVai4nG5um /pjiWj4iRaAEbD9S2l8X9zwEso/Fc0/MPCCLvnvZxo95vMU19yDk0pltaTBDp/TVLwRh 8iEpwDdh+kBsnBKj1RyzBHE3n+ulXEbjNxe/Jz7gWHnq+M4+yO1iULE+N5PgJtCY7f+8 0A2KN3gDZl5IwwdJTJM2np9bYUt4R48ND9LZVo42nttc05u4OEvKIUwnUGCnanLbUXAq SKgY4ET11e5IdyJQ9LoUvgBAuaAx49d+Q1+vjhjr/5VSai52mIemnRXUBnlQ4nMh6J73 0JGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=D+i0SDAVd/8+w4aaqzRc+qGBF/nnD/XV6wSALWGl1lA=; b=RgoMm5/sNjFiGJSXWQ2h8yVb/3kE8Tcdr7H9O/kqh0uJClPe8c63Hj+is0bAa0WmAO MrhdkEX2PTyurtY9U/aBWIJVOvM1QsG2OxwxRnuyK6bW1DOCYssuvs5pHWU6PgF3Zv7u VGpmHPZnJnEDgjYhLKba6LH6kJnHGxL0a2TrA/maKVc3+S36eiKa0HEQijmcLx4tYmY1 lgpH/g2yhTZJlARCdZm36z6hL8Uhuv40iX+xphvy324zcTenS4LTXkiJrRNQNNCeaokE QgUGDTF6aexk14w9AiuYzvmLPjFaH9VLPMVkyCuW9Dyb7MEE+XfrCpW9m/o8pLgzZ0Fj dc4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=Ewts+TIM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k20si1415603ejb.298.2021.02.03.06.10.43; Wed, 03 Feb 2021 06:11:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=Ewts+TIM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232653AbhBCOKI (ORCPT + 99 others); Wed, 3 Feb 2021 09:10:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232644AbhBCOJ5 (ORCPT ); Wed, 3 Feb 2021 09:09:57 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E047EC061573 for ; Wed, 3 Feb 2021 06:09:14 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id g10so24474806wrx.1 for ; Wed, 03 Feb 2021 06:09:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=D+i0SDAVd/8+w4aaqzRc+qGBF/nnD/XV6wSALWGl1lA=; b=Ewts+TIMfIiI1CJjP5REUP+Iv3rKL7F1fzJqmTjPLczWwFg0eNAuYOeDyiA0gnndUS bN0nEtwJod7Vqn/nqM3lvRFdsDdrgJjFjgwa45+KrL1T6R1ZlGaI39mHjc7WT82oJqUk IryWboywuqfw3s9eO6hSu49CNjNQWfHnfUsro= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=D+i0SDAVd/8+w4aaqzRc+qGBF/nnD/XV6wSALWGl1lA=; b=avomM1mR0XiefQOsfb1QyKMgVCI1b4PrjDp1N+8LqCchYha0QrhHk6sRSyWFdnbWmC fGyQMn02yj9ihgcc60M/DoyjPw//da0FExCsjoRGyY2CISuIKKMiuQWtEuCpcetrlGKW FCywY54CgI21qtMf83TZfovF1G5THOYFPZkgFU3AYh2liuvuQGFg/Ph0/s79BciHiguX 3i79LNjVjai1g2vxQoEO/5k6oR/ezTa73qqPAK4i5B7T/y9dsrMvIZ0Y3XvB/ygSSyGz RqbeJjOfSfOHixoRSR+0akkOX9y9WN1hqFscI39sAOnbkaHg1RPWKPmBQAMFPXdkjSap iciw== X-Gm-Message-State: AOAM530DLvBcdQC+xgtZv3ayLl+OTCFj1Ak+UpkaDc/lwIFZxxQD1jeO kbDlnANsSSIl7VPg6buHcnrF1w== X-Received: by 2002:adf:f7cf:: with SMTP id a15mr3762509wrq.351.1612361353644; Wed, 03 Feb 2021 06:09:13 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o124sm3030721wmb.5.2021.02.03.06.09.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 06:09:12 -0800 (PST) Date: Wed, 3 Feb 2021 15:09:10 +0100 From: Daniel Vetter To: Kevin Tang Cc: 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, orsonzhai@gmail.com, zhang.lyra@gmail.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org Subject: Re: [PATCH v3 2/6] drm/sprd: add Unisoc's drm kms master Message-ID: Mail-Followup-To: Kevin Tang , maarten.lankhorst@linux.intel.com, mripard@kernel.org, sean@poorly.run, airlied@linux.ie, robh+dt@kernel.org, mark.rutland@arm.com, orsonzhai@gmail.com, zhang.lyra@gmail.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org References: <1609854367-2720-1-git-send-email-kevin3.tang@gmail.com> <1609854367-2720-3-git-send-email-kevin3.tang@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1609854367-2720-3-git-send-email-kevin3.tang@gmail.com> X-Operating-System: Linux phenom 5.7.0-1-amd64 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 05, 2021 at 09:46:03PM +0800, Kevin Tang wrote: > 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: 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 | 222 ++++++++++++++++++++++++++++++++++++++++ > drivers/gpu/drm/sprd/sprd_drm.h | 16 +++ > 6 files changed, 258 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 147d61b..15b4e13 100644 > --- a/drivers/gpu/drm/Kconfig > +++ b/drivers/gpu/drm/Kconfig > @@ -388,6 +388,8 @@ source "drivers/gpu/drm/tidss/Kconfig" > > source "drivers/gpu/drm/xlnx/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 8156900..d3001e7 100644 > --- a/drivers/gpu/drm/Makefile > +++ b/drivers/gpu/drm/Makefile > @@ -124,3 +124,4 @@ obj-$(CONFIG_DRM_ASPEED_GFX) += aspeed/ > obj-$(CONFIG_DRM_MCDE) += mcde/ > obj-$(CONFIG_DRM_TIDSS) += tidss/ > obj-y += xlnx/ > +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..6e80cc9 > --- /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 chipset. > + 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..ec101de > --- /dev/null > +++ b/drivers/gpu/drm/sprd/sprd_drm.c > @@ -0,0 +1,222 @@ > +// 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.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 drm_device *drm = dev_get_drvdata(dev); > + int ret; > + > + 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"); > + goto err_dc_cleanup; > + } > + > + /* 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; > + } > + /* 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); > + > + 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); > +err_dc_cleanup: > + drm_mode_config_cleanup(drm); This shouldn't be needed with drmm_mode_config_cleanup. I think the trouble is that you have the drm_device setup split up between your probe and your bind function, you need to move the call to drmm_mode_config_init into you probe, or you move the devm_drm_dev_alloc and the entire setup into your master_ops->bind function. I think the latter is the more usual approach. With that addressed Acked-by: Daniel Vetter > + 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); > + > + drm_mode_config_cleanup(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) > +{ > + struct device *dev = &pdev->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; > + > + ret = dma_set_mask_and_coherent(dev, ~0UL); > + if (ret) { > + drm_err(drm, "dma_set_mask_and_coherent failed (%d)\n", ret); > + return ret; > + } > + > + platform_set_drvdata(pdev, drm); > + > + return drm_of_component_probe(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) > +{ > + 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..9781fd5 > --- /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 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch