From patchwork Sun May 26 19:58:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13674401 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 D2B0CC25B75 for ; Sun, 26 May 2024 19:59:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7BEC310EA01; Sun, 26 May 2024 19:59:23 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.b="K5mU3L9P"; dkim-atps=neutral Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0D97410E4E0 for ; Sun, 26 May 2024 19:59:17 +0000 (UTC) X-Envelope-To: maarten.lankhorst@linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1716753556; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gt1GZxDNDVzPynPm2Fc/jjTcpRuD3aRfoyoaAWA9e3w=; b=K5mU3L9PDVN6Qiciorijzn+pS4JN/fokyXR+ka1VTpYo0plVLSwMop8iUnyDiFXqZxk0kx tV5Qsp4klcwmsGJi8LmuE8JQd9u1sgt5RMKgrU/KNdXVRjpNOb5h3dRxIbVC2eBhXLxBOm PG4V3/tOCefTN52+8w7InI7hFTPCyt4= X-Envelope-To: mripard@kernel.org X-Envelope-To: tzimmermann@suse.de X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: dri-devel@lists.freedesktop.org X-Envelope-To: markus.elfring@web.de X-Envelope-To: sui.jingfeng@linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Sui Jingfeng To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Markus Elfring , Sui Jingfeng Subject: [PATCH v2 1/3] drm/loongson: Add a helper for creating child devices Date: Mon, 27 May 2024 03:58:24 +0800 Message-Id: <20240526195826.109008-2-sui.jingfeng@linux.dev> In-Reply-To: <20240526195826.109008-1-sui.jingfeng@linux.dev> References: <20240526195826.109008-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In some display subsystems, the functionality of a PCIe device may too complex to be managed by a single driver. A split of the functionality into child devices can helpful to achieve better modularity. Another benefit is that we could migrate the dependency on exterinal modules to a submodule level with the helper created. For example, it's not uncommon that some exterinal module will return -EPROBE_DEFER to our driver during probe time. KMS driver has to tear down everything when it receives -EPROBE_DEFER, the problem is that it's completely not necessary and rising cyclic dependency problems if not process correctly. Add the loongson_create_platform_device() function, which allows the KMS driver to create sub-devices for it. The manually created decice acts as agents for the principal part, migrate the potential issue to submodule. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/loongson/loongson_device.c | 42 ++++++++++++++++++++++ drivers/gpu/drm/loongson/lsdc_drv.h | 6 ++++ 2 files changed, 48 insertions(+) diff --git a/drivers/gpu/drm/loongson/loongson_device.c b/drivers/gpu/drm/loongson/loongson_device.c index 9986c8a2a255..b268549d643e 100644 --- a/drivers/gpu/drm/loongson/loongson_device.c +++ b/drivers/gpu/drm/loongson/loongson_device.c @@ -4,6 +4,7 @@ */ #include +#include #include "lsdc_drv.h" @@ -100,3 +101,44 @@ lsdc_device_probe(struct pci_dev *pdev, enum loongson_chip_id chip_id) { return __chip_id_desc_table[chip_id]; } + +int loongson_create_platform_device(struct device *parent, + const char *name, int id, + struct resource *pres, + void *data, + struct platform_device **ppdev) +{ + struct platform_device *pdev; + int ret; + + pdev = platform_device_alloc(name, id); + if (!pdev) + return -ENOMEM; + + pdev->dev.parent = parent; + + if (pres) { + ret = platform_device_add_resources(pdev, pres, 1); + if (ret) { + platform_device_put(pdev); + return ret; + } + } + + if (data) { + void *pdata = kmalloc(sizeof(void *), GFP_KERNEL); + + *(void **)pdata = data; + pdev->dev.platform_data = pdata; + } + + ret = platform_device_add(pdev); + if (ret) { + platform_device_put(pdev); + return ret; + } + + *ppdev = pdev; + + return 0; +} diff --git a/drivers/gpu/drm/loongson/lsdc_drv.h b/drivers/gpu/drm/loongson/lsdc_drv.h index fbf2d760ef27..a2c6b496a69f 100644 --- a/drivers/gpu/drm/loongson/lsdc_drv.h +++ b/drivers/gpu/drm/loongson/lsdc_drv.h @@ -47,6 +47,12 @@ enum loongson_chip_id { const struct lsdc_desc * lsdc_device_probe(struct pci_dev *pdev, enum loongson_chip_id chip); +int loongson_create_platform_device(struct device *parent, + const char *name, int id, + struct resource *pres, + void *data, + struct platform_device **ppdev); + struct lsdc_kms_funcs; /* DC specific */ From patchwork Sun May 26 19:58:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13674402 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 C6D7EC25B75 for ; Sun, 26 May 2024 19:59:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1228610E8E6; Sun, 26 May 2024 19:59:29 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.b="ECKxfimC"; dkim-atps=neutral Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6585F10E8E6 for ; Sun, 26 May 2024 19:59:23 +0000 (UTC) X-Envelope-To: maarten.lankhorst@linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1716753561; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vxl1w9mtqDkyZD04DnulPgGkGBzNIZLutabN9Rr9Q2I=; b=ECKxfimC7g/ZqW3qDT1fTw+i95pPXZ3ApwmUE12jcwSN+pQVcrTbYObO6X/kGHZwejw7u7 S23u2UxIjRlVn4rgpmZOCc/+rNJFPAn5lsGmZRXAZGoGj7gf/MV8GdJyIA7fZhol89TZVc nUzo6udPtguG8JeZR0tsWG6enwuPDFo= X-Envelope-To: mripard@kernel.org X-Envelope-To: tzimmermann@suse.de X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: dri-devel@lists.freedesktop.org X-Envelope-To: markus.elfring@web.de X-Envelope-To: sui.jingfeng@linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Sui Jingfeng To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Markus Elfring , Sui Jingfeng Subject: [PATCH v2 2/3] drm/loongson: Introduce component framework support Date: Mon, 27 May 2024 03:58:25 +0800 Message-Id: <20240526195826.109008-3-sui.jingfeng@linux.dev> In-Reply-To: <20240526195826.109008-1-sui.jingfeng@linux.dev> References: <20240526195826.109008-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Hardware units come with PCIe are actually all ready to be driven, but there has some board specific modules could return '-EPROBE_DEFER'. However, the driver needs all of the subcompoments ready to use before it can register the drm service to userspace. Introduce the component framework to tackle such problems, move DRM device related code into loongson_drm_master_bind() function. Move output related things into subdriver. Display controller and GPIO-I2C goes with the PCIe master, sinch they has no dependency on exterinal modules. While the outputs drivers, such as encoders and conectors, may has some dependency on exterinal modules. Those hardware units are relatively independent hardware IPs from the CRTC. Hence, offload them to submodules. This design allows subdriver return '-EPROBE_DEFER' to the driver core if it need to do so, the master drvier won't bind until all submodules are ready. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/loongson/Makefile | 1 + drivers/gpu/drm/loongson/loongson_module.c | 17 +- drivers/gpu/drm/loongson/loongson_module.h | 1 + drivers/gpu/drm/loongson/lsdc_drv.c | 205 +++++++++++------- drivers/gpu/drm/loongson/lsdc_drv.h | 31 +-- drivers/gpu/drm/loongson/lsdc_i2c.c | 5 +- drivers/gpu/drm/loongson/lsdc_i2c.h | 3 - drivers/gpu/drm/loongson/lsdc_output.c | 176 +++++++++++++++ drivers/gpu/drm/loongson/lsdc_output.h | 38 +++- drivers/gpu/drm/loongson/lsdc_output_7a1000.c | 3 +- drivers/gpu/drm/loongson/lsdc_output_7a2000.c | 17 +- 11 files changed, 367 insertions(+), 130 deletions(-) create mode 100644 drivers/gpu/drm/loongson/lsdc_output.c diff --git a/drivers/gpu/drm/loongson/Makefile b/drivers/gpu/drm/loongson/Makefile index 91e72bd900c1..e15cb9bff378 100644 --- a/drivers/gpu/drm/loongson/Makefile +++ b/drivers/gpu/drm/loongson/Makefile @@ -9,6 +9,7 @@ loongson-y := \ lsdc_gfxpll.o \ lsdc_i2c.o \ lsdc_irq.o \ + lsdc_output.o \ lsdc_output_7a1000.o \ lsdc_output_7a2000.o \ lsdc_plane.o \ diff --git a/drivers/gpu/drm/loongson/loongson_module.c b/drivers/gpu/drm/loongson/loongson_module.c index d2a51bd395f6..037fa7ffe9c9 100644 --- a/drivers/gpu/drm/loongson/loongson_module.c +++ b/drivers/gpu/drm/loongson/loongson_module.c @@ -4,6 +4,7 @@ */ #include +#include #include