From patchwork Mon Apr 23 14:16:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 902963 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="VPp7yYzp"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40V7nd4S8Jz9s02 for ; Tue, 24 Apr 2018 00:17:07 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 5C903C21DA1; Mon, 23 Apr 2018 14:17:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 3F29DC21C29; Mon, 23 Apr 2018 14:16:58 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3DB8CC21C93; Mon, 23 Apr 2018 14:16:57 +0000 (UTC) Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by lists.denx.de (Postfix) with ESMTPS id D2C82C21BE5 for ; Mon, 23 Apr 2018 14:16:56 +0000 (UTC) Received: by mail-wr0-f195.google.com with SMTP id s18-v6so41754455wrg.9 for ; Mon, 23 Apr 2018 07:16:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=qreq/K2UU8HRNpFEJb43XZQbNwh0DqELf0VPVTRmq1M=; b=VPp7yYzplZFBs/Eez7tnK0EFv7OLD6qYMGxy+/rzYA0e4Gfci1/k0HoxvBDCW5Ty7W rf5EkSyeqT4/IZUGg5EZaXUP0mJYivSY+whTJVmKRXD7jUbY9IYkzOtHrzSZY5Nv5D7H q3JPFngSeuycC73DCKK2KsAhuG+M57QrP8aNlc6iS509jAmDzPfyRgx0DYJsQcYKSUji yfXvd9lRnLDn2JESz4DmWWPd7N9i8KGxE6E55jTO080TFu1eVxHYqShMj5l9+nCfUirr 3mH3C7ao3iOJWUlvJsSTwlg/tPxHBNNwKMed+4pelDBFvY1DZrh6W7X7t6zgKoGuzn53 CJUg== 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; bh=qreq/K2UU8HRNpFEJb43XZQbNwh0DqELf0VPVTRmq1M=; b=K84eVlcLEuyrDaN5GOAMyl3Mb5VkP4yAW6RsQNgZHxnV4zalCgw5rNGjr230bI32P1 sWNFD9YXTh9v9dpOp+qHR7r+0ieh4fBXys/sWjDAf8F8haC6M6iNEkjsUzvOu3nVOYUg 4Wf4CQHZxCb6onYQo39gV5dYuXeuV97hcUn3KpOORhf5zJXkTEmDwmHxLSrYNiuuo8o0 hH9W/MepsvcxDyFSw86edS4Py0905uhsGthffHk+Ca+oTMUpq8nZRYy/9SFCP4UXgYVb i8d/8vKZe5zlZfgzSzFrEuO6rWKMOX9ggZL0HRBvVVJPuSMXqwGTgNU+CpAJb4dkkSm0 midA== X-Gm-Message-State: ALQs6tDmWGPfnJnwM3IBL3yZEk9jLKkcqV5J3a9e1xuyV07dI39Hh5y0 jfh2n4KHQjqRUUSmypCjJKriVw== X-Google-Smtp-Source: AIpwx4/uuZTLPBfyY+yKVI8skhaPo8ways3yQ3COZWOPN3x2HS09Lk2dvSZ+gy0m0qYUYr9rtQQ2Lg== X-Received: by 10.28.52.16 with SMTP id b16mr9310875wma.147.1524493016373; Mon, 23 Apr 2018 07:16:56 -0700 (PDT) Received: from bender.baylibre.local ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id 14sm10803790wmo.27.2018.04.23.07.16.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Apr 2018 07:16:55 -0700 (PDT) From: Neil Armstrong To: trini@konsulko.com, sjg@chromium.org, u-boot@lists.denx.de Date: Mon, 23 Apr 2018 16:16:52 +0200 Message-Id: <1524493012-2587-1-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 2.7.4 Subject: [U-Boot] [PATCH] regmap: add regmap_update_bits() helper X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add the regmap_update_bits() to simply the read/modify/write of registers in a single command. The function is taken from Linux regmap implementation. Signed-off-by: Neil Armstrong --- include/regmap.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/regmap.h b/include/regmap.h index 493a5d8..3c463e9 100644 --- a/include/regmap.h +++ b/include/regmap.h @@ -47,6 +47,29 @@ int regmap_read(struct regmap *map, uint offset, uint *valp); regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), valp) /** + * regmap_update_bits() - Perform a read/modify/write using a mask + * + * @map: The map returned by regmap_init_mem*() + * @offset: Offset of the memory + * @mask: Mask to apply to the read value + * @val: Value to apply to the value to write + */ +static inline int regmap_update_bits(struct regmap *map, uint offset, + uint mask, uint val) +{ + uint reg; + int ret; + + ret = regmap_read(map, offset, ®); + if (ret) + return ret; + + reg &= ~mask; + + return regmap_write(map, offset, reg | val); +} + +/** * regmap_init_mem() - Set up a new register map that uses memory access * * Use regmap_uninit() to free it.