From nobody Fri Nov 29 00:38:45 2024 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 909DF3A1BA for ; Wed, 25 Sep 2024 16:40:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727282432; cv=none; b=VruuP6EBV/qQTLLEbU9jocxroUHjqZpmmTHQGPY3mYG8+bqoVKLH1l0eCE3QG3z1OLCal9smpRXhXRqIiTNICuzY2VgMoPldfPOpGMfbgrMjURQbesbxHBcJcZDcTk8jNy8tj4gcwXpPoaNxMPEdXTpwyV4Plyap/UrVAQCC+E4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727282432; c=relaxed/simple; bh=jPjNGbJWuTeDP4URyPT30u3kbqgp/Drw74uZuvjdwl0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dPQhuLi97uNuTzpdLYGT4T5A0URtv99EUdJ0qeBEMNxzaAkfaXen7gAjQm6PFiVsKqtxzVrV2xf7ERh0HgPJvyIejChlm3hP2ItIk7HSB1pgKOResdov/kVWa0aF+jUHH10gubaTUGpLzlqR+CEp7puUIQHvmYonuW3qQeoC0tY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from dude05.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::54]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1stV3r-00046t-K0; Wed, 25 Sep 2024 18:40:19 +0200 From: Philipp Zabel Date: Wed, 25 Sep 2024 18:40:09 +0200 Subject: [PATCH v2 1/3] reset: replace boolean parameters with flags parameter Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240925-reset-get-deasserted-v2-1-b3601bbd0458@pengutronix.de> References: <20240925-reset-get-deasserted-v2-0-b3601bbd0458@pengutronix.de> In-Reply-To: <20240925-reset-get-deasserted-v2-0-b3601bbd0458@pengutronix.de> To: Kunihiko Hayashi , Masami Hiramatsu , Lad Prabhakar , Geert Uytterhoeven , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de, Philipp Zabel X-Mailer: b4 0.15-dev-13183 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::54 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Introduce enum reset_control_flags and replace the list of boolean parameters to the internal reset_control_get functions with a single flags parameter, before adding more boolean options. The separate boolean parameters have been shown to be error prone in the past. See for example commit a57f68ddc886 ("reset: Fix devm bulk optional exclusive control getter"). Signed-off-by: Philipp Zabel Acked-by: Uwe Kleine-K=C3=B6nig --- Changes in v2: - Clear RESET_CONTROL_FLAGS_BIT_OPTIONAL out of flags. - Check flags in __of_reset_control_get(). - Fix devm_reset_control_array_get() documentation. --- drivers/reset/core.c | 71 ++++++++++++---------- include/linux/reset.h | 161 +++++++++++++++++++++++++++++++---------------= ---- 2 files changed, 139 insertions(+), 93 deletions(-) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index 4d509d41456a..682d61812852 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -773,12 +773,19 @@ EXPORT_SYMBOL_GPL(reset_control_bulk_release); =20 static struct reset_control * __reset_control_get_internal(struct reset_controller_dev *rcdev, - unsigned int index, bool shared, bool acquired) + unsigned int index, enum reset_control_flags flags) { + bool shared =3D flags & RESET_CONTROL_FLAGS_BIT_SHARED; + bool acquired =3D flags & RESET_CONTROL_FLAGS_BIT_ACQUIRED; struct reset_control *rstc; =20 lockdep_assert_held(&reset_list_mutex); =20 + /* Expect callers to filter out OPTIONAL and DEASSERTED bits */ + if (WARN_ON(flags & ~(RESET_CONTROL_FLAGS_BIT_SHARED | + RESET_CONTROL_FLAGS_BIT_ACQUIRED))) + return ERR_PTR(-EINVAL); + list_for_each_entry(rstc, &rcdev->reset_control_head, list) { if (rstc->id =3D=3D index) { /* @@ -994,8 +1001,9 @@ static struct reset_controller_dev *__reset_find_rcdev= (const struct of_phandle_a =20 struct reset_control * __of_reset_control_get(struct device_node *node, const char *id, int index, - bool shared, bool optional, bool acquired) + enum reset_control_flags flags) { + bool optional =3D flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; bool gpio_fallback =3D false; struct reset_control *rstc; struct reset_controller_dev *rcdev; @@ -1059,8 +1067,10 @@ __of_reset_control_get(struct device_node *node, con= st char *id, int index, goto out_unlock; } =20 + flags &=3D ~RESET_CONTROL_FLAGS_BIT_OPTIONAL; + /* reset_list_mutex also protects the rcdev's reset_control list */ - rstc =3D __reset_control_get_internal(rcdev, rstc_id, shared, acquired); + rstc =3D __reset_control_get_internal(rcdev, rstc_id, flags); =20 out_unlock: mutex_unlock(&reset_list_mutex); @@ -1091,8 +1101,9 @@ __reset_controller_by_name(const char *name) =20 static struct reset_control * __reset_control_get_from_lookup(struct device *dev, const char *con_id, - bool shared, bool optional, bool acquired) + enum reset_control_flags flags) { + bool optional =3D flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; const struct reset_control_lookup *lookup; struct reset_controller_dev *rcdev; const char *dev_id =3D dev_name(dev); @@ -1116,9 +1127,11 @@ __reset_control_get_from_lookup(struct device *dev, = const char *con_id, return ERR_PTR(-EPROBE_DEFER); } =20 + flags &=3D ~RESET_CONTROL_FLAGS_BIT_OPTIONAL; + rstc =3D __reset_control_get_internal(rcdev, lookup->index, - shared, acquired); + flags); mutex_unlock(&reset_list_mutex); break; } @@ -1133,30 +1146,29 @@ __reset_control_get_from_lookup(struct device *dev,= const char *con_id, } =20 struct reset_control *__reset_control_get(struct device *dev, const char *= id, - int index, bool shared, bool optional, - bool acquired) + int index, enum reset_control_flags flags) { + bool shared =3D flags & RESET_CONTROL_FLAGS_BIT_SHARED; + bool acquired =3D flags & RESET_CONTROL_FLAGS_BIT_ACQUIRED; + if (WARN_ON(shared && acquired)) return ERR_PTR(-EINVAL); =20 if (dev->of_node) - return __of_reset_control_get(dev->of_node, id, index, shared, - optional, acquired); + return __of_reset_control_get(dev->of_node, id, index, flags); =20 - return __reset_control_get_from_lookup(dev, id, shared, optional, - acquired); + return __reset_control_get_from_lookup(dev, id, flags); } EXPORT_SYMBOL_GPL(__reset_control_get); =20 int __reset_control_bulk_get(struct device *dev, int num_rstcs, struct reset_control_bulk_data *rstcs, - bool shared, bool optional, bool acquired) + enum reset_control_flags flags) { int ret, i; =20 for (i =3D 0; i < num_rstcs; i++) { - rstcs[i].rstc =3D __reset_control_get(dev, rstcs[i].id, 0, - shared, optional, acquired); + rstcs[i].rstc =3D __reset_control_get(dev, rstcs[i].id, 0, flags); if (IS_ERR(rstcs[i].rstc)) { ret =3D PTR_ERR(rstcs[i].rstc); goto err; @@ -1226,7 +1238,7 @@ static void devm_reset_control_release(struct device = *dev, void *res) =20 struct reset_control * __devm_reset_control_get(struct device *dev, const char *id, int index, - bool shared, bool optional, bool acquired) + enum reset_control_flags flags) { struct reset_control **ptr, *rstc; =20 @@ -1235,7 +1247,7 @@ __devm_reset_control_get(struct device *dev, const ch= ar *id, int index, if (!ptr) return ERR_PTR(-ENOMEM); =20 - rstc =3D __reset_control_get(dev, id, index, shared, optional, acquired); + rstc =3D __reset_control_get(dev, id, index, flags); if (IS_ERR_OR_NULL(rstc)) { devres_free(ptr); return rstc; @@ -1262,7 +1274,7 @@ static void devm_reset_control_bulk_release(struct de= vice *dev, void *res) =20 int __devm_reset_control_bulk_get(struct device *dev, int num_rstcs, struct reset_control_bulk_data *rstcs, - bool shared, bool optional, bool acquired) + enum reset_control_flags flags) { struct reset_control_bulk_devres *ptr; int ret; @@ -1272,7 +1284,7 @@ int __devm_reset_control_bulk_get(struct device *dev,= int num_rstcs, if (!ptr) return -ENOMEM; =20 - ret =3D __reset_control_bulk_get(dev, num_rstcs, rstcs, shared, optional,= acquired); + ret =3D __reset_control_bulk_get(dev, num_rstcs, rstcs, flags); if (ret < 0) { devres_free(ptr); return ret; @@ -1298,6 +1310,7 @@ EXPORT_SYMBOL_GPL(__devm_reset_control_bulk_get); */ int __device_reset(struct device *dev, bool optional) { + enum reset_control_flags flags; struct reset_control *rstc; int ret; =20 @@ -1313,7 +1326,8 @@ int __device_reset(struct device *dev, bool optional) } #endif =20 - rstc =3D __reset_control_get(dev, NULL, 0, 0, optional, true); + flags =3D optional ? RESET_CONTROL_OPTIONAL_EXCLUSIVE : RESET_CONTROL_EXC= LUSIVE; + rstc =3D __reset_control_get(dev, NULL, 0, flags); if (IS_ERR(rstc)) return PTR_ERR(rstc); =20 @@ -1356,17 +1370,14 @@ static int of_reset_control_get_count(struct device= _node *node) * device node. * * @np: device node for the device that requests the reset controls array - * @shared: whether reset controls are shared or not - * @optional: whether it is optional to get the reset controls - * @acquired: only one reset control may be acquired for a given controller - * and ID + * @flags: whether reset controls are shared, optional, acquired * * Returns pointer to allocated reset_control on success or error on failu= re */ struct reset_control * -of_reset_control_array_get(struct device_node *np, bool shared, bool optio= nal, - bool acquired) +of_reset_control_array_get(struct device_node *np, enum reset_control_flag= s flags) { + bool optional =3D flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; struct reset_control_array *resets; struct reset_control *rstc; int num, i; @@ -1381,8 +1392,7 @@ of_reset_control_array_get(struct device_node *np, bo= ol shared, bool optional, resets->num_rstcs =3D num; =20 for (i =3D 0; i < num; i++) { - rstc =3D __of_reset_control_get(np, NULL, i, shared, optional, - acquired); + rstc =3D __of_reset_control_get(np, NULL, i, flags); if (IS_ERR(rstc)) goto err_rst; resets->rstc[i] =3D rstc; @@ -1407,8 +1417,7 @@ EXPORT_SYMBOL_GPL(of_reset_control_array_get); * devm_reset_control_array_get - Resource managed reset control array get * * @dev: device that requests the list of reset controls - * @shared: whether reset controls are shared or not - * @optional: whether it is optional to get the reset controls + * @flags: whether reset controls are shared, optional, acquired * * The reset control array APIs are intended for a list of resets * that just have to be asserted or deasserted, without any @@ -1417,7 +1426,7 @@ EXPORT_SYMBOL_GPL(of_reset_control_array_get); * Returns pointer to allocated reset_control on success or error on failu= re */ struct reset_control * -devm_reset_control_array_get(struct device *dev, bool shared, bool optiona= l) +devm_reset_control_array_get(struct device *dev, enum reset_control_flags = flags) { struct reset_control **ptr, *rstc; =20 @@ -1426,7 +1435,7 @@ devm_reset_control_array_get(struct device *dev, bool= shared, bool optional) if (!ptr) return ERR_PTR(-ENOMEM); =20 - rstc =3D of_reset_control_array_get(dev->of_node, shared, optional, true); + rstc =3D of_reset_control_array_get(dev->of_node, flags); if (IS_ERR_OR_NULL(rstc)) { devres_free(ptr); return rstc; diff --git a/include/linux/reset.h b/include/linux/reset.h index 514ddf003efc..99296af98f81 100644 --- a/include/linux/reset.h +++ b/include/linux/reset.h @@ -25,6 +25,33 @@ struct reset_control_bulk_data { struct reset_control *rstc; }; =20 +#define RESET_CONTROL_FLAGS_BIT_SHARED BIT(0) /* not exclusive */ +#define RESET_CONTROL_FLAGS_BIT_OPTIONAL BIT(1) +#define RESET_CONTROL_FLAGS_BIT_ACQUIRED BIT(2) /* iff exclusive, not rele= ased */ + +/** + * enum reset_control_flags - Flags that can be passed to the reset_contro= l_get functions + * to determine the type of reset control. + * These values cannot be OR'd. + * + * @RESET_CONTROL_EXCLUSIVE: exclusive, acquired, + * @RESET_CONTROL_EXCLUSIVE_RELEASED: exclusive, released, + * @RESET_CONTROL_SHARED: shared + * @RESET_CONTROL_OPTIONAL_EXCLUSIVE: optional, exclusive, acquired + * @RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED: optional, exclusive, relea= sed + * @RESET_CONTROL_OPTIONAL_SHARED: optional, shared + */ +enum reset_control_flags { + RESET_CONTROL_EXCLUSIVE =3D RESET_CONTROL_FLAGS_BIT_ACQUIRED, + RESET_CONTROL_EXCLUSIVE_RELEASED =3D 0, + RESET_CONTROL_SHARED =3D RESET_CONTROL_FLAGS_BIT_SHARED, + RESET_CONTROL_OPTIONAL_EXCLUSIVE =3D RESET_CONTROL_FLAGS_BIT_OPTIONAL | + RESET_CONTROL_FLAGS_BIT_ACQUIRED, + RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED =3D RESET_CONTROL_FLAGS_BIT_OPT= IONAL, + RESET_CONTROL_OPTIONAL_SHARED =3D RESET_CONTROL_FLAGS_BIT_OPTIONAL | + RESET_CONTROL_FLAGS_BIT_SHARED, +}; + #ifdef CONFIG_RESET_CONTROLLER =20 int reset_control_reset(struct reset_control *rstc); @@ -42,30 +69,25 @@ int reset_control_bulk_acquire(int num_rstcs, struct re= set_control_bulk_data *rs void reset_control_bulk_release(int num_rstcs, struct reset_control_bulk_d= ata *rstcs); =20 struct reset_control *__of_reset_control_get(struct device_node *node, - const char *id, int index, bool shared, - bool optional, bool acquired); + const char *id, int index, enum reset_control_flags flags); struct reset_control *__reset_control_get(struct device *dev, const char *= id, - int index, bool shared, - bool optional, bool acquired); + int index, enum reset_control_flags flags); void reset_control_put(struct reset_control *rstc); int __reset_control_bulk_get(struct device *dev, int num_rstcs, struct reset_control_bulk_data *rstcs, - bool shared, bool optional, bool acquired); + enum reset_control_flags flags); void reset_control_bulk_put(int num_rstcs, struct reset_control_bulk_data = *rstcs); =20 int __device_reset(struct device *dev, bool optional); struct reset_control *__devm_reset_control_get(struct device *dev, - const char *id, int index, bool shared, - bool optional, bool acquired); + const char *id, int index, enum reset_control_flags flags); int __devm_reset_control_bulk_get(struct device *dev, int num_rstcs, struct reset_control_bulk_data *rstcs, - bool shared, bool optional, bool acquired); + enum reset_control_flags flags); =20 struct reset_control *devm_reset_control_array_get(struct device *dev, - bool shared, bool optional); -struct reset_control *of_reset_control_array_get(struct device_node *np, - bool shared, bool optional, - bool acquired); + enum reset_control_flags flags); +struct reset_control *of_reset_control_array_get(struct device_node *np, e= num reset_control_flags); =20 int reset_control_get_count(struct device *dev); =20 @@ -116,17 +138,19 @@ static inline int __device_reset(struct device *dev, = bool optional) =20 static inline struct reset_control *__of_reset_control_get( struct device_node *node, - const char *id, int index, bool shared, - bool optional, bool acquired) + const char *id, int index, enum reset_control_flags flags) { + bool optional =3D flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; + return optional ? NULL : ERR_PTR(-ENOTSUPP); } =20 static inline struct reset_control *__reset_control_get( struct device *dev, const char *id, - int index, bool shared, bool optional, - bool acquired) + int index, enum reset_control_flags flags) { + bool optional =3D flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; + return optional ? NULL : ERR_PTR(-ENOTSUPP); } =20 @@ -162,8 +186,10 @@ reset_control_bulk_release(int num_rstcs, struct reset= _control_bulk_data *rstcs) static inline int __reset_control_bulk_get(struct device *dev, int num_rstcs, struct reset_control_bulk_data *rstcs, - bool shared, bool optional, bool acquired) + enum reset_control_flags flags) { + bool optional =3D flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; + return optional ? 0 : -EOPNOTSUPP; } =20 @@ -174,30 +200,36 @@ reset_control_bulk_put(int num_rstcs, struct reset_co= ntrol_bulk_data *rstcs) =20 static inline struct reset_control *__devm_reset_control_get( struct device *dev, const char *id, - int index, bool shared, bool optional, - bool acquired) + int index, enum reset_control_flags flags) { + bool optional =3D flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; + return optional ? NULL : ERR_PTR(-ENOTSUPP); } =20 static inline int __devm_reset_control_bulk_get(struct device *dev, int num_rstcs, struct reset_control_bulk_data *rstcs, - bool shared, bool optional, bool acquired) + enum reset_control_flags flags) { + bool optional =3D flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; + return optional ? 0 : -EOPNOTSUPP; } =20 static inline struct reset_control * -devm_reset_control_array_get(struct device *dev, bool shared, bool optiona= l) +devm_reset_control_array_get(struct device *dev, enum reset_control_flags = flags) { + bool optional =3D flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; + return optional ? NULL : ERR_PTR(-ENOTSUPP); } =20 static inline struct reset_control * -of_reset_control_array_get(struct device_node *np, bool shared, bool optio= nal, - bool acquired) +of_reset_control_array_get(struct device_node *np, enum reset_control_flag= s flags) { + bool optional =3D flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; + return optional ? NULL : ERR_PTR(-ENOTSUPP); } =20 @@ -236,7 +268,7 @@ static inline int device_reset_optional(struct device *= dev) static inline struct reset_control * __must_check reset_control_get_exclusive(struct device *dev, const char *i= d) { - return __reset_control_get(dev, id, 0, false, false, true); + return __reset_control_get(dev, id, 0, RESET_CONTROL_EXCLUSIVE); } =20 /** @@ -253,7 +285,7 @@ static inline int __must_check reset_control_bulk_get_exclusive(struct device *dev, int num_rstcs, struct reset_control_bulk_data *rstcs) { - return __reset_control_bulk_get(dev, num_rstcs, rstcs, false, false, true= ); + return __reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_EXCL= USIVE); } =20 /** @@ -274,7 +306,7 @@ static inline struct reset_control * __must_check reset_control_get_exclusive_released(struct device *dev, const char *id) { - return __reset_control_get(dev, id, 0, false, false, false); + return __reset_control_get(dev, id, 0, RESET_CONTROL_EXCLUSIVE_RELEASED); } =20 /** @@ -295,7 +327,7 @@ static inline int __must_check reset_control_bulk_get_exclusive_released(struct device *dev, int num_rstc= s, struct reset_control_bulk_data *rstcs) { - return __reset_control_bulk_get(dev, num_rstcs, rstcs, false, false, fals= e); + return __reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_EXCL= USIVE_RELEASED); } =20 /** @@ -316,7 +348,8 @@ static inline int __must_check reset_control_bulk_get_optional_exclusive_released(struct device *dev, int= num_rstcs, struct reset_control_bulk_data *rstcs) { - return __reset_control_bulk_get(dev, num_rstcs, rstcs, false, true, false= ); + return __reset_control_bulk_get(dev, num_rstcs, rstcs, + RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED); } =20 /** @@ -344,7 +377,7 @@ reset_control_bulk_get_optional_exclusive_released(stru= ct device *dev, int num_r static inline struct reset_control *reset_control_get_shared( struct device *dev, const char *id) { - return __reset_control_get(dev, id, 0, true, false, false); + return __reset_control_get(dev, id, 0, RESET_CONTROL_SHARED); } =20 /** @@ -361,7 +394,7 @@ static inline int __must_check reset_control_bulk_get_shared(struct device *dev, int num_rstcs, struct reset_control_bulk_data *rstcs) { - return __reset_control_bulk_get(dev, num_rstcs, rstcs, true, false, false= ); + return __reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_SHAR= ED); } =20 /** @@ -378,7 +411,7 @@ reset_control_bulk_get_shared(struct device *dev, int n= um_rstcs, static inline struct reset_control *reset_control_get_optional_exclusive( struct device *dev, const char *id) { - return __reset_control_get(dev, id, 0, false, true, true); + return __reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_EXCLUSIVE); } =20 /** @@ -398,7 +431,7 @@ static inline int __must_check reset_control_bulk_get_optional_exclusive(struct device *dev, int num_rstc= s, struct reset_control_bulk_data *rstcs) { - return __reset_control_bulk_get(dev, num_rstcs, rstcs, false, true, true); + return __reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_OPTI= ONAL_EXCLUSIVE); } =20 /** @@ -415,7 +448,7 @@ reset_control_bulk_get_optional_exclusive(struct device= *dev, int num_rstcs, static inline struct reset_control *reset_control_get_optional_shared( struct device *dev, const char *id) { - return __reset_control_get(dev, id, 0, true, true, false); + return __reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_SHARED); } =20 /** @@ -435,7 +468,7 @@ static inline int __must_check reset_control_bulk_get_optional_shared(struct device *dev, int num_rstcs, struct reset_control_bulk_data *rstcs) { - return __reset_control_bulk_get(dev, num_rstcs, rstcs, true, true, false); + return __reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_OPTI= ONAL_SHARED); } =20 /** @@ -451,7 +484,7 @@ reset_control_bulk_get_optional_shared(struct device *d= ev, int num_rstcs, static inline struct reset_control *of_reset_control_get_exclusive( struct device_node *node, const char *id) { - return __of_reset_control_get(node, id, 0, false, false, true); + return __of_reset_control_get(node, id, 0, RESET_CONTROL_EXCLUSIVE); } =20 /** @@ -471,7 +504,7 @@ static inline struct reset_control *of_reset_control_ge= t_exclusive( static inline struct reset_control *of_reset_control_get_optional_exclusiv= e( struct device_node *node, const char *id) { - return __of_reset_control_get(node, id, 0, false, true, true); + return __of_reset_control_get(node, id, 0, RESET_CONTROL_OPTIONAL_EXCLUSI= VE); } =20 /** @@ -496,7 +529,7 @@ static inline struct reset_control *of_reset_control_ge= t_optional_exclusive( static inline struct reset_control *of_reset_control_get_shared( struct device_node *node, const char *id) { - return __of_reset_control_get(node, id, 0, true, false, false); + return __of_reset_control_get(node, id, 0, RESET_CONTROL_SHARED); } =20 /** @@ -513,7 +546,7 @@ static inline struct reset_control *of_reset_control_ge= t_shared( static inline struct reset_control *of_reset_control_get_exclusive_by_inde= x( struct device_node *node, int index) { - return __of_reset_control_get(node, NULL, index, false, false, true); + return __of_reset_control_get(node, NULL, index, RESET_CONTROL_EXCLUSIVE); } =20 /** @@ -541,7 +574,7 @@ static inline struct reset_control *of_reset_control_ge= t_exclusive_by_index( static inline struct reset_control *of_reset_control_get_shared_by_index( struct device_node *node, int index) { - return __of_reset_control_get(node, NULL, index, true, false, false); + return __of_reset_control_get(node, NULL, index, RESET_CONTROL_SHARED); } =20 /** @@ -560,7 +593,7 @@ static inline struct reset_control * __must_check devm_reset_control_get_exclusive(struct device *dev, const char *id) { - return __devm_reset_control_get(dev, id, 0, false, false, true); + return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_EXCLUSIVE); } =20 /** @@ -580,7 +613,8 @@ static inline int __must_check devm_reset_control_bulk_get_exclusive(struct device *dev, int num_rstcs, struct reset_control_bulk_data *rstcs) { - return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, false, false,= true); + return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, + RESET_CONTROL_EXCLUSIVE); } =20 /** @@ -599,7 +633,7 @@ static inline struct reset_control * __must_check devm_reset_control_get_exclusive_released(struct device *dev, const char *id) { - return __devm_reset_control_get(dev, id, 0, false, false, false); + return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_EXCLUSIVE_RELEA= SED); } =20 /** @@ -619,7 +653,8 @@ static inline int __must_check devm_reset_control_bulk_get_exclusive_released(struct device *dev, int num= _rstcs, struct reset_control_bulk_data *rstcs) { - return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, false, false,= false); + return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, + RESET_CONTROL_EXCLUSIVE_RELEASED); } =20 /** @@ -638,7 +673,7 @@ static inline struct reset_control * __must_check devm_reset_control_get_optional_exclusive_released(struct dev= ice *dev, const char *id) { - return __devm_reset_control_get(dev, id, 0, false, true, false); + return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_EXCLUS= IVE_RELEASED); } =20 /** @@ -658,7 +693,8 @@ static inline int __must_check devm_reset_control_bulk_get_optional_exclusive_released(struct device *dev= , int num_rstcs, struct reset_control_bulk_data *rstcs) { - return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, false, true, = false); + return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, + RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED); } =20 /** @@ -673,7 +709,7 @@ devm_reset_control_bulk_get_optional_exclusive_released= (struct device *dev, int static inline struct reset_control *devm_reset_control_get_shared( struct device *dev, const char *id) { - return __devm_reset_control_get(dev, id, 0, true, false, false); + return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_SHARED); } =20 /** @@ -693,7 +729,7 @@ static inline int __must_check devm_reset_control_bulk_get_shared(struct device *dev, int num_rstcs, struct reset_control_bulk_data *rstcs) { - return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, true, false, = false); + return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL= _SHARED); } =20 /** @@ -711,7 +747,7 @@ devm_reset_control_bulk_get_shared(struct device *dev, = int num_rstcs, static inline struct reset_control *devm_reset_control_get_optional_exclus= ive( struct device *dev, const char *id) { - return __devm_reset_control_get(dev, id, 0, false, true, true); + return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_EXCLUS= IVE); } =20 /** @@ -731,7 +767,8 @@ static inline int __must_check devm_reset_control_bulk_get_optional_exclusive(struct device *dev, int num= _rstcs, struct reset_control_bulk_data *rstcs) { - return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, false, true, = true); + return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, + RESET_CONTROL_OPTIONAL_EXCLUSIVE); } =20 /** @@ -749,7 +786,7 @@ devm_reset_control_bulk_get_optional_exclusive(struct d= evice *dev, int num_rstcs static inline struct reset_control *devm_reset_control_get_optional_shared( struct device *dev, const char *id) { - return __devm_reset_control_get(dev, id, 0, true, true, false); + return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_SHARED= ); } =20 /** @@ -769,7 +806,7 @@ static inline int __must_check devm_reset_control_bulk_get_optional_shared(struct device *dev, int num_rs= tcs, struct reset_control_bulk_data *rstcs) { - return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, true, true, f= alse); + return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL= _OPTIONAL_SHARED); } =20 /** @@ -787,7 +824,7 @@ devm_reset_control_bulk_get_optional_shared(struct devi= ce *dev, int num_rstcs, static inline struct reset_control * devm_reset_control_get_exclusive_by_index(struct device *dev, int index) { - return __devm_reset_control_get(dev, NULL, index, false, false, true); + return __devm_reset_control_get(dev, NULL, index, RESET_CONTROL_EXCLUSIVE= ); } =20 /** @@ -803,7 +840,7 @@ devm_reset_control_get_exclusive_by_index(struct device= *dev, int index) static inline struct reset_control * devm_reset_control_get_shared_by_index(struct device *dev, int index) { - return __devm_reset_control_get(dev, NULL, index, true, false, false); + return __devm_reset_control_get(dev, NULL, index, RESET_CONTROL_SHARED); } =20 /* @@ -851,54 +888,54 @@ static inline struct reset_control *devm_reset_contro= l_get_by_index( static inline struct reset_control * devm_reset_control_array_get_exclusive(struct device *dev) { - return devm_reset_control_array_get(dev, false, false); + return devm_reset_control_array_get(dev, RESET_CONTROL_EXCLUSIVE); } =20 static inline struct reset_control * devm_reset_control_array_get_shared(struct device *dev) { - return devm_reset_control_array_get(dev, true, false); + return devm_reset_control_array_get(dev, RESET_CONTROL_SHARED); } =20 static inline struct reset_control * devm_reset_control_array_get_optional_exclusive(struct device *dev) { - return devm_reset_control_array_get(dev, false, true); + return devm_reset_control_array_get(dev, RESET_CONTROL_OPTIONAL_EXCLUSIVE= ); } =20 static inline struct reset_control * devm_reset_control_array_get_optional_shared(struct device *dev) { - return devm_reset_control_array_get(dev, true, true); + return devm_reset_control_array_get(dev, RESET_CONTROL_OPTIONAL_SHARED); } =20 static inline struct reset_control * of_reset_control_array_get_exclusive(struct device_node *node) { - return of_reset_control_array_get(node, false, false, true); + return of_reset_control_array_get(node, RESET_CONTROL_EXCLUSIVE); } =20 static inline struct reset_control * of_reset_control_array_get_exclusive_released(struct device_node *node) { - return of_reset_control_array_get(node, false, false, false); + return of_reset_control_array_get(node, RESET_CONTROL_EXCLUSIVE_RELEASED); } =20 static inline struct reset_control * of_reset_control_array_get_shared(struct device_node *node) { - return of_reset_control_array_get(node, true, false, true); + return of_reset_control_array_get(node, RESET_CONTROL_SHARED); } =20 static inline struct reset_control * of_reset_control_array_get_optional_exclusive(struct device_node *node) { - return of_reset_control_array_get(node, false, true, true); + return of_reset_control_array_get(node, RESET_CONTROL_OPTIONAL_EXCLUSIVE); } =20 static inline struct reset_control * of_reset_control_array_get_optional_shared(struct device_node *node) { - return of_reset_control_array_get(node, true, true, true); + return of_reset_control_array_get(node, RESET_CONTROL_OPTIONAL_SHARED); } #endif --=20 2.39.5 From nobody Fri Nov 29 00:38:45 2024 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6957950284 for ; Wed, 25 Sep 2024 16:40:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727282439; cv=none; b=jtyKFWnkWL892FgqRT7ofJs8vWu+LrViwC/33x4N7rU0OnHBsdYvskCtjGu0xTOFHLfH/VtS4C28frtkfk9csDSdj1tJmNt/YkdorZ7IjqB/q53LfV/oU7ArNzHtRFDsYbPX6g7/V8Ij+9Jf10ydcoobLGBks9LOSohAr0CTMvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727282439; c=relaxed/simple; bh=lp7raZp2g5LrqsnOZSvgkxD1/M1x9v7PHoZQ9GYY12o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WTC/DWFCyQkgS/ZZo4RAD+yqa0kGBp6FwXps/MlUemRhu4iZQetn0inR+/YzrQi/jkpR+z7Y87bygN+YhH9oJS2C55Gb7nOZTmk202SZWPXdIUbdIEKWE3s0+t2rE+w+wJzkTgRuXIjgonOFtC2sfLroGVQu1osTETCU8X4Z/5U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from dude05.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::54]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1stV3r-00046t-Lg; Wed, 25 Sep 2024 18:40:19 +0200 From: Philipp Zabel Date: Wed, 25 Sep 2024 18:40:10 +0200 Subject: [PATCH v2 2/3] reset: Add devres helpers to request pre-deasserted reset controls Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240925-reset-get-deasserted-v2-2-b3601bbd0458@pengutronix.de> References: <20240925-reset-get-deasserted-v2-0-b3601bbd0458@pengutronix.de> In-Reply-To: <20240925-reset-get-deasserted-v2-0-b3601bbd0458@pengutronix.de> To: Kunihiko Hayashi , Masami Hiramatsu , Lad Prabhakar , Geert Uytterhoeven , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de, Philipp Zabel X-Mailer: b4 0.15-dev-13183 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::54 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add devres helpers - devm_reset_control_bulk_get_exclusive_deasserted - devm_reset_control_bulk_get_optional_exclusive_deasserted - devm_reset_control_bulk_get_optional_shared_deasserted - devm_reset_control_bulk_get_shared_deasserted - devm_reset_control_get_exclusive_deasserted - devm_reset_control_get_optional_exclusive_deasserted - devm_reset_control_get_optional_shared_deasserted - devm_reset_control_get_shared_deasserted to request and immediately deassert reset controls. During cleanup, reset_control_assert() will be called automatically on the returned reset controls. Signed-off-by: Philipp Zabel Acked-by: Uwe Kleine-K=C3=B6nig --- Changes in v2: - Clear RESET_CONTROL_FLAGS_BIT_DEASSERTED out of flags. --- drivers/reset/core.c | 48 ++++++++++++++++++++- include/linux/reset.h | 113 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 159 insertions(+), 2 deletions(-) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index 682d61812852..22f67fc77ae5 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -1236,23 +1236,46 @@ static void devm_reset_control_release(struct devic= e *dev, void *res) reset_control_put(*(struct reset_control **)res); } =20 +static void devm_reset_control_release_deasserted(struct device *dev, void= *res) +{ + struct reset_control *rstc =3D *(struct reset_control **)res; + + reset_control_assert(rstc); + reset_control_put(rstc); +} + struct reset_control * __devm_reset_control_get(struct device *dev, const char *id, int index, enum reset_control_flags flags) { struct reset_control **ptr, *rstc; + bool deasserted =3D flags & RESET_CONTROL_FLAGS_BIT_DEASSERTED; =20 - ptr =3D devres_alloc(devm_reset_control_release, sizeof(*ptr), + ptr =3D devres_alloc(deasserted ? devm_reset_control_release_deasserted : + devm_reset_control_release, sizeof(*ptr), GFP_KERNEL); if (!ptr) return ERR_PTR(-ENOMEM); =20 + flags &=3D ~RESET_CONTROL_FLAGS_BIT_DEASSERTED; + rstc =3D __reset_control_get(dev, id, index, flags); if (IS_ERR_OR_NULL(rstc)) { devres_free(ptr); return rstc; } =20 + if (deasserted) { + int ret; + + ret =3D reset_control_deassert(rstc); + if (ret) { + reset_control_put(rstc); + devres_free(ptr); + return ERR_PTR(ret); + } + } + *ptr =3D rstc; devres_add(dev, ptr); =20 @@ -1272,24 +1295,45 @@ static void devm_reset_control_bulk_release(struct = device *dev, void *res) reset_control_bulk_put(devres->num_rstcs, devres->rstcs); } =20 +static void devm_reset_control_bulk_release_deasserted(struct device *dev,= void *res) +{ + struct reset_control_bulk_devres *devres =3D res; + + reset_control_bulk_assert(devres->num_rstcs, devres->rstcs); + reset_control_bulk_put(devres->num_rstcs, devres->rstcs); +} + int __devm_reset_control_bulk_get(struct device *dev, int num_rstcs, struct reset_control_bulk_data *rstcs, enum reset_control_flags flags) { struct reset_control_bulk_devres *ptr; + bool deasserted =3D flags & RESET_CONTROL_FLAGS_BIT_DEASSERTED; int ret; =20 - ptr =3D devres_alloc(devm_reset_control_bulk_release, sizeof(*ptr), + ptr =3D devres_alloc(deasserted ? devm_reset_control_bulk_release_deasser= ted : + devm_reset_control_bulk_release, sizeof(*ptr), GFP_KERNEL); if (!ptr) return -ENOMEM; =20 + flags &=3D ~RESET_CONTROL_FLAGS_BIT_DEASSERTED; + ret =3D __reset_control_bulk_get(dev, num_rstcs, rstcs, flags); if (ret < 0) { devres_free(ptr); return ret; } =20 + if (deasserted) { + ret =3D reset_control_bulk_deassert(num_rstcs, rstcs); + if (ret) { + reset_control_bulk_put(num_rstcs, rstcs); + devres_free(ptr); + return ret; + } + } + ptr->num_rstcs =3D num_rstcs; ptr->rstcs =3D rstcs; devres_add(dev, ptr); diff --git a/include/linux/reset.h b/include/linux/reset.h index 99296af98f81..2986ced69a02 100644 --- a/include/linux/reset.h +++ b/include/linux/reset.h @@ -28,6 +28,7 @@ struct reset_control_bulk_data { #define RESET_CONTROL_FLAGS_BIT_SHARED BIT(0) /* not exclusive */ #define RESET_CONTROL_FLAGS_BIT_OPTIONAL BIT(1) #define RESET_CONTROL_FLAGS_BIT_ACQUIRED BIT(2) /* iff exclusive, not rele= ased */ +#define RESET_CONTROL_FLAGS_BIT_DEASSERTED BIT(3) =20 /** * enum reset_control_flags - Flags that can be passed to the reset_contro= l_get functions @@ -35,21 +36,35 @@ struct reset_control_bulk_data { * These values cannot be OR'd. * * @RESET_CONTROL_EXCLUSIVE: exclusive, acquired, + * @RESET_CONTROL_EXCLUSIVE_DEASSERTED: exclusive, acquired, deasserted * @RESET_CONTROL_EXCLUSIVE_RELEASED: exclusive, released, * @RESET_CONTROL_SHARED: shared + * @RESET_CONTROL_SHARED_DEASSERTED: shared, deasserted * @RESET_CONTROL_OPTIONAL_EXCLUSIVE: optional, exclusive, acquired + * @RESET_CONTROL_OPTIONAL_EXCLUSIVE_DEASSERTED: optional, exclusive, acqu= ired, deasserted * @RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED: optional, exclusive, relea= sed * @RESET_CONTROL_OPTIONAL_SHARED: optional, shared + * @RESET_CONTROL_OPTIONAL_SHARED_DEASSERTED: optional, shared, deasserted */ enum reset_control_flags { RESET_CONTROL_EXCLUSIVE =3D RESET_CONTROL_FLAGS_BIT_ACQUIRED, + RESET_CONTROL_EXCLUSIVE_DEASSERTED =3D RESET_CONTROL_FLAGS_BIT_ACQUIRED | + RESET_CONTROL_FLAGS_BIT_DEASSERTED, RESET_CONTROL_EXCLUSIVE_RELEASED =3D 0, RESET_CONTROL_SHARED =3D RESET_CONTROL_FLAGS_BIT_SHARED, + RESET_CONTROL_SHARED_DEASSERTED =3D RESET_CONTROL_FLAGS_BIT_SHARED | + RESET_CONTROL_FLAGS_BIT_DEASSERTED, RESET_CONTROL_OPTIONAL_EXCLUSIVE =3D RESET_CONTROL_FLAGS_BIT_OPTIONAL | RESET_CONTROL_FLAGS_BIT_ACQUIRED, + RESET_CONTROL_OPTIONAL_EXCLUSIVE_DEASSERTED =3D RESET_CONTROL_FLAGS_BIT_O= PTIONAL | + RESET_CONTROL_FLAGS_BIT_ACQUIRED | + RESET_CONTROL_FLAGS_BIT_DEASSERTED, RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED =3D RESET_CONTROL_FLAGS_BIT_OPT= IONAL, RESET_CONTROL_OPTIONAL_SHARED =3D RESET_CONTROL_FLAGS_BIT_OPTIONAL | RESET_CONTROL_FLAGS_BIT_SHARED, + RESET_CONTROL_OPTIONAL_SHARED_DEASSERTED =3D RESET_CONTROL_FLAGS_BIT_OPTI= ONAL | + RESET_CONTROL_FLAGS_BIT_SHARED | + RESET_CONTROL_FLAGS_BIT_DEASSERTED, }; =20 #ifdef CONFIG_RESET_CONTROLLER @@ -596,6 +611,25 @@ __must_check devm_reset_control_get_exclusive(struct d= evice *dev, return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_EXCLUSIVE); } =20 +/** + * devm_reset_control_get_exclusive_deasserted - resource managed + * reset_control_get_exclusive() + + * reset_control_deassert() + * @dev: device to be reset by the controller + * @id: reset line name + * + * Managed reset_control_get_exclusive() + reset_control_deassert(). For r= eset + * controllers returned from this function, reset_control_assert() + + * reset_control_put() is called automatically on driver detach. + * + * See reset_control_get_exclusive() for more information. + */ +static inline struct reset_control * __must_check +devm_reset_control_get_exclusive_deasserted(struct device *dev, const char= *id) +{ + return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_EXCLUSIVE_DEASS= ERTED); +} + /** * devm_reset_control_bulk_get_exclusive - resource managed * reset_control_bulk_get_exclusiv= e() @@ -712,6 +746,25 @@ static inline struct reset_control *devm_reset_control= _get_shared( return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_SHARED); } =20 +/** + * devm_reset_control_get_shared_deasserted - resource managed + * reset_control_get_shared() + + * reset_control_deassert() + * @dev: device to be reset by the controller + * @id: reset line name + * + * Managed reset_control_get_shared() + reset_control_deassert(). For reset + * controllers returned from this function, reset_control_assert() + + * reset_control_put() is called automatically on driver detach. + * + * See devm_reset_control_get_shared() for more information. + */ +static inline struct reset_control * __must_check +devm_reset_control_get_shared_deasserted(struct device *dev, const char *i= d) +{ + return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_SHARED_DEASSERT= ED); +} + /** * devm_reset_control_bulk_get_shared - resource managed * reset_control_bulk_get_shared() @@ -732,6 +785,28 @@ devm_reset_control_bulk_get_shared(struct device *dev,= int num_rstcs, return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL= _SHARED); } =20 +/** + * devm_reset_control_bulk_get_shared_deasserted - resource managed + * reset_control_bulk_get_= shared() + + * reset_control_bulk_deas= sert() + * @dev: device to be reset by the controller + * @num_rstcs: number of entries in rstcs array + * @rstcs: array of struct reset_control_bulk_data with reset line names s= et + * + * Managed reset_control_bulk_get_shared() + reset_control_bulk_deassert()= . For + * reset controllers returned from this function, reset_control_bulk_asser= t() + + * reset_control_bulk_put() are called automatically on driver detach. + * + * See devm_reset_control_bulk_get_shared() for more information. + */ +static inline int __must_check +devm_reset_control_bulk_get_shared_deasserted(struct device *dev, int num_= rstcs, + struct reset_control_bulk_data *rstcs) +{ + return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, + RESET_CONTROL_SHARED_DEASSERTED); +} + /** * devm_reset_control_get_optional_exclusive - resource managed * reset_control_get_optional_= exclusive() @@ -750,6 +825,25 @@ static inline struct reset_control *devm_reset_control= _get_optional_exclusive( return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_EXCLUS= IVE); } =20 +/** + * devm_reset_control_get_optional_exclusive_deasserted - resource managed + * reset_control_ge= t_optional_exclusive() + + * reset_control_de= assert() + * @dev: device to be reset by the controller + * @id: reset line name + * + * Managed reset_control_get_optional_exclusive() + reset_control_deassert= (). + * For reset controllers returned from this function, reset_control_assert= () + + * reset_control_put() is called automatically on driver detach. + * + * See devm_reset_control_get_optional_exclusive() for more information. + */ +static inline struct reset_control * +devm_reset_control_get_optional_exclusive_deasserted(struct device *dev, c= onst char *id) +{ + return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_EXCLUS= IVE_DEASSERTED); +} + /** * devm_reset_control_bulk_get_optional_exclusive - resource managed * reset_control_bulk_get= _optional_exclusive() @@ -789,6 +883,25 @@ static inline struct reset_control *devm_reset_control= _get_optional_shared( return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_SHARED= ); } =20 +/** + * devm_reset_control_get_optional_shared_deasserted - resource managed + * reset_control_get_o= ptional_shared() + + * reset_control_deass= ert() + * @dev: device to be reset by the controller + * @id: reset line name + * + * Managed reset_control_get_optional_shared() + reset_control_deassert().= For + * reset controllers returned from this function, reset_control_assert() + + * reset_control_put() is called automatically on driver detach. + * + * See devm_reset_control_get_optional_shared() for more information. + */ +static inline struct reset_control * +devm_reset_control_get_optional_shared_deasserted(struct device *dev, cons= t char *id) +{ + return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_SHARED= _DEASSERTED); +} + /** * devm_reset_control_bulk_get_optional_shared - resource managed * reset_control_bulk_get_op= tional_shared() --=20 2.39.5 From nobody Fri Nov 29 00:38:45 2024 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C8B0D520 for ; Wed, 25 Sep 2024 16:40:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727282424; cv=none; b=jaNdK8JOgw8f5Ko5nNl/iyEW8skgXzndmk2RVK4+PSI/U1fZiz/vCmNL6GTNCGziy2/uk5/zeSjo3sLym/715azZdeVwiLw+hpUnxTFOxcHHa+jHoNZBQrOfYS/z7YQj4OejJk509neZC4d9ywLfhxHgqToi77Ih7z5AD2ZalV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727282424; c=relaxed/simple; bh=XJLI1q11MCzwrfN28X1pUSiRSb6Pv4ZsimpDyNVdQMo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jqqVupcK/7zMPEEbL99BYN5sCEaCQRhUi2lAmSILf1zf2+1lp39yVnhLVLUrNwDnrnpyQYg2TPSk8CV0zfeVSis6J1J4gajaF7huVC9kGKf7ZZ/EKcPvVx7KWymPYbnzJ5unk3GznL77eJWNg+OfLi26iJJYNSJV5WLM1SZ09hU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from dude05.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::54]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1stV3r-00046t-NX; Wed, 25 Sep 2024 18:40:19 +0200 From: Philipp Zabel Date: Wed, 25 Sep 2024 18:40:11 +0200 Subject: [PATCH v2 3/3] reset: uniphier-glue: Use devm_reset_control_bulk_get_shared_deasserted() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240925-reset-get-deasserted-v2-3-b3601bbd0458@pengutronix.de> References: <20240925-reset-get-deasserted-v2-0-b3601bbd0458@pengutronix.de> In-Reply-To: <20240925-reset-get-deasserted-v2-0-b3601bbd0458@pengutronix.de> To: Kunihiko Hayashi , Masami Hiramatsu , Lad Prabhakar , Geert Uytterhoeven , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de, Philipp Zabel X-Mailer: b4 0.15-dev-13183 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::54 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Replace the pattern devm_reset_control_bulk_get_shared() / reset_control_bulk_deassert() / devm_add_action_or_reset() with devm_reset_control_bulk_get_shared_deasserted() for some reduction in boilerplate. Signed-off-by: Philipp Zabel Acked-by: Uwe Kleine-K=C3=B6nig --- drivers/reset/reset-uniphier-glue.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/drivers/reset/reset-uniphier-glue.c b/drivers/reset/reset-unip= hier-glue.c index 5f9f2f7994c0..a2a262bf6bfc 100644 --- a/drivers/reset/reset-uniphier-glue.c +++ b/drivers/reset/reset-uniphier-glue.c @@ -35,13 +35,6 @@ static void uniphier_clk_disable(void *_priv) clk_bulk_disable_unprepare(priv->data->nclks, priv->clk); } =20 -static void uniphier_rst_assert(void *_priv) -{ - struct uniphier_glue_reset_priv *priv =3D _priv; - - reset_control_bulk_assert(priv->data->nrsts, priv->rst); -} - static int uniphier_glue_reset_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; @@ -68,13 +61,6 @@ static int uniphier_glue_reset_probe(struct platform_dev= ice *pdev) if (ret) return ret; =20 - for (i =3D 0; i < priv->data->nrsts; i++) - priv->rst[i].id =3D priv->data->reset_names[i]; - ret =3D devm_reset_control_bulk_get_shared(dev, priv->data->nrsts, - priv->rst); - if (ret) - return ret; - ret =3D clk_bulk_prepare_enable(priv->data->nclks, priv->clk); if (ret) return ret; @@ -83,11 +69,11 @@ static int uniphier_glue_reset_probe(struct platform_de= vice *pdev) if (ret) return ret; =20 - ret =3D reset_control_bulk_deassert(priv->data->nrsts, priv->rst); - if (ret) - return ret; - - ret =3D devm_add_action_or_reset(dev, uniphier_rst_assert, priv); + for (i =3D 0; i < priv->data->nrsts; i++) + priv->rst[i].id =3D priv->data->reset_names[i]; + ret =3D devm_reset_control_bulk_get_shared_deasserted(dev, + priv->data->nrsts, + priv->rst); if (ret) return ret; =20 --=20 2.39.5