From patchwork Mon Jan 30 02:04:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 50091 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1968822wrn; Sun, 29 Jan 2023 18:14:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXvnlch5R40/lIaV5UHn67cxriSulfxS/K0FJOS9eHyR4pt10vdEg/ljGXKgODeeKrhCldwf X-Received: by 2002:a17:90a:1a:b0:22b:bcae:d6e2 with SMTP id 26-20020a17090a001a00b0022bbcaed6e2mr35429219pja.10.1675044857395; Sun, 29 Jan 2023 18:14:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675044857; cv=none; d=google.com; s=arc-20160816; b=Z/xncEJisq3MrpyyQG1ThEnsrtYmH/N9W5mqpgRrnrNz8q+fuWe/sWykJ5N2rj49wd UP7Enj2DzKIRIC8ncZcS351CGbKSie2WuqrTPfkapl+XSeEsBSxSYSSs7siAb5TGp2yI tsIUZB7jT3wkhmmFqn9zIzgJLIFzq1jhOBgPYCHT5wagCyapOum73zaaBt/f7aVaMXTc Pz6/hZWIXbp0/H5aUlLL2+fa17mTPggnDE/dIFEbNi5IQYzyB+2kJU8lefk3ow39YNLb Awi/m205oOEFD5Wb00wTFTu/jk4KwdLmTdFBCsWmnQKHuHxXlcF4yf94CfW5VDakNh/9 kJbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date; bh=IzOKznPXRzmHZrqPL/+c31bn1e9m5Wy747jQtQUZ3QY=; b=n/tTopM+5JqILbTRu/EsfGv5b/DDANZk3N4NfDQ+VCs24cVqjYKqB/vN4ZGNh1pIzd ylY1AjGzwBcffEHcl3FLTAvo7tvM/WwXeuMffKpJRylF95GnTF5289mjL3aLCeIe0cE3 hoOOICsJEmXOUGRHsLg4mO8viojAF8NGoGnjKCaJ5iwiqIRUxFdvI+eM4rC0OlT28Elx ZnYkX7BrhgA5kjr8N2Orcs7LPc/WIneOD5QQlVN+pmc482LvPklNefHBGJVaUJd3wsxz ZrGbOUJqm6E0YLTahX1MoOcW77E9v1L3Sh1TF19g7L7fl9HjlpJST7T4j28upUZyeKbV mNMg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i198-20020a636dcf000000b004da13f2c14esi11526638pgc.710.2023.01.29.18.14.02; Sun, 29 Jan 2023 18:14:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235412AbjA3CFO (ORCPT + 99 others); Sun, 29 Jan 2023 21:05:14 -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-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756234820060323100?= X-GMAIL-MSGID: =?utf-8?q?1756411836390837250?= 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 Tested-by: Colin Foster --- 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;