From patchwork Mon Jun 6 10:02:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 12870207 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 7AFF0C433EF for ; Mon, 6 Jun 2022 10:05:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SvbxAnHY8u+B0+ZCpkdepWO16nQ6+c5Q6ti0BO+6kNU=; b=jSiI2Il6b25PRw v7k7QMOemYC2WLgMCNqFXyV1XSmT0xSEkoiKuuwpbcymunOUeD8+MKp4vXQcJGh2MHk3Udgb9J/2w 6tL1cpzWQocY6MTCkY/HJf0WWXzBC5DXLV/4bM02Knn5isNmDhdjgv/iWFZxhi4X6JbMZx0gGOXNf ZJN9zZXu/PdIbsU2B7SJRdRzIiOSgznd2qiitNULsiHSdC1e8tvfx1YOQKMiLftf/gtyEIs59HTJd FwGfLP6CSjDKKXAx9qzEzXybU7K6s0oNjIBpr4CqIh3uYi24S+bGluWEzj75EfpING+CXEDduAMoy tfplKFzm3df1UmbWj65Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ny9az-000ang-FX; Mon, 06 Jun 2022 10:04:25 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ny9Zi-000aDD-Jl for linux-arm-kernel@lists.infradead.org; Mon, 06 Jun 2022 10:03:09 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3FC0F1596; Mon, 6 Jun 2022 03:03:05 -0700 (PDT) Received: from e120937-lin.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 32D023F66F; Mon, 6 Jun 2022 03:03:03 -0700 (PDT) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, Jonathan.Cameron@Huawei.com, f.fainelli@gmail.com, etienne.carriere@linaro.org, vincent.guittot@linaro.org, daniel.lezcano@linaro.org, tarek.el-sherbiny@arm.com, adrian.slatineanu@arm.com, souvik.chakravarty@arm.com, wleavitt@marvell.com, wbartczak@marvell.com, Cristian Marussi Subject: [PATCH v2 6/7] firmware: arm_scmi: Add scmi_driver optional setup/teardown callbacks Date: Mon, 6 Jun 2022 11:02:29 +0100 Message-Id: <20220606100230.3465828-7-cristian.marussi@arm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220606100230.3465828-1-cristian.marussi@arm.com> References: <20220606100230.3465828-1-cristian.marussi@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220606_030306_737022_EA26881D X-CRM114-Status: GOOD ( 12.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add optional .setup and .teardown methods to the scmi_driver descriptor: such callbacks, if provided, will be called by the SCIM core at driver registration time, so that, an SCMI driver, registered as usual with the module_scmi_driver() helper macro, can provide custom callbacks to be run once for all at module load/unload time to perform specific setup or teardown operations before/after .probe and .remove steps. Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/bus.c | 15 +++++++++++++-- include/linux/scmi_protocol.h | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c index f6fe723ab869..e95085a66bc4 100644 --- a/drivers/firmware/arm_scmi/bus.c +++ b/drivers/firmware/arm_scmi/bus.c @@ -132,12 +132,21 @@ int scmi_driver_register(struct scmi_driver *driver, struct module *owner, { int retval; - if (!driver->probe) + if (!driver->probe || !driver->id_table) return -EINVAL; + if (driver->setup) { + retval = driver->setup(); + if (retval) + return retval; + } + retval = scmi_protocol_device_request(driver->id_table); - if (retval) + if (retval) { + if (driver->teardown) + driver->teardown(); return retval; + } driver->driver.bus = &scmi_bus_type; driver->driver.name = driver->name; @@ -156,6 +165,8 @@ void scmi_driver_unregister(struct scmi_driver *driver) { driver_unregister(&driver->driver); scmi_protocol_device_unrequest(driver->id_table); + if (driver->teardown) + driver->teardown(); } EXPORT_SYMBOL_GPL(scmi_driver_unregister); diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h index 8ff81a5aa18f..ec550f23e2c8 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -804,6 +804,8 @@ struct scmi_device_id { struct scmi_driver { const char *name; + int (*setup)(void); + void (*teardown)(void); int (*probe)(struct scmi_device *sdev); void (*remove)(struct scmi_device *sdev); const struct scmi_device_id *id_table;