Message ID | ZFM7lE4ZuDrUTspH@fedora |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp69498vqo; Wed, 3 May 2023 22:29:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5DyykFZ0W8jiuS6pYOw4u0aZxiclW6NTf+1YR6wAhcBgVhzRTyEHuYDGbq0AZ4/0baw3Pj X-Received: by 2002:a05:6a00:170e:b0:63d:254a:3909 with SMTP id h14-20020a056a00170e00b0063d254a3909mr1116209pfc.32.1683178169194; Wed, 03 May 2023 22:29:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683178169; cv=none; d=google.com; s=arc-20160816; b=BY9WQNk8HpRo+04zoYdKVZMu6GZ+wUl2j5jbhkyktciBUxYoNCoYmyVa6TxCARzjeU m5zUHQrJAcLvwgZGks1XU/NQHHjrplmzjV5iftEwXY5viNm/ngUgA1p3O9WNNNXv8To1 hgjZ+Ypu8bDmc4JSuPsq11BACMKos7uIypD8NkcXkb2Ai29MRxzOldfqRs9Bi7U6ZnNr iCdj7K49ScN3SkIl9VmzNCUM6zczXGqVAc4ezyeUqCL5S0jHMaSL6/fXEg/ijyQw+TWc eIVpBm0sK08KmXkielXjeuspZ5Wj8NLGpiZRPHwVZ+/HoXy5g8Z+HmQI5x4VbE2aIUxI N06Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=3ErlKNWxBynVKO1TxiPrcdtE3Y8hGtnJhFEqGtEQkc8=; b=wZlxw1PF4vqFV73x8y6hOg9VJBY13+ZZcw4y+/sQLCS8+aGA1VDclh/0Br9Fh3BK3q wVEWEOpnROqb96S3S+04KDImnxjQINTS+ppn5JPhgMLO1VX2nsRuN9S8r4mNqyv3qRPX Oz4m5xhTRF5/kLIYydBRUTCizepWx+8NKJGVKWppMTfAP75vHmDokyz8LtcW6g2cjk/K xwdWE6rqpBIcrrfAHrW3UGaRh85OMfdWsrQZ/8WbRGmvZS97qvF1qTPVo8C+f5M7hI9V tjdZnnhDj5pfX8jB68kGBcxvrEJ/IKHAQCHIFhb+MUq0XdiYqb6AYGoCRHQESBIGsUxp 321A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=soIwOFlS; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w68-20020a626247000000b0063b87f60f7bsi34570655pfb.48.2023.05.03.22.29.06; Wed, 03 May 2023 22:29:29 -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=@gmail.com header.s=20221208 header.b=soIwOFlS; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229610AbjEDE7P (ORCPT <rfc822;lhua1029@gmail.com> + 99 others); Thu, 4 May 2023 00:59:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbjEDE7N (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 4 May 2023 00:59:13 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97EA31BCC; Wed, 3 May 2023 21:59:12 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4f11d267d8bso26487e87.2; Wed, 03 May 2023 21:59:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683176351; x=1685768351; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=3ErlKNWxBynVKO1TxiPrcdtE3Y8hGtnJhFEqGtEQkc8=; b=soIwOFlSuDbixg2p6QtdSv5cD/tBfMNtUK26BEhWsrzI1LyhraH1IP/7pkVKQNhxHs HUIJgYKti/U32k8lDHufVq5ADib5F02en5QQvxvNpYP8aJzrvoggy1I+YUu1tViv2LnK NL0KfxYalHS7fqsfbvsS8UK65BCMmtRkb8ufoAHy2r36w7gq82xc+mwsq8X6cS5Vi4MA VufyakMl7lhWek/zQLsSdAAE4a0H4/bPZ0rWmiVDp1KwCSWqLXvyb6EHoaRbZftbnYU6 PlYmFCq57kaeltIRilTngjqhGubBKB9ehrBtcUBxwuGep2/pRTyDH0kZEIlpJLclS8kv BIUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683176351; x=1685768351; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3ErlKNWxBynVKO1TxiPrcdtE3Y8hGtnJhFEqGtEQkc8=; b=OYRuxPuY5zaVy/7G/MO90gmWw0PNt5nHxOt0kzFlr2KuwqSzqZfzD9b8Zru79GZcVY bB+30zIYUfXQfAwE8GrY0+2dHnEiJ1TeDuw+Hyz9v9nkHcCrUAefnffgxT2+WTYO/TdE JxC43wP624nEa6yYxxag2P3SyRFb1c7N/PHQ9I0nrRLw+byyB69Seutm2K2Ejo3hhbAa npeIXa2ADY7EEYacqTdiJGGER/U3ZSLNqVTdCiz7WQ/uUGxueFTS0gJTGbGcGEg0Mc7L Wwrnb0r+ih3aZEBrqC4TzA21CE6l6pNFtpDBgdobpMY64lAB1f6QzIvhJh8tjI9R7qru T1Qg== X-Gm-Message-State: AC+VfDysYPJpRbbldxhpPg6GY2iHHmh0MG0CPOS8oTK8MlxhoeJftLh+ MfuBXV1K36HRQKzbQTXzZppCArkADP0= X-Received: by 2002:a2e:97c5:0:b0:2aa:43cd:57c9 with SMTP id m5-20020a2e97c5000000b002aa43cd57c9mr497393ljj.36.1683176350423; Wed, 03 May 2023 21:59:10 -0700 (PDT) Received: from fedora (62-78-225-252.bb.dnainternet.fi. [62.78.225.252]) by smtp.gmail.com with ESMTPSA id v1-20020a2e9901000000b002ab4ceea005sm3242194lji.136.2023.05.03.21.59.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 May 2023 21:59:09 -0700 (PDT) Date: Thu, 4 May 2023 07:59:00 +0300 From: Matti Vaittinen <mazziesaccount@gmail.com> To: Matti Vaittinen <mazziesaccount@gmail.com>, Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com> Cc: Matti Vaittinen <mazziesaccount@gmail.com>, Jonathan Cameron <jic23@kernel.org>, Lars-Peter Clausen <lars@metafoo.de>, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] iio: bu27034: Reinit regmap cache after reset Message-ID: <ZFM7lE4ZuDrUTspH@fedora> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="WjVFt0L+e0GrUcbG" Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764940231852817141?= X-GMAIL-MSGID: =?utf-8?q?1764940231852817141?= |
Series |
iio: bu27034: Reinit regmap cache after reset
|
|
Commit Message
Matti Vaittinen
May 4, 2023, 4:59 a.m. UTC
When BU27034 restores the default register values when SWRESET is
issued. This can cause register cache to be outdated.
Rebuild register cache after SWRESET.
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Fixes: e52afbd61039 ("iio: light: ROHM BU27034 Ambient Light Sensor")
---
I noticed this was missing while writing driver for another light
sensor. The change is not tested in hardware as I don't have the BU27034
at my hands right now. Careful review would be highly appreciated.
This change is built on top of the
https://lore.kernel.org/all/ZFIw%2FKdApZe1euN8@fedora/
and could probably be squashed with it. Unfortunately I spotted the
missing cache re-init only after sending the fix linked above.
Please, let me know if you want me to squash and respin.
---
drivers/iio/light/rohm-bu27034.c | 7 +++++++
1 file changed, 7 insertions(+)
Comments
On Thu, 4 May 2023 07:59:00 +0300 Matti Vaittinen <mazziesaccount@gmail.com> wrote: > When BU27034 restores the default register values when SWRESET is > issued. This can cause register cache to be outdated. > > Rebuild register cache after SWRESET. > > Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com> > Fixes: e52afbd61039 ("iio: light: ROHM BU27034 Ambient Light Sensor") > > --- > I noticed this was missing while writing driver for another light > sensor. The change is not tested in hardware as I don't have the BU27034 > at my hands right now. Careful review would be highly appreciated. > > This change is built on top of the > https://lore.kernel.org/all/ZFIw%2FKdApZe1euN8@fedora/ > and could probably be squashed with it. Unfortunately I spotted the > missing cache re-init only after sending the fix linked above. > I'm not sure I follow what would be happening here or if this makes sense. Partly the following is based on my mental image of how regmap caching works and could be completely wrong :) I don't think it goes off an reads registers until they are actually accessed the first time. In this case nothing has been accessed before this point other than the SYSTEM_CONTROL register and that happens to the one that is set to trigger the reset. So at worst I think the only cache element that will potentially be wrong is the SYSTEM_CONTROL register as the cache will contain the reset bits as set. That would be a problem if you read it again anywhere in the driver after that point, but you don't so not a 'bug' but perhaps prevention of potential future bugs as this behaviour is odd. If you were to try setting some other bits then you'd probably accidentally reset the device :) So, what's the ideal solution. You could just bypass the regcache initially and turn it on later. Thus it would never become wrong due to the reset (as nothing would be cached until after that). Or just leave it as you have it here, but explain why it matters - as prevention of potential issues due to wrong value in that single register. Jonathan > Please, let me know if you want me to squash and respin. > --- > drivers/iio/light/rohm-bu27034.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/drivers/iio/light/rohm-bu27034.c b/drivers/iio/light/rohm-bu27034.c > index 740ebd86b6e5..f85194fda6b0 100644 > --- a/drivers/iio/light/rohm-bu27034.c > +++ b/drivers/iio/light/rohm-bu27034.c > @@ -1281,6 +1281,13 @@ static int bu27034_chip_init(struct bu27034_data *data) > return dev_err_probe(data->dev, ret, "Sensor reset failed\n"); > > msleep(1); > + > + ret = regmap_reinit_cache(data->regmap, &bu27034_regmap); > + if (ret) { > + dev_err(data->dev, "Failed to reinit reg cache\n"); > + return ret; > + } > + > /* > * Read integration time here to ensure it is in regmap cache. We do > * this to speed-up the int-time acquisition in the start of the buffer
On 5/6/23 21:07, Jonathan Cameron wrote: > On Thu, 4 May 2023 07:59:00 +0300 > Matti Vaittinen <mazziesaccount@gmail.com> wrote: > >> When BU27034 restores the default register values when SWRESET is >> issued. This can cause register cache to be outdated. >> >> Rebuild register cache after SWRESET. >> >> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com> >> Fixes: e52afbd61039 ("iio: light: ROHM BU27034 Ambient Light Sensor") >> >> --- >> I noticed this was missing while writing driver for another light >> sensor. The change is not tested in hardware as I don't have the BU27034 >> at my hands right now. Careful review would be highly appreciated. >> >> This change is built on top of the >> https://lore.kernel.org/all/ZFIw%2FKdApZe1euN8@fedora/ >> and could probably be squashed with it. Unfortunately I spotted the >> missing cache re-init only after sending the fix linked above. >> > > I'm not sure I follow what would be happening here or if this makes sense. > > Partly the following is based on my mental image of how regmap caching works > and could be completely wrong :) > > I don't think it goes off an reads registers until they are actually accessed > the first time. I think this is not the absolute truth. AFAIR the regmap_init may lead to regcache_hw_init() - which can read the non volatile registers to the cache. I can't say if this is the case with current bu27034 regmap-config without taking a good look at this with some thought :) Nevertheless, we know that _if_ there is anything in cache when we do reset, the cache will most likely be invalid as HW will reset the registers. My thinking was that it is just safest to reinit the cache when this happens, then we do not need to care if regcache was populated when this is called. > In this case nothing has been accessed before this point > other than the SYSTEM_CONTROL register and that happens to the one that > is set to trigger the reset. > > So at worst I think the only cache element that will potentially be wrong > is the SYSTEM_CONTROL register as the cache will contain the reset bits as set. > > That would be a problem if you read it again anywhere in the driver after that > point, but you don't so not a 'bug' but perhaps prevention of potential future > bugs as this behaviour is odd. If you were to try setting some other bits > then you'd probably accidentally reset the device :) > > So, what's the ideal solution. You could just bypass the regcache initially > and turn it on later. I think I've never temporarily bypassed the cache when I've used one :) I need to check how this is done :) > Thus it would never become wrong due to the reset (as nothing > would be cached until after that). > > Or just leave it as you have it here, but explain why it matters - as prevention > of potential issues due to wrong value in that single register. Hm. I'd not limit the potential problems to single register as probe may get changed - or error handling could be added and reset performed after probe. (I was actually thinking of this as the spec states that if VCC drops the sensor may go to undefined state and won't recover unless VCC is turned off for > 1mS. Didn't add this for now as it is not at all obvious the regulator would support detecting under-voltage - or that the sensor could really turn-off the regulator as it might be also supplying something else - so I didn't want to implement some overkill error handling when we might not have hardware which actually benefits from this). Yours, -- Matti
On Sun, 7 May 2023 13:16:57 +0300 Matti Vaittinen <mazziesaccount@gmail.com> wrote: > On 5/6/23 21:07, Jonathan Cameron wrote: > > On Thu, 4 May 2023 07:59:00 +0300 > > Matti Vaittinen <mazziesaccount@gmail.com> wrote: > > > >> When BU27034 restores the default register values when SWRESET is > >> issued. This can cause register cache to be outdated. > >> > >> Rebuild register cache after SWRESET. > >> > >> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com> > >> Fixes: e52afbd61039 ("iio: light: ROHM BU27034 Ambient Light Sensor") > >> > >> --- > >> I noticed this was missing while writing driver for another light > >> sensor. The change is not tested in hardware as I don't have the BU27034 > >> at my hands right now. Careful review would be highly appreciated. > >> > >> This change is built on top of the > >> https://lore.kernel.org/all/ZFIw%2FKdApZe1euN8@fedora/ > >> and could probably be squashed with it. Unfortunately I spotted the > >> missing cache re-init only after sending the fix linked above. > >> > > > > I'm not sure I follow what would be happening here or if this makes sense. > > > > Partly the following is based on my mental image of how regmap caching works > > and could be completely wrong :) > > > > I don't think it goes off an reads registers until they are actually accessed > > the first time. > > I think this is not the absolute truth. AFAIR the regmap_init may lead > to regcache_hw_init() - which can read the non volatile registers to the > cache. I can't say if this is the case with current bu27034 > regmap-config without taking a good look at this with some thought :) I think that's only true if you provide various things you haven't in the regmap config. > > Nevertheless, we know that _if_ there is anything in cache when we do > reset, the cache will most likely be invalid as HW will reset the > registers. My thinking was that it is just safest to reinit the cache > when this happens, then we do not need to care if regcache was populated > when this is called. True, but that's rather heavy weight when we know we only touched one register. > > > In this case nothing has been accessed before this point > > other than the SYSTEM_CONTROL register and that happens to the one that > > is set to trigger the reset. > > > > So at worst I think the only cache element that will potentially be wrong > > is the SYSTEM_CONTROL register as the cache will contain the reset bits as set. > > > > That would be a problem if you read it again anywhere in the driver after that > > point, but you don't so not a 'bug' but perhaps prevention of potential future > > bugs as this behaviour is odd. If you were to try setting some other bits > > then you'd probably accidentally reset the device :) > > > > So, what's the ideal solution. You could just bypass the regcache initially > > and turn it on later. > > I think I've never temporarily bypassed the cache when I've used one :) > I need to check how this is done :) > regcache_cache_bypass(map, true / false); > > Thus it would never become wrong due to the reset (as nothing > > would be cached until after that). > > > > Or just leave it as you have it here, but explain why it matters - as prevention > > of potential issues due to wrong value in that single register. > > Hm. I'd not limit the potential problems to single register as probe may > get changed - or error handling could be added and reset performed after > probe. (I was actually thinking of this as the spec states that if VCC > drops the sensor may go to undefined state and won't recover unless VCC > is turned off for > 1mS. Didn't add this for now as it is not at all > obvious the regulator would support detecting under-voltage - or that > the sensor could really turn-off the regulator as it might be also > supplying something else - so I didn't want to implement some overkill > error handling when we might not have hardware which actually benefits > from this). OK. I'm fine with just reinitializing it and paying the penalty of that being overkill given current code. Combine this with the other patch into one clean fix / tidy up though. Jonathan > > Yours, > -- Matti >
On 5/7/23 16:36, Jonathan Cameron wrote: > On Sun, 7 May 2023 13:16:57 +0300 > Matti Vaittinen <mazziesaccount@gmail.com> wrote: > >> On 5/6/23 21:07, Jonathan Cameron wrote: >>> On Thu, 4 May 2023 07:59:00 +0300 >>> Matti Vaittinen <mazziesaccount@gmail.com> wrote: >> >> I think I've never temporarily bypassed the cache when I've used one :) >> I need to check how this is done :) >> > > regcache_cache_bypass(map, true / false); Thanks! This is a nice tool to have in my toolbox ;) > > Combine this with the other patch into one clean fix / tidy up though. Sure, thanks!
diff --git a/drivers/iio/light/rohm-bu27034.c b/drivers/iio/light/rohm-bu27034.c index 740ebd86b6e5..f85194fda6b0 100644 --- a/drivers/iio/light/rohm-bu27034.c +++ b/drivers/iio/light/rohm-bu27034.c @@ -1281,6 +1281,13 @@ static int bu27034_chip_init(struct bu27034_data *data) return dev_err_probe(data->dev, ret, "Sensor reset failed\n"); msleep(1); + + ret = regmap_reinit_cache(data->regmap, &bu27034_regmap); + if (ret) { + dev_err(data->dev, "Failed to reinit reg cache\n"); + return ret; + } + /* * Read integration time here to ensure it is in regmap cache. We do * this to speed-up the int-time acquisition in the start of the buffer