Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1313451rdb; Wed, 6 Dec 2023 15:18:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IGpHWfKMzivlK80qo0CTeWkwX35ogiwBi3I9oTdHxN7ie2XlZ4l5HI0wDfAWV0Pslhve9fN X-Received: by 2002:a17:902:d487:b0:1d0:b5aa:2ff6 with SMTP id c7-20020a170902d48700b001d0b5aa2ff6mr5395780plg.39.1701904705198; Wed, 06 Dec 2023 15:18:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701904705; cv=none; d=google.com; s=arc-20160816; b=pzAHcAfZPk+5d9qvworagZOl/e4ucJzvfwhWi6JDClViBhcbe8sai2hDG8TBYzwvsV ZTouhnufRBTYgA5MX2pii7DhzlQWdd4NmbvorWZkq/M4NcsnqGbzaSzEvMeYseTaAEUu I4Um3ch9Of9zluEYtUJkTFBvcUkrug2kDmYu+yCfbwbanTz0NWMxx5Fjf+zVizhzpdX4 KNRTP5R1l40FXob6SE/f4lZdxN1yBziWfiG65h3fxjXYt0tM3jb62DS3bwfy/jCGyBfV MdSNlzmlXoeRNcQr2n03BhtxGNu4CI7vQjsLYsZ9+cXf4eh+hpQi3qDypSx0Ev3Mme3w hJYg== 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 :dkim-signature; bh=9cQ0nnxRIAlLS0zsskkj4f3yF5uqECmSkWkegBz4IVM=; fh=fyWHa9Xga1kBSwfIj7Gdwg4R3yg35b+1QQ92cERVV+E=; b=ShpvwUVtAdRKxwnPBVAj0+CxYGZ8B5qHpBASuUmdYEmi2bBm6UncQLn/iwyfDH57LG BTIQvLOOzzqGCIEGMIdQItv2U5D2NOvXk2Dym1yC69nfsD3ypc1FOhnZuIgDWFLCz+a/ wDWuaEO8mcX7tl6k5x6nuddXdRIPUVJ7U75x7tQdqp80p5NFEa3zlQAzRC2jQCHyD9ym xqTck04j1uwj8Xj517aJk02vPeBqflv0hCh+jfV42qmqKgsKwxpRuRR4D+GXMGGPFyx1 yzUUibj3Y6K2tu9SVEiXM30vt3XK7OoE1thovNNea+wf0NJJZyIs1vr0WhtscNgyYkHX zByg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=k7IFO3ij; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id a20-20020a631a54000000b005bdd6196f4asi46624pgm.392.2023.12.06.15.18.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 15:18:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=k7IFO3ij; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id EB40A810EC11; Wed, 6 Dec 2023 15:18:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379681AbjLFXRh (ORCPT + 99 others); Wed, 6 Dec 2023 18:17:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377599AbjLFXRa (ORCPT ); Wed, 6 Dec 2023 18:17:30 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3FC2D68 for ; Wed, 6 Dec 2023 15:17:35 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 640CDC433C9; Wed, 6 Dec 2023 23:17:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701904655; bh=7tbd8uhNTKZSutzFMyZ5HgE6AjUYlNT/oHYwtf76HfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k7IFO3ijBVlBV1sBpidCG1KvAEhs/FdY5Cl7xJpD10CLO+aYXDeWcKeSrvgNEsGub 5Rf2cEYPNvyEyg1xhu0tcFKbiY6WiEdpOLgJ5uuJMuGrqK3Z8UknDEr3w8wDb+j8WL XYDK+HlHVZL1qWWFPJu2hOdIH0PGTE2aMbffeDl+gjoNgfuIRSsMugNvSDRwuGfDuq Pb9eWpGJihPNCWIKJ7oJVE7isSmV5M+HRtF86RKlabuNm5oT/54T5gliBPyPBWjW22 lUjU5PcNgGrMcZ/ZJb+BuTE7o0UFE/jN0pHNmX3szaYwXSTbfa7HKqG+uFFz7cpKtO VqsCXFYhMV7Sw== From: Stephen Boyd To: Greg Kroah-Hartman Cc: Fei Shao , linux-kernel@vger.kernel.org, patches@lists.linux.dev, AngeloGioacchino Del Regno Subject: [PATCH 3/8] spmi: Introduce device-managed functions Date: Wed, 6 Dec 2023 15:17:26 -0800 Message-ID: <20231206231733.4031901-4-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231206231733.4031901-1-sboyd@kernel.org> References: <20231206231733.4031901-1-sboyd@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 06 Dec 2023 15:18:22 -0800 (PST) From: Fei Shao Utilize the managed resource (devres) framework and add the following devm_* helpers for the SPMI driver: - devm_spmi_controller_alloc() - devm_spmi_controller_add() Signed-off-by: Fei Shao Link: https://lore.kernel.org/r/20230824104101.4083400-2-fshao@chromium.org Reviewed-by: AngeloGioacchino Del Regno [sboyd@kernel.org: Rename to spmi-devres for module niceness, slap on GPL module license] Signed-off-by: Stephen Boyd --- drivers/spmi/Makefile | 2 +- drivers/spmi/spmi-devres.c | 64 ++++++++++++++++++++++++++++++++++++++ include/linux/spmi.h | 3 ++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 drivers/spmi/spmi-devres.c diff --git a/drivers/spmi/Makefile b/drivers/spmi/Makefile index 9d974424c8c1..7f152167bb05 100644 --- a/drivers/spmi/Makefile +++ b/drivers/spmi/Makefile @@ -2,7 +2,7 @@ # # Makefile for kernel SPMI framework. # -obj-$(CONFIG_SPMI) += spmi.o +obj-$(CONFIG_SPMI) += spmi.o spmi-devres.o obj-$(CONFIG_SPMI_HISI3670) += hisi-spmi-controller.o obj-$(CONFIG_SPMI_MSM_PMIC_ARB) += spmi-pmic-arb.o diff --git a/drivers/spmi/spmi-devres.c b/drivers/spmi/spmi-devres.c new file mode 100644 index 000000000000..7683e6fdb18f --- /dev/null +++ b/drivers/spmi/spmi-devres.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2023 Google LLC. + */ + +#include +#include + +static void devm_spmi_controller_release(struct device *parent, void *res) +{ + spmi_controller_put(*(struct spmi_controller **)res); +} + +struct spmi_controller *devm_spmi_controller_alloc(struct device *parent, size_t size) +{ + struct spmi_controller **ptr, *ctrl; + + ptr = devres_alloc(devm_spmi_controller_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + ctrl = spmi_controller_alloc(parent, size); + if (!ctrl) { + devres_free(ptr); + return ERR_PTR(-ENOMEM); + } + + *ptr = ctrl; + devres_add(parent, ptr); + + return ctrl; +} +EXPORT_SYMBOL_GPL(devm_spmi_controller_alloc); + +static void devm_spmi_controller_remove(struct device *parent, void *res) +{ + spmi_controller_remove(*(struct spmi_controller **)res); +} + +int devm_spmi_controller_add(struct device *parent, struct spmi_controller *ctrl) +{ + struct spmi_controller **ptr; + int ret; + + ptr = devres_alloc(devm_spmi_controller_remove, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + ret = spmi_controller_add(ctrl); + if (ret) { + devres_free(ptr); + return ret; + } + + *ptr = ctrl; + devres_add(parent, ptr); + + return 0; + +} +EXPORT_SYMBOL_GPL(devm_spmi_controller_add); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("SPMI devres helpers"); diff --git a/include/linux/spmi.h b/include/linux/spmi.h index eac1956a8727..14597708fdbc 100644 --- a/include/linux/spmi.h +++ b/include/linux/spmi.h @@ -120,6 +120,9 @@ static inline void spmi_controller_put(struct spmi_controller *ctrl) int spmi_controller_add(struct spmi_controller *ctrl); void spmi_controller_remove(struct spmi_controller *ctrl); +struct spmi_controller *devm_spmi_controller_alloc(struct device *parent, size_t size); +int devm_spmi_controller_add(struct device *parent, struct spmi_controller *ctrl); + /** * struct spmi_driver - SPMI slave device driver * @driver: SPMI device drivers should initialize name and owner field of -- https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git/ https://git.kernel.org/pub/scm/linux/kernel/git/sboyd/spmi.git