From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753449AbdCHODR (ORCPT ); Wed, 8 Mar 2017 09:03:17 -0500 Received: from foss.arm.com ([217.140.101.70]:59698 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753138AbdCHODP (ORCPT ); Wed, 8 Mar 2017 09:03:15 -0500 Subject: Re: [PATCH 2/2] reset: simple: read back to make sure changes are applied To: Philipp Zabel , linux-kernel@vger.kernel.org References: <20170308095423.3948-1-p.zabel@pengutronix.de> <20170308095423.3948-2-p.zabel@pengutronix.de> Cc: Maxime Coquelin , Alexandre Torgue , Maxime Ripard , Chen-Yu Tsai From: Andre Przywara Message-ID: Date: Wed, 8 Mar 2017 14:04:27 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <20170308095423.3948-2-p.zabel@pengutronix.de> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 08/03/17 09:54, Philipp Zabel wrote: > Read back the register after setting or clearing a reset bit to make > sure that the changes are applied to the reset controller hardware. > Theoretically, this avoids the write to stay stuck in a store buffer > during the delay of an assert-delay-deassert sequence, and makes sure > that the reset really is asserted for the specified duration. > > Signed-off-by: Philipp Zabel > --- > drivers/reset/reset-simple.c | 14 ++++++++++---- > 1 file changed, 10 insertions(+), 4 deletions(-) > > diff --git a/drivers/reset/reset-simple.c b/drivers/reset/reset-simple.c > index 2160e84fe216b..e32289bdaf0c6 100644 > --- a/drivers/reset/reset-simple.c > +++ b/drivers/reset/reset-simple.c > @@ -33,13 +33,16 @@ static int reset_simple_clear(struct reset_controller_dev *rcdev, > int reg_width = sizeof(u32); > int bank = id / (reg_width * BITS_PER_BYTE); > int offset = id % (reg_width * BITS_PER_BYTE); > + void __iomem *addr = data->membase + (bank * reg_width); > unsigned long flags; > u32 reg; > > spin_lock_irqsave(&data->lock, flags); > > - reg = readl(data->membase + (bank * reg_width)); > - writel(reg & ~BIT(offset), data->membase + (bank * reg_width)); > + reg = readl(addr); > + writel(reg & ~BIT(offset), addr); > + /* Read back to make sure the write doesn't linger in a store buffer */ > + readl(addr); Nit: "Read back to make sure the write doesn't linger in a store buffer", sounds somewhat dodgy. What about: "Read back to make sure the write has reached the device."? And I wonder if we actually need to check the returned value to make sure the device has actually changed the state? Or is this too paranoid? Cheers, Andre. > spin_unlock_irqrestore(&data->lock, flags); > > @@ -53,13 +56,16 @@ static int reset_simple_set(struct reset_controller_dev *rcdev, > int reg_width = sizeof(u32); > int bank = id / (reg_width * BITS_PER_BYTE); > int offset = id % (reg_width * BITS_PER_BYTE); > + void __iomem *addr = data->membase + (bank * reg_width); > unsigned long flags; > u32 reg; > > spin_lock_irqsave(&data->lock, flags); > > - reg = readl(data->membase + (bank * reg_width)); > - writel(reg | BIT(offset), data->membase + (bank * reg_width)); > + reg = readl(addr); > + writel(reg | BIT(offset), addr); > + /* Read back to make sure the write doesn't linger in a store buffer */ > + readl(addr); > > spin_unlock_irqrestore(&data->lock, flags); > >