Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp481106pxk; Wed, 9 Sep 2020 10:15:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRA+WnVdWREu9R2OE76G/7YqMylzRTeREYe3kBkDjQccYqjdkF5uePhD6tMe1bY4aP58bv X-Received: by 2002:a17:906:194b:: with SMTP id b11mr4566626eje.159.1599671709927; Wed, 09 Sep 2020 10:15:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599671709; cv=none; d=google.com; s=arc-20160816; b=av3HMq+ndvrc3EYn7R+em8wpBqa0NNUoemg18N3QJ19Q5QW8JIB2Rs1TRAqdwLcV/0 qV5dxF8Su59Q+JNDdVxyjDdrY8TMouy3X2yoKQN5VYOjkLtAhJWDUTxdsJqJw3Su992h H46yWRWetTTxJ08gX/dc0cHlrkiyIukJipt4nyu5pYCfWBwKAMdBmWoNGmPGzdmgUyLD 3tuv6gH++GE2NB9g2czMIAkrOYHNQoJTVRKmGh+jtGAuTOhStWof1p9H5bpiTxDaxEqd ypaQquLxdMwZLFWnL1myKUvZhkOsEqJd3gNVglLZ5/ebH/Oyxj95zZkF3NTzdWASqvoP CWbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lxomaUFyGRKilrUFZcIY7/bWZldlI+e6WC4qMP3FId4=; b=N0LWOuChqtO7Hexs1v7SS2m4NXfK6cqY1Ey9andpdXS41Bcp/QaywVMr3lOBGyGA7/ 3DyBE4XTp0Frt+eEHHM7iE9k5YUKdM5v7nZHGhtHJ1/wj3T604nLuFnmrsmlYjSgi4f4 ro9l0tgEjiBPqGvhR9ylDouhJM6sytouACyAShW7PDygXtjzxLgtbfFUN/M8GtOW2ByU M15EtiLKSmUEK7/OPiYW7pkeOjvGuem/OOwG26Gl2JgRP8hcTvL91iJy8rTvUCHxDtOs g0nNO34kKdAGK6pDchuPQlrqAzPcDq7QbSxKyPBTQ9s0xYBdj12VEAgwKvUjSohu5tZj JHvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HE090ecS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n4si1851193ejs.15.2020.09.09.10.14.46; Wed, 09 Sep 2020 10:15:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HE090ecS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730631AbgIIROQ (ORCPT + 99 others); Wed, 9 Sep 2020 13:14:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729161AbgIIPa1 (ORCPT ); Wed, 9 Sep 2020 11:30:27 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 765B4C0619C5 for ; Wed, 9 Sep 2020 08:17:57 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id b16so1497284pjp.0 for ; Wed, 09 Sep 2020 08:17:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=lxomaUFyGRKilrUFZcIY7/bWZldlI+e6WC4qMP3FId4=; b=HE090ecSFk0jzOjOcs6/fwBeViGwXTCfW0N5H7NrQqD2XUh03p5pyhh8OP85BT68cs FPUrRQlw3bOkeSbD8JAo7ZBL+pdRnv+qAQlhTliaouwO8x4zfMrsr4KSDBqUsbtCduyu PKrVmvqSeA1ygJQDKRU8Aqf/K/N51oePA2KAD2TzY6SqxPrzuvmvydydwLaCtIKBJRYl 9ocpspgIxNoU/O2wnvxmbWIZWglG1C2EWJXrmQseljkVb84nCbUdx6i9sprXsuXAbbwD pDtvc/QDeFwSkq7hMYgoVOUgD229P5+2xdR0SO+c6UyNNKhfaVifhRC0zmpUbEvLSrIO n/Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=lxomaUFyGRKilrUFZcIY7/bWZldlI+e6WC4qMP3FId4=; b=ckMQb0T1gpTUGgRx035+Rcp6Wq07ZGujGuQ4ziCEMfYBDTtnDaTCQX6kR8UeS9c0CY pSq7I+23MzPt4O8+OH3efwQD25xe3l1iZI/4It1gQePl1i7ear5mibvdFCyZr1a4QSNS zxwiOU3Obk4/7hYDizJJh0Q3uWYdGE7rL4hFbcJSOibYFB4Nttn2rJ1spM+tKLFyBosp XFKZPNgmWbZejJce852TX9lFVoM+UfPUqpd8ip4oLGNc2e0HTSKKqm0EoWbDjh+VZxAv ujlyxe/nNbM+LXYyEoQYBjKWsb1C8ldTroc3gPs/jZruILlOpyoFiKH1wHcOxS6DjP86 1j/g== X-Gm-Message-State: AOAM530f13cSp9xZcbn3uiAh+pWT4hvyMd5R8oYoPL+pZgxVaqVwhc1H 88U5Wu/IuLNwmUZu9MuXpJ3v X-Received: by 2002:a17:90b:1211:: with SMTP id gl17mr1256048pjb.87.1599664676371; Wed, 09 Sep 2020 08:17:56 -0700 (PDT) Received: from mani ([103.59.133.81]) by smtp.gmail.com with ESMTPSA id s20sm3144816pfu.112.2020.09.09.08.17.53 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 Sep 2020 08:17:55 -0700 (PDT) Date: Wed, 9 Sep 2020 20:47:48 +0530 From: Manivannan Sadhasivam To: Cristian Ciocaltea Cc: Andreas =?iso-8859-1?Q?F=E4rber?= , linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-actions@lists.infradead.org Subject: Re: [PATCH v2 1/1] i2c: busses: Add support for atomic transfers in Actions Semi Owl driver Message-ID: <20200909151748.GA11397@mani> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Cristi, On 0908, Cristian Ciocaltea wrote: > Atomic transfers are required to properly power off a machine through > an I2C controlled PMIC, such as the Actions Semi ATC260x series. > > System shutdown may happen with interrupts being disabled and, as a > consequence, the kernel may hang if the driver does not support atomic > transfers. > > This functionality is essentially implemented by polling the FIFO > Status register until either Command Execute Completed or NACK Error > bits are set. > Thanks for the patch! I just have couple of minor comments and other than that it looks good to me. > Signed-off-by: Cristian Ciocaltea > --- > Changes in v2: > - Dropped unused return codes from owl_i2c_xfer_data(), per Mani's review > - Rebased patch on v5.9-rc4 > > drivers/i2c/busses/i2c-owl.c | 78 ++++++++++++++++++++++++++---------- > 1 file changed, 57 insertions(+), 21 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-owl.c b/drivers/i2c/busses/i2c-owl.c > index 672f1f239bd6..29605257831f 100644 > --- a/drivers/i2c/busses/i2c-owl.c > +++ b/drivers/i2c/busses/i2c-owl.c > @@ -14,6 +14,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -76,6 +77,7 @@ > #define OWL_I2C_FIFOCTL_TFR BIT(2) > > /* I2Cc_FIFOSTAT Bit Mask */ > +#define OWL_I2C_FIFOSTAT_CECB BIT(0) > #define OWL_I2C_FIFOSTAT_RNB BIT(1) > #define OWL_I2C_FIFOSTAT_RFE BIT(2) > #define OWL_I2C_FIFOSTAT_TFF BIT(5) > @@ -83,7 +85,8 @@ > #define OWL_I2C_FIFOSTAT_RFD GENMASK(15, 8) > > /* I2C bus timeout */ > -#define OWL_I2C_TIMEOUT msecs_to_jiffies(4 * 1000) > +#define OWL_I2C_TIMEOUT_MS (4 * 1000) > +#define OWL_I2C_TIMEOUT msecs_to_jiffies(OWL_I2C_TIMEOUT_MS) > > #define OWL_I2C_MAX_RETRIES 50 > > @@ -161,29 +164,25 @@ static void owl_i2c_set_freq(struct owl_i2c_dev *i2c_dev) > writel(OWL_I2C_DIV_FACTOR(val), i2c_dev->base + OWL_I2C_REG_CLKDIV); > } > > -static irqreturn_t owl_i2c_interrupt(int irq, void *_dev) > +static void owl_i2c_xfer_data(struct owl_i2c_dev *i2c_dev) > { > - struct owl_i2c_dev *i2c_dev = _dev; > struct i2c_msg *msg = i2c_dev->msg; > - unsigned long flags; > unsigned int stat, fifostat; > > - spin_lock_irqsave(&i2c_dev->lock, flags); > - > i2c_dev->err = 0; > > /* Handle NACK from slave */ > fifostat = readl(i2c_dev->base + OWL_I2C_REG_FIFOSTAT); > if (fifostat & OWL_I2C_FIFOSTAT_RNB) { > i2c_dev->err = -ENXIO; > - goto stop; > + return; > } > > /* Handle bus error */ > stat = readl(i2c_dev->base + OWL_I2C_REG_STAT); > if (stat & OWL_I2C_STAT_BEB) { > i2c_dev->err = -EIO; > - goto stop; > + return; > } > > /* Handle FIFO read */ > @@ -196,18 +195,28 @@ static irqreturn_t owl_i2c_interrupt(int irq, void *_dev) > } else { > /* Handle the remaining bytes which were not sent */ > while (!(readl(i2c_dev->base + OWL_I2C_REG_FIFOSTAT) & > - OWL_I2C_FIFOSTAT_TFF) && i2c_dev->msg_ptr < msg->len) { > + OWL_I2C_FIFOSTAT_TFF) && i2c_dev->msg_ptr < msg->len) { Spurious change? > writel(msg->buf[i2c_dev->msg_ptr++], > i2c_dev->base + OWL_I2C_REG_TXDAT); > } > } > +} > + > +static irqreturn_t owl_i2c_interrupt(int irq, void *_dev) > +{ > + struct owl_i2c_dev *i2c_dev = _dev; > + unsigned long flags; > + > + spin_lock_irqsave(&i2c_dev->lock, flags); > + > + owl_i2c_xfer_data(i2c_dev); > > -stop: > /* Clear pending interrupts */ > owl_i2c_update_reg(i2c_dev->base + OWL_I2C_REG_STAT, > OWL_I2C_STAT_IRQP, true); > > complete_all(&i2c_dev->msg_complete); > + > spin_unlock_irqrestore(&i2c_dev->lock, flags); > > return IRQ_HANDLED; > @@ -235,8 +244,8 @@ static int owl_i2c_check_bus_busy(struct i2c_adapter *adap) > return 0; > } > > -static int owl_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, > - int num) > +static int owl_i2c_xfer_common(struct i2c_adapter *adap, struct i2c_msg *msgs, > + int num, bool atomic) > { > struct owl_i2c_dev *i2c_dev = i2c_get_adapdata(adap); > struct i2c_msg *msg; > @@ -280,11 +289,12 @@ static int owl_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, > goto err_exit; > } > > - reinit_completion(&i2c_dev->msg_complete); > + if (!atomic) > + reinit_completion(&i2c_dev->msg_complete); > > - /* Enable I2C controller interrupt */ > + /* Enable/disable I2C controller interrupt */ > owl_i2c_update_reg(i2c_dev->base + OWL_I2C_REG_CTL, > - OWL_I2C_CTL_IRQE, true); > + OWL_I2C_CTL_IRQE, !atomic); > > /* > * Select: FIFO enable, Master mode, Stop enable, Data count enable, > @@ -352,20 +362,33 @@ static int owl_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, > > spin_unlock_irqrestore(&i2c_dev->lock, flags); > > - time_left = wait_for_completion_timeout(&i2c_dev->msg_complete, > - adap->timeout); > + if (atomic) { > + /* Wait for Command Execute Completed or NACK Error bits */ > + ret = readl_poll_timeout_atomic(i2c_dev->base + OWL_I2C_REG_FIFOSTAT, > + val, val & (OWL_I2C_FIFOSTAT_CECB | > + OWL_I2C_FIFOSTAT_RNB), > + 10, OWL_I2C_TIMEOUT_MS * 1000); > + } else { > + time_left = wait_for_completion_timeout(&i2c_dev->msg_complete, > + adap->timeout); > + if (!time_left) > + ret = -ETIMEDOUT; > + } > > spin_lock_irqsave(&i2c_dev->lock, flags); > - if (time_left == 0) { > + > + if (ret) { > dev_err(&adap->dev, "Transaction timed out\n"); > /* Send stop condition and release the bus */ > owl_i2c_update_reg(i2c_dev->base + OWL_I2C_REG_CTL, > OWL_I2C_CTL_GBCC_STOP | OWL_I2C_CTL_RB, > true); > - ret = -ETIMEDOUT; > goto err_exit; > } > > + if (atomic) > + owl_i2c_xfer_data(i2c_dev); You are not clearing the pending interrupts here. Thanks, Mani > + > ret = i2c_dev->err < 0 ? i2c_dev->err : num; > > err_exit: > @@ -379,9 +402,22 @@ static int owl_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, > return ret; > } > > +static int owl_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, > + int num) > +{ > + return owl_i2c_xfer_common(adap, msgs, num, false); > +} > + > +static int owl_i2c_xfer_atomic(struct i2c_adapter *adap, > + struct i2c_msg *msgs, int num) > +{ > + return owl_i2c_xfer_common(adap, msgs, num, true); > +} > + > static const struct i2c_algorithm owl_i2c_algorithm = { > - .master_xfer = owl_i2c_master_xfer, > - .functionality = owl_i2c_func, > + .master_xfer = owl_i2c_xfer, > + .master_xfer_atomic = owl_i2c_xfer_atomic, > + .functionality = owl_i2c_func, > }; > > static const struct i2c_adapter_quirks owl_i2c_quirks = { > -- > 2.28.0 >