From patchwork Fri Apr 27 09:56:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 905599 X-Patchwork-Delegate: trini@ti.com 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="wJ0HKZHO"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40XTrc0BBGz9s02 for ; Fri, 27 Apr 2018 19:57:51 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id B5217C220C9; Fri, 27 Apr 2018 09:57:14 +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_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 70C10C2210D; Fri, 27 Apr 2018 09:56:36 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9072CC220BF; Fri, 27 Apr 2018 09:56:20 +0000 (UTC) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by lists.denx.de (Postfix) with ESMTPS id 69912C22092 for ; Fri, 27 Apr 2018 09:56:20 +0000 (UTC) Received: by mail-wm0-f65.google.com with SMTP id x12so2667719wmc.0 for ; Fri, 27 Apr 2018 02:56:20 -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:in-reply-to:references; bh=lFmOnp/YgeJZ9+wN/snHQVG4sRPpK5wWJgPAuXChwl0=; b=wJ0HKZHOdAaXZtRq8d2NEPSm2oy2WWkP2jpqeiz77sLowxH5xydP6gt0RPlNpvp4D5 9Vy0j842PmOqmqyn6VMP/BroSxpPcWqxBy0+yeeFO6Hbg5QyeWNwA7EO8FWaXlXq2Wo8 dwvq6yWIvBfbfi7uJ+/3ceiX8tpFeTkzMFFLxj3n/iW8fnh+xla7E3a99noeffBNtdNn Z3mmkrmcDeFqSV1gMtSwQSsDSCXxeW3x2YlKTv11UZIg6RoaZvtjGHXDTQnL+VG6Laei 8hjN3gNf5ZwNsK8KgtMITB7L7fZ+KtuWrugBrDjbmR/+4RaHL33k2mvvC4mycvltYgej WxEg== 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; bh=lFmOnp/YgeJZ9+wN/snHQVG4sRPpK5wWJgPAuXChwl0=; b=rd6gn9VS1RbvOyNM0UcGXKYw0YNEXAPu9sssJcpDSiJiZdHL633ZHKv69jYMCWLMv9 TiYjS/zEUrju+BrFXNakCyTPB4okcVWeg057/HI3ZwgYhDePmX/FPUOlFFzSZNzD3xUU ouwX2fQZmSMxJKo5k4cCN5dX/YQWu7UBe6IX4std8J4bHTfOrfnTLevPwCC2hJILLNuR iOMJ/m0yAadrybtnL89XKWBPuXkWNxhsRKM8sGQG1cYwds2dBGG9498/3I6/IrDzS5CG lxTbEDpjI1GFFcYa0qlKhm+6W8Xa/QeY/NJidwugR7zptqGkp9CxUvUtb7j17asqKV3+ +48A== X-Gm-Message-State: ALQs6tABZrbqFvqWK/ZkSlvtG76GVdDr4tkoHrqOdatp5nGYC7VPeqGZ WffzlgIntFHv3qmBSt2OaH+iDQ== X-Google-Smtp-Source: AB8JxZrVIfiWgeQrPbaZG6lKOblcmt1D9V02H5zSVV2IjC0cnNNM4BCzggaaMAGRBGQhjcnB4UMFZQ== X-Received: by 10.28.231.4 with SMTP id e4mr869672wmh.119.1524822979905; Fri, 27 Apr 2018 02:56:19 -0700 (PDT) Received: from bender.baylibre.local ([2a01:e34:eeb6:4690:35c7:f264:355a:6031]) by smtp.gmail.com with ESMTPSA id 77sm1777108wmt.11.2018.04.27.02.56.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Apr 2018 02:56:19 -0700 (PDT) From: Neil Armstrong To: trini@konsulko.com, sjg@chromium.org, u-boot@lists.denx.de Date: Fri, 27 Apr 2018 11:56:14 +0200 Message-Id: <1524822975-22120-2-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524822975-22120-1-git-send-email-narmstrong@baylibre.com> References: <1524822975-22120-1-git-send-email-narmstrong@baylibre.com> Subject: [U-Boot] [PATCH v2 1/2] 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 Reviewed-by: Simon Glass --- drivers/core/regmap.c | 14 ++++++++++++++ include/regmap.h | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c index 8a0e00f..9fae252 100644 --- a/drivers/core/regmap.c +++ b/drivers/core/regmap.c @@ -147,3 +147,17 @@ int regmap_write(struct regmap *map, uint offset, uint val) return 0; } + +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); +} diff --git a/include/regmap.h b/include/regmap.h index 493a5d8..1349d40 100644 --- a/include/regmap.h +++ b/include/regmap.h @@ -47,6 +47,16 @@ 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 + */ +int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val); + +/** * regmap_init_mem() - Set up a new register map that uses memory access * * Use regmap_uninit() to free it.