Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2373879pxb; Tue, 9 Mar 2021 00:22:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxUN/BOAVb+op+gBX8Amz9Ar59z2kWyoZ5bopWsmCdSrCDWtDQn643ulQx8Lq7W88oyO2c X-Received: by 2002:a05:6402:30a2:: with SMTP id df2mr2709786edb.29.1615278156665; Tue, 09 Mar 2021 00:22:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615278156; cv=none; d=google.com; s=arc-20160816; b=VzZA+W5DxovguJe2ew3OVLf1zEESUJ2/KnXhXCFtqXpCyAz3L6FKFWn/56APabXB/h Y6D7h3oT5DZUDZxZWxf/rst2nuqpFeBO4YQGzFK7upWaGCjsiV3dsCU0jvUz8BA/uBtW s9CRVKKw8X8AovsMM0WOt023LfCh0TxJIRbk9rAh/BZN5GJOSCusvuL0iEWTbl+yp+An Yz8R7x9haxhm4O7VcjlkqNGZbRlYLA6rSsQ7A9hsdSdE2kx77H9XSqjDzURGqAuiFOCD U4mi1O7rIMT0YBzp/VI5K35oLWfepiCSekgQh6KOz08Ei1qW4QvjoP6ZYRkJVY8sk48e rH5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=MSMjMCqP63jDMehRjkPECi23yTB9JQhxuj3AVIVNIhI=; b=LiiOpB+hj4yHyLwdZdHQkU76ZDoq4xBA83VByw0U3pBECOPImdnqEGN/9BvvzPMyhv lVc1AIYy1MdjczlCRyw0nx5+Kut49dsfSRhlxHFrangcS4XSHY/QkESQyBxehQ2Dvvsa KGaxrfJ4l0iz6qdTQHV0UqhtJfnC9O2g8FpHOrLQm4fTp1SK2CCcl+FFa5HhwI8rCZt4 2IEHaaPNe2YIHmB6VYPkJQhzJMf1e7iwUDGKYNyvD8CaV15yoG37LC4IfrkZUZM4SnoY IIi/OgElFxACLlAiwPuqwGb9PeY4iEWok74Zj9UwI8FdHV1FI3oFryghhcmrH1ri1NC5 zNjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Jpb6PBZZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x11si2945839ejv.267.2021.03.09.00.22.13; Tue, 09 Mar 2021 00:22:36 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=Jpb6PBZZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229972AbhCIIUV (ORCPT + 99 others); Tue, 9 Mar 2021 03:20:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbhCIIUI (ORCPT ); Tue, 9 Mar 2021 03:20:08 -0500 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F958C06174A; Tue, 9 Mar 2021 00:20:08 -0800 (PST) Received: by mail-il1-x12c.google.com with SMTP id p10so11401576ils.9; Tue, 09 Mar 2021 00:20:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MSMjMCqP63jDMehRjkPECi23yTB9JQhxuj3AVIVNIhI=; b=Jpb6PBZZPSNdGJ/67sPwdbiWJ+tyIU0KIqh01E0Hn+4QFSzd4XHV3zxmHb2ZFvcrfE qoxW3jsMvEIKfaTGClg3+opJ5SyC9VHykJiuKfKonG7Xhbb+E0c3X210+F3PRUXvV4d7 40duBJI0sR3pCCg9MWzWPbaVLqbqBx/DoZvR2cWfvA6iHQNM5RbRhhKBogUAH6gHebKA DhWFKefjGCyJuA5uW/LZ21tOJ9Uy34+LoXK928SI2J4TbnevxXl/TwQmmD8/Rvo2OvJV eOQGnvLkIc375vRgAUCj4BHk1NC24l2/QqkkCmk2mJ24dSkYof6z2pHTmJ1vBc8YxV04 VutA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MSMjMCqP63jDMehRjkPECi23yTB9JQhxuj3AVIVNIhI=; b=DlxYSO/hXPIEqDK0z2H0F+RskG37JQBXRO1VZvgFlKFiceCu8hGQcy0WUs9Okc9kDe m35tcGkm9jl2b9Pr6FxbYagCpoHen6yF0o8mNu0FKjmh1R1ioxPf97nqlPQN3JsZGZtk hg6/nv66uZd674eV1FLC4ocWZd+pC+EsHSyMbhtsznUV0y4TEzpAlAXseoI9IRorb/+Y v4fE9fh0dxf+spfzUjcScwP4BREa28sEnSQX/EW6NUXcDxcWjNQbHQT6vn6nFs7qSTcc ulkxwzbGFEnSHos/g9/wCu7T66SO//HuD8GAFVIaItuG6j/gFpHTu42r/06QSMka9gRR uJWQ== X-Gm-Message-State: AOAM530nFLGP4XvZuvD4b5nMUExmh5+INxWqViZT7oaby8OkUmFCBz6N BdfKe5pu1nI9PrEedgCYZig156rVWEFleliyUeM= X-Received: by 2002:a05:6e02:d4e:: with SMTP id h14mr23392685ilj.80.1615278007404; Tue, 09 Mar 2021 00:20:07 -0800 (PST) MIME-Version: 1.0 References: <20210208152758.13093-1-mark.jonas@de.bosch.com> <20210308144211.GK4931@dell> In-Reply-To: <20210308144211.GK4931@dell> From: Mark Jonas Date: Tue, 9 Mar 2021 09:19:56 +0100 Message-ID: Subject: Re: [PATCH v4] mfd: da9063: Support SMBus and I2C mode To: Lee Jones Cc: Mark Jonas , Support Opensource , linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, Adam.Thomson.Opensource@diasemi.com, stwiss.opensource@diasemi.com, marek.vasut@gmail.com, "RUAN Tingquan (BT-FIR/ENG1-Zhu)" , "Streidl Hubert (BT-FIR/ENG1-Grb)" , Wolfram Sang Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Lee, Thank you for having a look at the patch. > > From: Hubert Streidl > > > > By default the PMIC DA9063 2-wire interface is SMBus compliant. This > > means the PMIC will automatically reset the interface when the clock > > signal ceases for more than the SMBus timeout of 35 ms. > > > > If the I2C driver / device is not capable of creating atomic I2C > > transactions, a context change can cause a ceasing of the clock signal. > > This can happen if for example a real-time thread is scheduled. Then > > the DA9063 in SMBus mode will reset the 2-wire interface. Subsequently > > a write message could end up in the wrong register. This could cause > > unpredictable system behavior. > > > > The DA9063 PMIC also supports an I2C compliant mode for the 2-wire > > interface. This mode does not reset the interface when the clock > > signal ceases. Thus the problem depicted above does not occur. > > > > This patch tests for the bus functionality "I2C_FUNC_I2C". It can > > reasonably be assumed that the bus cannot obey SMBus timings if > > this functionality is set. SMBus commands most probably are emulated > > in this case which is prone to the latency issue described above. > > > > This patch enables the I2C bus mode if I2C_FUNC_I2C is set or > > otherwise enables the SMBus mode for a native SMBus controller > > which doesn't have I2C_FUNC_I2C set. > > > > Signed-off-by: Hubert Streidl > > Signed-off-by: Mark Jonas > > --- > > Changes in v4: > > - Remove logging of selected 2-wire bus mode. > > > > Changes in v3: > > - busmode now contains the correct bit DA9063_TWOWIRE_TO > > > > Changes in v2: > > - Implement proposal by Adam Thomson and Wolfram Sang to check for > > functionality I2C_FUNC_I2C instead of introducing a new DT property. > > > > drivers/mfd/da9063-i2c.c | 11 +++++++++++ > > include/linux/mfd/da9063/registers.h | 3 +++ > > 2 files changed, 14 insertions(+) > > > > diff --git a/drivers/mfd/da9063-i2c.c b/drivers/mfd/da9063-i2c.c > > index 3781d0bb7786..9450c95a3741 100644 > > --- a/drivers/mfd/da9063-i2c.c > > +++ b/drivers/mfd/da9063-i2c.c > > @@ -355,6 +355,7 @@ static int da9063_i2c_probe(struct i2c_client *i2c, > > const struct i2c_device_id *id) > > { > > struct da9063 *da9063; > > + unsigned int busmode; > > int ret; > > > > da9063 = devm_kzalloc(&i2c->dev, sizeof(struct da9063), GFP_KERNEL); > > @@ -442,6 +443,16 @@ static int da9063_i2c_probe(struct i2c_client *i2c, > > return ret; > > } > > > > + busmode = i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C) ? > > + 0 : DA9063_TWOWIRE_TO; > > Nit: I find ternaries like this tend to complicate matters and > harm readability rather than the converse. We can send an update of the patch if required. > > + ret = regmap_update_bits(da9063->regmap, DA9063_REG_CONFIG_J, > > + DA9063_TWOWIRE_TO, busmode); > > + if (ret < 0) { > > + dev_err(da9063->dev, "Failed to set 2-wire bus mode.\n"); > > + return -EIO; > > + } > > I'm a little confused by this. It's likely just me, but I would still > like some clarification. > > So you write to the TWOWIRE register despite whether I2C is operable > not, which I guess is fine. In our understanding at this point the I2C / SMBus is definitely operable. Otherwise the call to da9063_get_device_type() would have already failed because it reads the chip ID via I2C / SMBus. > But what if I2C is disabled and the update fails. You seem to complain > to the user that a failure occurred and return an error even if the > configuration is invalid in the first place. > > Would it not be better to encapsulate the update inside the > functionality check? Do you mean i2c_check_functionality() with "functionality check"? I understood that this function is part of the I2C / SMBus subsystem. It checks available features of the I2C / SMBus controller. As proposed during review of this patch we check for I2C_FUNC_I2C to determine whether the controller can do SMBus or if it is limited to I2C functionality. If the controller can only do I2C then the DA9063 shall not expect SMBus. By default the DA9063 assumes that it is connected to an SMBus. Thus, even with our patch there are potentially still two (get chip ID, set 2-wire mode) accesses to the DA9063 by an I2C controller but the DA9063 assumes SMBus. Yet, our patch closes the window of opportunity for something bad to happen from maybe one accesse per second to two accesses over the complete lifetime of the driver. I think this is already pretty good. If you have a concrete proposal we could try to improve further. But one write access for setting the twowire mode will always be there. And without the call to da9063_get_device_type() this would also have to be "hard-coded" without the use of the regmap. I consider our patch being already that much better than the current state that it is worth taking it mainline. Without the patch our system triggers the fault during normal operation. Even with heavy stress testing we have not been able to trigger the fault once our patch was applied. > > return da9063_device_init(da9063, i2c->irq); > > } > > > > diff --git a/include/linux/mfd/da9063/registers.h b/include/linux/mfd/da9063/registers.h > > index 1dbabf1b3cb8..6e0f66a2e727 100644 > > --- a/include/linux/mfd/da9063/registers.h > > +++ b/include/linux/mfd/da9063/registers.h > > @@ -1037,6 +1037,9 @@ > > #define DA9063_NONKEY_PIN_AUTODOWN 0x02 > > #define DA9063_NONKEY_PIN_AUTOFLPRT 0x03 > > > > +/* DA9063_REG_CONFIG_J (addr=0x10F) */ > > +#define DA9063_TWOWIRE_TO 0x40 > > + > > /* DA9063_REG_MON_REG_5 (addr=0x116) */ > > #define DA9063_MON_A8_IDX_MASK 0x07 > > #define DA9063_MON_A8_IDX_NONE 0x00 I am currently out of office. In case of change requirements we'll most likely send an updated patch mid of next week. Cheers, Mark