From patchwork Wed Sep 16 18:14:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Anholt X-Patchwork-Id: 7198521 X-Patchwork-Delegate: agross@codeaurora.org Return-Path: X-Original-To: patchwork-linux-arm-msm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 70DD7BF036 for ; Wed, 16 Sep 2015 18:20:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F11C120868 for ; Wed, 16 Sep 2015 18:19:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D713C20859 for ; Wed, 16 Sep 2015 18:19:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753952AbbIPSTy (ORCPT ); Wed, 16 Sep 2015 14:19:54 -0400 Received: from gabe.freedesktop.org ([131.252.210.177]:37632 "EHLO gabe.freedesktop.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752565AbbIPSSi (ORCPT ); Wed, 16 Sep 2015 14:18:38 -0400 Received: from annarchy.freedesktop.org (annarchy.freedesktop.org [131.252.210.176]) by gabe.freedesktop.org (Postfix) with ESMTP id 77C036E4EB; Wed, 16 Sep 2015 11:18:37 -0700 (PDT) Received: from eliezer.anholt.net (annarchy.freedesktop.org [127.0.0.1]) by annarchy.freedesktop.org (Postfix) with ESMTP id 48223182E4; Wed, 16 Sep 2015 11:18:37 -0700 (PDT) Received: by eliezer.anholt.net (Postfix, from userid 1000) id 9ACF3F0066E; Wed, 16 Sep 2015 11:14:12 -0700 (PDT) From: Eric Anholt To: dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org, David Airlie , Inki Dae , Joonyoung Shim , Seung-Woo Kim , Kyungmin Park , linux-arm-msm@vger.kernel.org, Rob Clark , Eric Anholt Subject: [PATCH 1/4] drm: Put platform driver registration/unregistration loops in core. Date: Wed, 16 Sep 2015 14:14:07 -0400 Message-Id: <1442427250-9833-2-git-send-email-eric@anholt.net> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1442427250-9833-1-git-send-email-eric@anholt.net> References: <1442427250-9833-1-git-send-email-eric@anholt.net> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is mostly just a move of the code from exynos, with a slight reformat. I wanted to do a similar thing for vc4, and msm looks like a good candidate as well. Signed-off-by: Eric Anholt --- drivers/gpu/drm/Makefile | 3 ++- drivers/gpu/drm/drm_platform_helpers.c | 45 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/exynos/exynos_drm_drv.c | 38 +++++----------------------- include/drm/drmP.h | 4 +++ 4 files changed, 57 insertions(+), 33 deletions(-) create mode 100644 drivers/gpu/drm/drm_platform_helpers.c diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 45e7719..266d199 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -7,7 +7,8 @@ drm-y := drm_auth.o drm_bufs.o drm_cache.o \ drm_fops.o drm_gem.o drm_ioctl.o drm_irq.o \ drm_lock.o drm_memory.o drm_drv.o drm_vm.o \ drm_agpsupport.o drm_scatter.o drm_pci.o \ - drm_platform.o drm_sysfs.o drm_hashtab.o drm_mm.o \ + drm_platform.o drm_platform_helpers.o \ + drm_sysfs.o drm_hashtab.o drm_mm.o \ drm_crtc.o drm_modes.o drm_edid.o \ drm_info.o drm_debugfs.o drm_encoder_slave.o \ drm_trace_points.o drm_global.o drm_prime.o \ diff --git a/drivers/gpu/drm/drm_platform_helpers.c b/drivers/gpu/drm/drm_platform_helpers.c new file mode 100644 index 0000000..a54c3e3 --- /dev/null +++ b/drivers/gpu/drm/drm_platform_helpers.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + */ + +#include + +/** + * drm_platform_register_drivers - Helper to register an array of + * struct platform_drivers. + */ +int drm_platform_register_drivers(struct platform_driver *const *drv, + int count) +{ + int i, ret; + + for (i = 0; i < count; ++i) { + ret = platform_driver_register(drv[i]); + if (ret) { + while (--i >= 0) + platform_driver_unregister(drv[i]); + return ret; + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(drm_platform_register_drivers); + +/** + * drm_platform_unregister_drivers - Helper to unregister an array of + * struct platform_drivers (in the opposite order they would have been + * registered by drm_platform_register_drivers()). + */ +void drm_platform_unregister_drivers(struct platform_driver *const *drv, + int count) +{ + while (--count >= 0) + platform_driver_unregister(drv[count]); +} +EXPORT_SYMBOL_GPL(drm_platform_unregister_drivers); diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c index fa5194c..83f829b 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_drv.c +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c @@ -520,53 +520,27 @@ static int exynos_drm_register_devices(void) return 0; } -static void exynos_drm_unregister_drivers(struct platform_driver * const *drv, - int count) -{ - while (--count >= 0) - platform_driver_unregister(drv[count]); -} - -static int exynos_drm_register_drivers(struct platform_driver * const *drv, - int count) -{ - int i, ret; - - for (i = 0; i < count; ++i) { - ret = platform_driver_register(drv[i]); - if (!ret) - continue; - - while (--i >= 0) - platform_driver_unregister(drv[i]); - - return ret; - } - - return 0; -} - static inline int exynos_drm_register_kms_drivers(void) { - return exynos_drm_register_drivers(exynos_drm_kms_drivers, - ARRAY_SIZE(exynos_drm_kms_drivers)); + return drm_platform_register_drivers(exynos_drm_kms_drivers, + ARRAY_SIZE(exynos_drm_kms_drivers)); } static inline int exynos_drm_register_non_kms_drivers(void) { - return exynos_drm_register_drivers(exynos_drm_non_kms_drivers, - ARRAY_SIZE(exynos_drm_non_kms_drivers)); + return drm_platform_register_drivers(exynos_drm_non_kms_drivers, + ARRAY_SIZE(exynos_drm_non_kms_drivers)); } static inline void exynos_drm_unregister_kms_drivers(void) { - exynos_drm_unregister_drivers(exynos_drm_kms_drivers, + drm_platform_unregister_drivers(exynos_drm_kms_drivers, ARRAY_SIZE(exynos_drm_kms_drivers)); } static inline void exynos_drm_unregister_non_kms_drivers(void) { - exynos_drm_unregister_drivers(exynos_drm_non_kms_drivers, + drm_platform_unregister_drivers(exynos_drm_non_kms_drivers, ARRAY_SIZE(exynos_drm_non_kms_drivers)); } diff --git a/include/drm/drmP.h b/include/drm/drmP.h index 8b5ce7c..a774574 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -1087,6 +1087,10 @@ extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask); /* platform section */ extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device); extern int drm_platform_set_busid(struct drm_device *d, struct drm_master *m); +int drm_platform_register_drivers(struct platform_driver *const *drv, + int count); +void drm_platform_unregister_drivers(struct platform_driver *const *drv, + int count); /* returns true if currently okay to sleep */ static __inline__ bool drm_can_sleep(void)