From patchwork Wed May 4 09:36:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 12837590 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 90ED2C433EF for ; Wed, 4 May 2022 09:53:35 +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=1JYOL0lG7CfVt5AB+xbXd/N6FIFHynf4bAlBndbPfQ0=; b=Y9AsJEzfvVyfCp cUSXPxJQoqthYuJqj7zZCcJPue80q+W/tlpdkfbpBtK7g9ma4Q3eRbYZp+KXRcuwyQF2CBVVptjy4 LyRtPO0juJkx2aCbaaHBvhMAFBNqzETU7XvDId57TT5n9Ty9niSce0nc9NcY1/YFn8T2Jwi9zO507 Tyn9Swhkcdf38DhmRvWnNkm6xeZ9eezESNoORszSCkSTTHP31CtOqdM83s0KdUd0IF9KR3eJYDu++ DVNZf+UsVwmoFIJgsMle3XZ7ociIWFRg4sDAaALYI74ZRxxXkzJ1O6+uAuA68QHcafGrGmnrvCyvq 9VOytNm9rgTSlfZKXUZg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nmBgN-00A4Fb-LM; Wed, 04 May 2022 09:52:31 +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 1nmBRD-009w7M-UL for linux-arm-kernel@lists.infradead.org; Wed, 04 May 2022 09:36:53 +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 85953153B; Wed, 4 May 2022 02:36:51 -0700 (PDT) Received: from e120937-lin.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EB6C13FA50; Wed, 4 May 2022 02:36:49 -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, vincent.guittot@linaro.org, daniel.lezcano@linaro.org, tarek.el-sherbiny@arm.com, adrian.slatineanu@arm.com, souvik.chakravarty@arm.com, Cristian Marussi Subject: [PATCH 6/7] firmware: arm_scmi: Add scmi_driver optional setup/teardown callbacks Date: Wed, 4 May 2022 10:36:08 +0100 Message-Id: <20220504093609.3077646-7-cristian.marussi@arm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220504093609.3077646-1-cristian.marussi@arm.com> References: <20220504093609.3077646-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-20220504_023652_071000_EBBFDEBA X-CRM114-Status: GOOD ( 12.23 ) 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 6f24715ca2fd..22728893959e 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -799,6 +799,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;