Message ID | ZFjWhbfuN5XcKty+@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 b10csp2098677vqo; Mon, 8 May 2023 05:03:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6GFTVKWytgktlzEKl5mp82er+lj5vg55fSSTzuo7whFjXUnzcBQN0lYx/VdA3D/pFKtxZg X-Received: by 2002:a17:90a:a595:b0:247:14ac:4d3a with SMTP id b21-20020a17090aa59500b0024714ac4d3amr11636001pjq.20.1683547396305; Mon, 08 May 2023 05:03:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683547396; cv=none; d=google.com; s=arc-20160816; b=NArjXs/7nZ/zcPSGcsWfZ6elLYLlznHE2qRcIhMPoXZ2lXVRROOqzXl9JrYFF46zeX PBVGam58lCD8kTNzQrY/I8uIL9KAA2Uyf/HaHS+0GIpBxwa99hXI9ZfB44zBkf+h0jO1 Dv0odql9UMWT27TQcpQHHc0jaXmSe7NXEo8NOlDe31i72x5w1ST9CiI04y6OBYyjtyYS awajc1GR/dC5L7mbAOo/dJ+GBVTht6U1g7CPAC7E835dB5fz5m+LonqaxV7DXs3MqkE5 NK+ZbacoXLmzncbuZN/GsoI2UQe/Wro5qyCcWd0HUqic9UiWgmJwsqG0RVr+Z+NNMrkj E0fA== 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=emaLfDqfNji1wHcGzgZ0JEzgTkXF4yqdECX8DFHrBeQ=; b=JCAjr7RV3ZtaSHBIjgY88HiHwM51Rkg3M0MyxkH4YmzY0M7nDHbYV8l5ChwR5gNr5u mXU1jBxtzkx8q+i1Hs/b9u2OTsSxdHizS3YOBZfIZRNBkLOCpNkEtraAsfjxEva/1Chh 0JKOlHicVYKT4w5Kzd71/rLXy4dM7rlsoSfUMIAkzGge2WT4wuJrCtJP3Y+R/AGZfji8 uJiQthEkv39/wZx25jKfVe4WAy5Hv/nBQ8bvcXRuSA45zN33rcEqYihFOBQ1nkcWUuBK uOFVUxau6nQ3MBOPYIgJ88jJnfeiFlVFHYs8Lr0Fw0Dg/M+gwhzAO+i3+1QDFd/a4xnn Vi3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=V0KakBYc; 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 b24-20020a170902d89800b001a644fba6d8si7685956plz.86.2023.05.08.05.03.02; Mon, 08 May 2023 05:03:16 -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=V0KakBYc; 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 S235486AbjEHLDO (ORCPT <rfc822;baris.duru.linux@gmail.com> + 99 others); Mon, 8 May 2023 07:03:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235537AbjEHLCm (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 8 May 2023 07:02:42 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 017E434881; Mon, 8 May 2023 04:01:41 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-4f24d4900bbso1310285e87.3; Mon, 08 May 2023 04:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683543700; x=1686135700; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=emaLfDqfNji1wHcGzgZ0JEzgTkXF4yqdECX8DFHrBeQ=; b=V0KakBYcXFaNHApKKoyS4LPMeoML66Ouc+LVpR69suB0GgqzrleJIrRFLRioegCtZX WASlzjlAMVi7a0HCxEMsWldkEgeGUA06puIsb/9SUo1poXMhPmE9Rupmy6RIYn9UZ3kr 2nXcDAg8GxUpcViYYEf90TT6zDjpXdUDs9Eqw2EcxPUBUgejOiFCfFUkj0pNNbxSA1/X eXaLBsynQeRqPl5lHtdytt7n45NbvUSycOuFu9mxsySWQb27Wx8T7GVqvye7zlAy3Dcy NCQvgshxXdsUlEjBoHU2eiNzmxnyDF+i5n+LReiqfWFKwMRgxwRaA23yoFYwpfxdYLEG QrZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683543700; x=1686135700; 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=emaLfDqfNji1wHcGzgZ0JEzgTkXF4yqdECX8DFHrBeQ=; b=MDgrCEMFqKN0KjEmq6wAOrOVW274hEWwWTxKhWZoso6n/AQaIxf5IAKTa8vNF9e0fV FlGIkBfelndozt/dx/9TP9aIiOl4aC3TC0qAgc8sOYPIMMnp4Euuyon42OH7i80dzz1c X0dWsfgB2oQzgOYEc0EfTsPtgkOUDFjJqH6InXWOkFjwirIJ/EBmBdMP/I3Rg7jz5xIb JW1QyXPY9XT00CnfPtDo4uzSh0oiMM2QMxLTtGmyF7zlXHjnAtEZmtUSdBxbI0Bbp3o7 7HLqT89FEsMn5lkkwqf6N4PDNFDO72vkhXn3yrk6PBCgjhi7KsR97gXhgmnKmRtQJQ0Q czkw== X-Gm-Message-State: AC+VfDwEZfnEwDl15IRfpZDxCwnWU0pEZl/yTMgtIbmhCz8/16sh/Jbv 1EvvYbwUamLRU7kaPchSKFA= X-Received: by 2002:a19:ae1a:0:b0:4f2:4d0a:7bdf with SMTP id f26-20020a19ae1a000000b004f24d0a7bdfmr908928lfc.52.1683543700112; Mon, 08 May 2023 04:01:40 -0700 (PDT) Received: from fedora (62-78-225-252.bb.dnainternet.fi. [62.78.225.252]) by smtp.gmail.com with ESMTPSA id j1-20020ac25501000000b004f001b0eda2sm1262729lfk.56.2023.05.08.04.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 May 2023 04:01:38 -0700 (PDT) Date: Mon, 8 May 2023 14:01:25 +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 v3] iio: bu27034: Ensure reset is written Message-ID: <ZFjWhbfuN5XcKty+@fedora> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="zUN/p8D1oB8SxR7S" 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?1765327394691146960?= X-GMAIL-MSGID: =?utf-8?q?1765327394691146960?= |
Series |
[v3] iio: bu27034: Ensure reset is written
|
|
Commit Message
Matti Vaittinen
May 8, 2023, 11:01 a.m. UTC
The reset bit must be always written to the hardware no matter what value
is in a cache or register. Ensure this by using regmap_write_bits()
instead of the regmap_update_bits(). Furthermore, the SWRESET bit may be
self-clearing, so mark the SYSTEM_CONTROL register volatile to guarantee
we do also read the right state - should we ever need to read it.
Finally, writing the SWRESET bit will restore the default register
values. This can cause register cache to be outdated if there are any
register values cached.
Rebuild register cache after SWRESET and use regmap_update_bits() when
performing the reset.
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Fixes: e52afbd61039 ("iio: light: ROHM BU27034 Ambient Light Sensor")
---
v3: Combined patches:
("iio: bu27034: Ensure reset is written")
https://lore.kernel.org/lkml/ZFIw%2FKdApZe1euN8@fedora/
("iio: bu27034: Reinit regmap cache after reset")
https://lore.kernel.org/lkml/ZFM7lE4ZuDrUTspH@fedora/
---
drivers/iio/light/rohm-bu27034.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
Comments
On Mon, 8 May 2023 14:01:25 +0300 Matti Vaittinen <mazziesaccount@gmail.com> wrote: > The reset bit must be always written to the hardware no matter what value > is in a cache or register. Ensure this by using regmap_write_bits() > instead of the regmap_update_bits(). Furthermore, the SWRESET bit may be > self-clearing, so mark the SYSTEM_CONTROL register volatile to guarantee > we do also read the right state - should we ever need to read it. > > Finally, writing the SWRESET bit will restore the default register > values. This can cause register cache to be outdated if there are any > register values cached. > > Rebuild register cache after SWRESET and use regmap_update_bits() when > performing the reset. > > Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com> > Fixes: e52afbd61039 ("iio: light: ROHM BU27034 Ambient Light Sensor") Still unclear to me if we should treat the register as volatile as hitting relevant bits causes a reset of the whole device anyway, but meh, it doesn't cause any problems and it's your driver. Applied to the fixes-togreg branch of iio.git Thanks, Jonathan > > --- > v3: Combined patches: > ("iio: bu27034: Ensure reset is written") > https://lore.kernel.org/lkml/ZFIw%2FKdApZe1euN8@fedora/ > ("iio: bu27034: Reinit regmap cache after reset") > https://lore.kernel.org/lkml/ZFM7lE4ZuDrUTspH@fedora/ > --- > drivers/iio/light/rohm-bu27034.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/drivers/iio/light/rohm-bu27034.c b/drivers/iio/light/rohm-bu27034.c > index 25c9b79574a5..f85194fda6b0 100644 > --- a/drivers/iio/light/rohm-bu27034.c > +++ b/drivers/iio/light/rohm-bu27034.c > @@ -231,6 +231,9 @@ struct bu27034_result { > > static const struct regmap_range bu27034_volatile_ranges[] = { > { > + .range_min = BU27034_REG_SYSTEM_CONTROL, > + .range_max = BU27034_REG_SYSTEM_CONTROL, > + }, { > .range_min = BU27034_REG_MODE_CONTROL4, > .range_max = BU27034_REG_MODE_CONTROL4, > }, { > @@ -1272,12 +1275,19 @@ static int bu27034_chip_init(struct bu27034_data *data) > int ret, sel; > > /* Reset */ > - ret = regmap_update_bits(data->regmap, BU27034_REG_SYSTEM_CONTROL, > + ret = regmap_write_bits(data->regmap, BU27034_REG_SYSTEM_CONTROL, > BU27034_MASK_SW_RESET, BU27034_MASK_SW_RESET); > if (ret) > 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
diff --git a/drivers/iio/light/rohm-bu27034.c b/drivers/iio/light/rohm-bu27034.c index 25c9b79574a5..f85194fda6b0 100644 --- a/drivers/iio/light/rohm-bu27034.c +++ b/drivers/iio/light/rohm-bu27034.c @@ -231,6 +231,9 @@ struct bu27034_result { static const struct regmap_range bu27034_volatile_ranges[] = { { + .range_min = BU27034_REG_SYSTEM_CONTROL, + .range_max = BU27034_REG_SYSTEM_CONTROL, + }, { .range_min = BU27034_REG_MODE_CONTROL4, .range_max = BU27034_REG_MODE_CONTROL4, }, { @@ -1272,12 +1275,19 @@ static int bu27034_chip_init(struct bu27034_data *data) int ret, sel; /* Reset */ - ret = regmap_update_bits(data->regmap, BU27034_REG_SYSTEM_CONTROL, + ret = regmap_write_bits(data->regmap, BU27034_REG_SYSTEM_CONTROL, BU27034_MASK_SW_RESET, BU27034_MASK_SW_RESET); if (ret) 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