Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp468692ybm; Thu, 28 May 2020 07:26:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOTpwf7VZ8o7YBTeCN7qkYpSbdFbQTH8xCpYIGrl9/nnW5f7xRd85zsmaJMm11Y4/B34pZ X-Received: by 2002:a50:d715:: with SMTP id t21mr3340089edi.194.1590675979841; Thu, 28 May 2020 07:26:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590675979; cv=none; d=google.com; s=arc-20160816; b=xbFmw08e/3GJSfDH86Bb9yQgGjbRskXKr2+4bSdMZtrmSwmT1Dy4Nw1aDic2axcxIU t1vQ1VM3vzdJz9srAovYm5tRAaBgfMB3rCBQmh18LPwXqatD9K4LxmoiGX8wLMbv125B DqXtGXI43vTpcSRpFBlXMjwTiAvQCkKN/RweT1czNBA/HSCnQj90vXDMwqitThMte/mn kawCXyvFyM4P0a+D05ltxWgindMNbUmOdosloK/BfKs+C656+sc/BOE1/eRocT4QX7xj hFhl5ddCsuvnJv0WvyKqavVEZYx7qgxLTOV1rzji7MMQhhgG2L4agFt3vp9pvuazu5Nv yZHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bUTqIyJQ96SSMI0A1T4YUDc+Z+dd4WsNKtNtEYEWK4U=; b=a3U+i0Fj06gAjIv2Vu9dwxCllltbZFLWEixt38Sm+JWrKYUUC3Wn5K+vAxXLuScDnj 3OcbtTrwnK595AhfpK1fCgvOdStK/ePPHkAAFrU0K8vow3QDsYILrd6O+lJ4HkOzZU4W YGqKjsbM3gyLN2cWU2aBOOHzZCzMGBOlwW1xt9xCFa8GZEu0N685MN9jjC8emi937dBZ NnSktq6YU6RDVNboNHJqysC61yYRa8Ra6KYR750y+rF66to3AODmZTugdAsTln7IdgSU 2BJjiA8GSwA0nMi2MPxfjuBYYWoTU6FgfMprpKw8n92Lc1IuKprRGftu0cThdLliboYb nxAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=upvfkJpE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lj13si726804ejb.528.2020.05.28.07.25.56; Thu, 28 May 2020 07:26:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=upvfkJpE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391149AbgE1OXq (ORCPT + 99 others); Thu, 28 May 2020 10:23:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391110AbgE1OW4 (ORCPT ); Thu, 28 May 2020 10:22:56 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87AA9C08C5C8 for ; Thu, 28 May 2020 07:22:55 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id u26so4614255wmn.1 for ; Thu, 28 May 2020 07:22:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bUTqIyJQ96SSMI0A1T4YUDc+Z+dd4WsNKtNtEYEWK4U=; b=upvfkJpE+j2X8Py5StpA9JlDlz2G9d49LnZEOgNJpWo/0I87+o9/l2XXA6HKaXcNac bXBCxrNiF435IihMwKsSZiyIuVjmiev2lr80Ts7YvZxkr2y+Ny3q+KKL2LEWFCP4f2Mn jDCBpYaiitFDb9cI/2Qsa+yvmMxX7nEjTCkgmHspXj8M19pq6FYicVh5ufEf3GsndFsC 3sImHWzerLDxh1w42NoP5PX14EUb5k9D/VNKWVIobkFk8O77pL77IyOg7lrb757twjpi QsnvGsOfA4hIJLkF9gCVphVrXvKu4hwwk8x1d2eQE56DXo5ckQKHQI6aiKdnddEUBnxD tqoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bUTqIyJQ96SSMI0A1T4YUDc+Z+dd4WsNKtNtEYEWK4U=; b=g7rovH789w8qunh7D7z81nU5mF2OCOnnVWtw+rXghfeOzdGL1zO7Zfkr79RezMjRyz 1IcxSQexNgDko/WITtAD4S7hgmbn1zeY2S5Dvcw7ug99ywDrRueDYBapSKZROCzN2QPX FWHvgMd34bu6JUx/oxFTNH0nOP5Xpk7fjKb1kPZbDgyJ8GTQi2WB46rTsgjw0v6pgSPV vn5VQ8BL7ZQBLqYOZ2Vovg4c5i5EQyEUPyCI3W0lamXzxpKaUvMEg0TbIPHVD52teHr9 iG4DRMJKxk205lllZOsao4lig63OACoUJbIRp4dUf/oQfoRPtWWBIg3rU6hDzHzjn/y1 ACgw== X-Gm-Message-State: AOAM531F46FW4yl6dCPyqPHb4AM7jCXlcgiasG58ZQ7L48Ml8EP1zJwK OyICZdYR4GKGTwShgfDM/scYqg== X-Received: by 2002:a7b:c086:: with SMTP id r6mr3540234wmh.29.1590675773653; Thu, 28 May 2020 07:22:53 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id h74sm6258162wrh.76.2020.05.28.07.22.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2020 07:22:53 -0700 (PDT) From: Bartosz Golaszewski To: John Crispin , Sean Wang , Mark Lee , "David S . Miller" , Jakub Kicinski , Matthias Brugger , Mark Brown Cc: netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Fabien Parent , Stephane Le Provost , Pedro Tsai , Andrew Perepech , Bartosz Golaszewski Subject: [PATCH v2 1/2] regmap: provide helpers for simple bit operations Date: Thu, 28 May 2020 16:22:40 +0200 Message-Id: <20200528142241.20466-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200528142241.20466-1-brgl@bgdev.pl> References: <20200528142241.20466-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski In many instances regmap_update_bits() is used for simple bit setting and clearing. In these cases the last argument is redundant and we can hide it with a static inline function. This adds three new helpers for simple bit operations: set_bits, clear_bits and test_bits. Signed-off-by: Bartosz Golaszewski --- drivers/base/regmap/regmap.c | 22 ++++++++++++++++++++++ include/linux/regmap.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 59f911e57719..30f659e0b4e4 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -2936,6 +2936,28 @@ int regmap_update_bits_base(struct regmap *map, unsigned int reg, } EXPORT_SYMBOL_GPL(regmap_update_bits_base); +/** + * regmap_test_bits() - Check if all specified bits are set in a register. + * + * @map: Register map to operate on + * @reg: Register to read from + * @bits: Bits to test + * + * Returns -1 if the underlying regmap_read() fails, 0 if at least one of the + * tested bits is not set and 1 if all tested bits are set. + */ +int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits) +{ + unsigned int val, ret; + + ret = regmap_read(map, reg, &val); + if (ret) + return ret; + + return (val & bits) == bits ? 1 : 0; +} +EXPORT_SYMBOL_GPL(regmap_test_bits); + void regmap_async_complete_cb(struct regmap_async *async, int ret) { struct regmap *map = async->map; diff --git a/include/linux/regmap.h b/include/linux/regmap.h index 40b07168fd8e..ddf0baff195d 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -1111,6 +1111,21 @@ bool regmap_reg_in_ranges(unsigned int reg, const struct regmap_range *ranges, unsigned int nranges); +static inline int regmap_set_bits(struct regmap *map, + unsigned int reg, unsigned int bits) +{ + return regmap_update_bits_base(map, reg, bits, bits, + NULL, false, false); +} + +static inline int regmap_clear_bits(struct regmap *map, + unsigned int reg, unsigned int bits) +{ + return regmap_update_bits_base(map, reg, bits, 0, NULL, false, false); +} + +int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits); + /** * struct reg_field - Description of an register field * @@ -1410,6 +1425,27 @@ static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg, return -EINVAL; } +static inline int regmap_set_bits(struct regmap *map, + unsigned int reg, unsigned int bits) +{ + WARN_ONCE(1, "regmap API is disabled"); + return -EINVAL; +} + +static inline int regmap_clear_bits(struct regmap *map, + unsigned int reg, unsigned int bits) +{ + WARN_ONCE(1, "regmap API is disabled"); + return -EINVAL; +} + +static inline int regmap_test_bits(struct regmap *map, + unsigned int reg, unsigned int bits) +{ + WARN_ONCE(1, "regmap API is disabled"); + return -EINVAL; +} + static inline int regmap_field_update_bits_base(struct regmap_field *field, unsigned int mask, unsigned int val, bool *change, bool async, bool force) -- 2.26.1