Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4454062imw; Tue, 19 Jul 2022 06:58:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tBFdlxugTPdY612etIMGqmEjNvcEa+CQCQpz1PTQ8mLsOPYVAbSxCNEfd5e77TDW9D0JUz X-Received: by 2002:a17:907:94d0:b0:72f:269c:3aa3 with SMTP id dn16-20020a17090794d000b0072f269c3aa3mr10727936ejc.695.1658239097609; Tue, 19 Jul 2022 06:58:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658239097; cv=none; d=google.com; s=arc-20160816; b=a217C0QhZ+9TkPsbjIpEEFAx8+jKx9flI3kIQ2t0CsbFxd9vED4yeBJbDHzYBAB0Oc qSjlbRwos1s4zppvDI40u7QcFrxH5lzXT/YvvfShphNSYciJgLB3thtCynzL1Bhlupxa sf8piBiWIRQtI4riRMbhdo16Bwn4Tj0WBoOj8xU69E0hLojoo9h7nm0tITneccZ83H/j WRCPXrl7Cx93vcl34xsuNvcqwgq5+1ZOrajdriX5MskY2ZH9E775IL/YLTM0wW/wjCoc 2mcrVCnxXbHaP05DgVoEap3nUyURV/t+ETjlft4XLx92/OpK/qU7bXbaDQuHpMBHaior RpTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=DSnN84I8id4pmT4ygtiuQTO7ZBfhQz7qlV9qScs+cCM=; b=qSOD8jZsqCcMB05cqbIbe58UFS9jrZg8f3PeTEZSvaesvQD5YEA8DAYw0WWshDwoNK VWXVPxZES/CTS6qzgLcEj6KnvqI3bRdHiq6AX52J1pUtTviI/z98rJ9y3EWasp+U5zrH VYa7DRzOh7k+RaPZ+DYgsqGA2Z7h+vqqqyFzlanreQHe/xaIiaRnaF9KZhjJNL+rD+0M LM83Arlsj8KdUsrKRU/tFJrEUwJ3ZCUb1mEcCx8c6+CsbPJMcIgheiEV8Y2D73MXuEyN n+N3+gqeZqvo1vgwbXGVA6OUhJl+fD9PYqSKeSBpxPWzyjmBC7nd1ilx/JFcrAXQxB1W vz+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=a1calhPE; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dx20-20020a170906a85400b0072b3b4f015csi16657742ejb.311.2022.07.19.06.57.46; Tue, 19 Jul 2022 06:58:17 -0700 (PDT) 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; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=a1calhPE; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234057AbiGSNkb (ORCPT + 99 others); Tue, 19 Jul 2022 09:40:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239753AbiGSNkM (ORCPT ); Tue, 19 Jul 2022 09:40:12 -0400 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 172E793C13 for ; Tue, 19 Jul 2022 05:54:16 -0700 (PDT) Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26JBSCu8020443; Tue, 19 Jul 2022 07:54:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=PODMain02222019; bh=DSnN84I8id4pmT4ygtiuQTO7ZBfhQz7qlV9qScs+cCM=; b=a1calhPEyLeoQoMTnMQxbPLqUd348g1KDZUxs8AKLFY2X1ej3nVOmYHVIj4stJMxBjd1 9pLDsP7cbj2Kcb+B935Xz4x2UjJh6YHLlkitufaBjJCP7csEBqgJgbJ1kL1l3SwpmxhI CN7YPU7ZBGNavEQi9XsWH5c1oP1LlB7xrEC/SC6Up2SUWDUIFC66P5xQErlStbvvJNn6 5HtB15KtOa34ROrXGUdudUI1n57AACypB9pxP2FtVsf/71dPDBWWL18ZlaBCxxUCFSjy D2/c5vjv+kJDX+DDpL6vtmUG9gRk9WMxDu/o9k05ykAlr2gCTUfiVYJ0ZS3uQrfiFXJn VA== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3hdrqfgas6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jul 2022 07:54:04 -0500 Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.9; Tue, 19 Jul 2022 07:54:02 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by anon-ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.2.1118.9 via Frontend Transport; Tue, 19 Jul 2022 07:54:02 -0500 Received: from ediswmail.ad.cirrus.com (ediswmail.ad.cirrus.com [198.61.86.93]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 01914B06; Tue, 19 Jul 2022 12:54:02 +0000 (UTC) Date: Tue, 19 Jul 2022 12:54:02 +0000 From: Charles Keepax To: Krzysztof Kozlowski CC: Mark Brown , Greg Kroah-Hartman , "Rafael J. Wysocki" , , Srinivas Kandagatla , Kuninori Morimoto , Bjorn Andersson Subject: Re: [PATCH] regmap: support regmap_field_write() on non-readable fields Message-ID: <20220719125401.GA92394@ediswmail.ad.cirrus.com> References: <20220719121446.375095-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20220719121446.375095-1-krzysztof.kozlowski@linaro.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-Proofpoint-ORIG-GUID: UO-aPwDOQH2ADVJS1xfZBGySBHGBnbPm X-Proofpoint-GUID: UO-aPwDOQH2ADVJS1xfZBGySBHGBnbPm X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,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 On Tue, Jul 19, 2022 at 02:14:46PM +0200, Krzysztof Kozlowski wrote: > Current implementation of regmap_field_write() performs an update of > register (read+write), therefore it ignores regmap read-restrictions and > is not suitable for write-only registers (e.g. interrupt clearing). > > Extend regmap_field_write() and regmap_field_force_write() to check if > register is readable and only then perform an update. In the other > case, it is expected that mask of field covers entire register thus a > full write is allowed. > > Signed-off-by: Krzysztof Kozlowski > > --- > > Cc: Srinivas Kandagatla > Cc: Charles Keepax > Cc: Kuninori Morimoto > Cc: Bjorn Andersson > --- > drivers/base/regmap/regmap.c | 50 ++++++++++++++++++++++++++++++++++++ > include/linux/regmap.h | 15 ++--------- > 2 files changed, 52 insertions(+), 13 deletions(-) > > diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c > index 0caa5690c560..4d18a34f7b2c 100644 > --- a/drivers/base/regmap/regmap.c > +++ b/drivers/base/regmap/regmap.c > @@ -2192,6 +2192,56 @@ int regmap_noinc_write(struct regmap *map, unsigned int reg, > } > EXPORT_SYMBOL_GPL(regmap_noinc_write); > > +static int _regmap_field_write_or_update(struct regmap_field *field, > + unsigned int val, bool *change, > + bool async, bool force) > +{ > + unsigned int mask = (~0 << field->shift) & field->mask; > + unsigned int map_val_mask, map_val_mask_h; > + int ret; > + > + if (regmap_readable(field->regmap, field->reg)) > + return regmap_update_bits_base(field->regmap, field->reg, > + mask, val << field->shift, > + change, async, force); > + I think this will break other valid use-cases, regmap_readable (I believe) returns if the register is physically readable, however it should still be possible to use update bits if the register is in the cache even if it can't physically be read. So really you need to fall into this path if it is readable or in the cache. Which does I guess also raise the question if your problem would be better solved with caching the register? Thanks, Charles