From patchwork Sat Jun 3 10:48:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 102820 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1586413vqr; Sat, 3 Jun 2023 03:57:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ErVa6NyCPnOQZc09o/4rpfLihNfMizAT7PrGSZaCqo3Z1kLtFoW2lHGxd1dRQ9GTORVbs X-Received: by 2002:a05:6a00:17a0:b0:64d:60f8:cb35 with SMTP id s32-20020a056a0017a000b0064d60f8cb35mr9313242pfg.7.1685789847874; Sat, 03 Jun 2023 03:57:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685789847; cv=none; d=google.com; s=arc-20160816; b=Q9TARKNyzLsrpxkVcP8Y3PoNQzmv824HO30lSCK+Y+debFeb03i+cBa2c4NcrhPn9q k01k7otAC3reWYRjkHqc6VZSzKL/dAQPO5WHy+H8Vf189otk09nWuHPttlVDnFnol+jB FvQ5D/gBccdvT5v1fRD2Iu5tWbkty9Pv2ma1/OCDqWbHR46ppZMcVZYrB4oK9OJ6iunU DbRT1cVH9RL4mRb2tY3Bjw08Lw7qM+f1izNqTB8qx6G6hxdwglps6WDGH8VJSuzauH/k 2YSftJJlbF/FxheWn/EH1m7kftf/4iWhO3Qa71Z/6/eaRh4sQiou2SlCT98rRS0ySs/X OxqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4j/71Z9OtbYjhzqbU7IeJdafy215Lb7b3MEEkA3Bruk=; b=DPCyv3QqUlPmbA5ExhYT532R0bCNtXoriuVCVJ80pwomZXHc+Nn9PswfI5W/mX4JWY KPwCWtVqeOEHeLIbi2OKlGKePYWveXoJmpkboSZqkgFxanRRtIX943tFm7b7of6wLLWa mQw4bYq05NYbEoula0UCyclRmg855FBLjqY7kowHyieinLuIa00VIRJTNlvvt7twJKrl 4fk+pDPXHyebAoqOq0Juh5ADj6O0neNBG7ALhU2bS3WCpq0Lp8ovLCM8f/hajJXOHNsZ vgfiikXueK3S8/480rYap/99snfNV9d5Uy/vceNSALO01gD0tD2psYMxP2m+txVyX1tm weKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 63-20020a630242000000b0052c3f0ae398si2547166pgc.158.2023.06.03.03.57.14; Sat, 03 Jun 2023 03:57:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232870AbjFCKtH (ORCPT + 99 others); Sat, 3 Jun 2023 06:49:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237010AbjFCKsy (ORCPT ); Sat, 3 Jun 2023 06:48:54 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 649291B3 for ; Sat, 3 Jun 2023 03:48:52 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8BxmPGTGntk6eoDAA--.8420S3; Sat, 03 Jun 2023 18:48:51 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx87SSGntkOjOHAA--.20866S5; Sat, 03 Jun 2023 18:48:51 +0800 (CST) From: Sui Jingfeng To: Lucas Stach , Christian Gmeiner , Daniel Vetter , Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn Subject: [PATCH v7 3/7] drm/etnaviv: add dedicated functions to create and destroy platform devices Date: Sat, 3 Jun 2023 18:48:46 +0800 Message-Id: <20230603104850.3042011-4-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230603104850.3042011-1-suijingfeng@loongson.cn> References: <20230603104850.3042011-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx87SSGntkOjOHAA--.20866S5 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxAr4ftrWxCr4xuFWkKFyxAFb_yoW5Gw4DpF 17GFWSyrW8uFW7Kw1xXwn8ZFW5C3WIg34F9rnFywnI9398Ar98XF95GFyUAFnxJrWrGa45 t39xtF48uF45ZrJanT9S1TB71UUUU07qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bvxYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JF0_JFyl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr1j6F4U JwAaw2AFwI0_GFv_Wryle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4 CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Gryq6s0DMcIj 6I8E87Iv67AKxVW8Jr0_Cr1UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrw ACjcxG6xCI17CEII8vrVW3JVW8Jr1lc7CjxVAaw2AFwI0_GFv_Wryl42xK82IYc2Ij64vI r41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_GFv_Wrylx2IqxVAqx4xG67 AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIY rxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_tr0E3s1lIxAIcVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4U JVWxJr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07 bGxRDUUUUU= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767678775716240541?= X-GMAIL-MSGID: =?utf-8?q?1767678775716240541?= Also rename the virtual master platform device as etnaviv_platform_device, for better reflection that it is a platform device, not a DRM device. Another benefit is that we no longer need to call of_node_put() for three different cases, Instead, we only need to call it once. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 56 +++++++++++++++++++-------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 31a7f59ccb49..cec005035d0e 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -656,12 +656,44 @@ static struct platform_driver etnaviv_platform_driver = { }, }; -static struct platform_device *etnaviv_drm; +static struct platform_device *etnaviv_platform_device; -static int __init etnaviv_init(void) +static int etnaviv_create_platform_device(const char *name, + struct platform_device **ppdev) { struct platform_device *pdev; int ret; + + pdev = platform_device_alloc(name, PLATFORM_DEVID_NONE); + if (!pdev) + return -ENOMEM; + + ret = platform_device_add(pdev); + if (ret) { + platform_device_put(pdev); + return ret; + } + + *ppdev = pdev; + + return 0; +} + +static void etnaviv_destroy_platform_device(struct platform_device **ppdev) +{ + struct platform_device *pdev = *ppdev; + + if (!pdev) + return; + + platform_device_unregister(pdev); + + *ppdev = NULL; +} + +static int __init etnaviv_init(void) +{ + int ret; struct device_node *np; etnaviv_validate_init(); @@ -681,23 +713,13 @@ static int __init etnaviv_init(void) for_each_compatible_node(np, NULL, "vivante,gc") { if (!of_device_is_available(np)) continue; + of_node_put(np); - pdev = platform_device_alloc("etnaviv", PLATFORM_DEVID_NONE); - if (!pdev) { - ret = -ENOMEM; - of_node_put(np); - goto unregister_platform_driver; - } - - ret = platform_device_add(pdev); - if (ret) { - platform_device_put(pdev); - of_node_put(np); + ret = etnaviv_create_platform_device("etnaviv", + &etnaviv_platform_device); + if (ret) goto unregister_platform_driver; - } - etnaviv_drm = pdev; - of_node_put(np); break; } @@ -713,7 +735,7 @@ module_init(etnaviv_init); static void __exit etnaviv_exit(void) { - platform_device_unregister(etnaviv_drm); + etnaviv_destroy_platform_device(&etnaviv_platform_device); platform_driver_unregister(&etnaviv_platform_driver); platform_driver_unregister(&etnaviv_gpu_driver); }