Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 199BDC54EED for ; Mon, 30 Jan 2023 02:05:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235414AbjA3CFP (ORCPT ); Sun, 29 Jan 2023 21:05:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235407AbjA3CFN (ORCPT ); Sun, 29 Jan 2023 21:05:13 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4019E4226 for ; Sun, 29 Jan 2023 18:05:11 -0800 (PST) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1pMJXg-0007Ev-0U; Mon, 30 Jan 2023 03:05:08 +0100 Date: Mon, 30 Jan 2023 02:04:57 +0000 From: Daniel Golle To: Colin Foster , linux-kernel@vger.kernel.org, Mark Brown , "Rafael J. Wysocki" , Greg Kroah-Hartman Subject: [RFC PATCH v2] regmap: apply reg_base and reg_downshift for single register ops Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org reg_base and reg_downshift currently don't have any effect if used with a regmap_bus or regmap_config which only offers single register operations (ie. reg_read, reg_write and optionally reg_update_bits). Fix that and take them into account also for regmap_bus with only reg_read and read_write operations by applying reg_base and reg_downshift in _regmap_bus_reg_write, _regmap_bus_reg_read. Also apply reg_base and reg_downshift in _regmap_update_bits, but only in case the operation is carried out with a reg_update_bits call defined in either regmap_bus or regmap_config. Fixes: 0074f3f2b1e43d ("regmap: allow a defined reg_base to be added to every address") Fixes: 86fc59ef818beb ("regmap: add configurable downshift for addresses") Signed-off-by: Daniel Golle --- I hope that I didn't miss anything there... @Colin Please let me know if this breaks anything with your ocelot_spi use-case. drivers/base/regmap/regmap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index d12d669157f24..d2a54eb0efd9b 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -1942,6 +1942,8 @@ static int _regmap_bus_reg_write(void *context, unsigned int reg, { struct regmap *map = context; + reg += map->reg_base; + reg >>= map->format.reg_downshift; return map->bus->reg_write(map->bus_context, reg, val); } @@ -2840,6 +2842,8 @@ static int _regmap_bus_reg_read(void *context, unsigned int reg, { struct regmap *map = context; + reg += map->reg_base; + reg >>= map->format.reg_downshift; return map->bus->reg_read(map->bus_context, reg, val); } @@ -3231,6 +3235,8 @@ static int _regmap_update_bits(struct regmap *map, unsigned int reg, *change = false; if (regmap_volatile(map, reg) && map->reg_update_bits) { + reg += map->reg_base; + reg >>= map->format.reg_downshift; ret = map->reg_update_bits(map->bus_context, reg, mask, val); if (ret == 0 && change) *change = true; -- 2.39.1