Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp508229ybl; Thu, 22 Aug 2019 00:05:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPzbYsbjD70GZP+8xnkNAW0UWkuZWy5oK8HrSvZwlSTzJoC1/GC/mszyJH0alMLqxgYAej X-Received: by 2002:a63:b20f:: with SMTP id x15mr33382580pge.453.1566457531374; Thu, 22 Aug 2019 00:05:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566457531; cv=none; d=google.com; s=arc-20160816; b=e4LIJk3iqWcc7rIEhb+4ms1z0SeyNKxH/Ml0UStLu76jk2mGkm9vQ66Y8nMS6C/m9I 9inRlAk7W33l/CJDfb4Ygn0pN21dpuZGTa3KFzL2cJXfNcKpG0k5mNgq5zWxgWUBykPf BFYVdKHFgqkAxiq2Vo03wXtFFcT+STOaNsnsKaemIciCz70lQDFi+JzbF6qUCBQsFrkQ wfLmSSnz2YjnwgiVi9cR9/0+2TchbOe4Dp4h0Vg+VgGNCXmLqNt8C1UxDgTUsGHVCs/x F9BEjbYK5b3Jiy66hs9SstlinFJRFb7MWVvr/b1LEPft585wG8ViW6WgOzpyPiBt1ERo YqtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Kn51c4iVY6vEKLBAUEgNeUWaRLfBi8NFzSwtDO3qJPo=; b=doKZ3AGCbMKyhaLa8DM0SWDv5SHIWeEtRy7vOzh4hGHs5ywP5cX/hepJpaTQAgFWFK zhRvkAa2qB7xln4Tf9ifZ10ZCWpuUPlYrDapMQ8gGUDH+JiaOrioFK0jBa5LodhNumA6 76IvJjzgKJhykvmnttFivvL4gdtsdhpjl0/OzmspPdtoNpOGTDHIArUnPkX9o1tUinwZ M8gjG9E8k+PRRXrcLSafQTRZ1KEmO1MfR+ejlCcCl7qnFNXfqScY534Q2tuvzfmZ8kMv whzfaIQuIP4vXyY8FFj2gOTXViQTNt9plEDrG9awNzVa0p1wwYzNfuFfrpQ81kO2w7hL /uGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=d+XGRDvs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y11si1658848pjp.54.2019.08.22.00.05.16; Thu, 22 Aug 2019 00:05:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=d+XGRDvs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731532AbfHVF6B (ORCPT + 99 others); Thu, 22 Aug 2019 01:58:01 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:46473 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731525AbfHVF6B (ORCPT ); Thu, 22 Aug 2019 01:58:01 -0400 Received: by mail-pf1-f195.google.com with SMTP id q139so3137852pfc.13 for ; Wed, 21 Aug 2019 22:58:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Kn51c4iVY6vEKLBAUEgNeUWaRLfBi8NFzSwtDO3qJPo=; b=d+XGRDvs6km5uuLibtMj+3KC3ZkxqZYWOsU2LWeCn9xko3LMBY/ZiIalGDExdpPNkv 2hL3j0jv/IRmHQ2CmCsOqXHykpFCzIX2ZmXO2/s20zJg9nYkd2fXr37b9m5qc4mNgd4k KQ6QB3GyCnueCJccC3fjLqL+gRTgY6o1l4ZZY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Kn51c4iVY6vEKLBAUEgNeUWaRLfBi8NFzSwtDO3qJPo=; b=QTKK/ZEnqXxlKoP+xVz4xcz6y211yxzmaHLnMXpZ7Ck+QYGe3Ddd78Z2SH+hF1L54e xITa0J4P/UtQChph0DMquEn4SB6uNOPhxpgXhcBuf66fSpz94BXNxgWafRsW++FOatS9 pWUiAeeApa+ck5a8WHOB1s2/W+9f3zsEqMDzIhb7/fTh7UTahEljZB1KLcN3AbXq1aUE Hu0Cstr/gsDlBfi0Fqhbg34Uw8XnSzRP7ppAxoLsO580M7n3B6UE5QCY7+Rh1hRXV8cB k3H40Tk0l1Pf1yBg8yQNpYudEwGlswD/mckkYNSfKGotuvoBR84X853o/6Til0xjUylt o5hA== X-Gm-Message-State: APjAAAUHelygPfQJnH9KBJdCMvgRNowEkY0Z19O+3v6KRxaJ99k1O3OF kvVVcaQWcCRwQxlg3mT5+IHi2w== X-Received: by 2002:a62:cec4:: with SMTP id y187mr39225066pfg.84.1566453480758; Wed, 21 Aug 2019 22:58:00 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:b852:bd51:9305:4261]) by smtp.gmail.com with ESMTPSA id e6sm24867338pfn.71.2019.08.21.22.57.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Aug 2019 22:58:00 -0700 (PDT) From: Hsin-Yi Wang To: Wolfram Sang Cc: Matthias Brugger , Qii Wang , Nicolas Boichat , Jun Gao , Thomas Gleixner , linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Alexandru M Stan Subject: [PATCH RESEND] i2c: mediatek: disable zero-length transfers for mt8183 Date: Thu, 22 Aug 2019 13:57:37 +0800 Message-Id: <20190822055737.142384-1-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When doing i2cdetect quick write mode, we would get transfer error ENOMEM, and i2cdetect shows there's no device at the address. Quoting from mt8183 datasheet, the number of transfers to be transferred in one transaction should be set to bigger than 1, so we should forbid zero-length transfer and update functionality. Incorrect return: localhost ~ # i2cdetect -q -y 0 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- After this patch: localhost ~ # i2cdetect -q -y 0 Error: Can't use SMBus Quick Write command on this bus localhost ~ # i2cdetect -y 0 Warning: Can't use SMBus Quick Write command, will skip some addresses 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: 10: 20: 30: -- -- -- -- -- -- -- -- 40: 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: 70: Reported-by: Alexandru M Stan Signed-off-by: Hsin-Yi Wang --- Previous patch and discussion: http://patchwork.ozlabs.org/patch/1042684/ --- drivers/i2c/busses/i2c-mt65xx.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c index 252edb433fdf..2842ca4b8c3b 100644 --- a/drivers/i2c/busses/i2c-mt65xx.c +++ b/drivers/i2c/busses/i2c-mt65xx.c @@ -234,6 +234,10 @@ static const struct i2c_adapter_quirks mt7622_i2c_quirks = { .max_num_msgs = 255, }; +static const struct i2c_adapter_quirks mt8183_i2c_quirks = { + .flags = I2C_AQ_NO_ZERO_LEN, +}; + static const struct mtk_i2c_compatible mt2712_compat = { .regs = mt_i2c_regs_v1, .pmic_i2c = 0, @@ -298,6 +302,7 @@ static const struct mtk_i2c_compatible mt8173_compat = { }; static const struct mtk_i2c_compatible mt8183_compat = { + .quirks = &mt8183_i2c_quirks, .regs = mt_i2c_regs_v2, .pmic_i2c = 0, .dcm = 0, @@ -870,7 +875,11 @@ static irqreturn_t mtk_i2c_irq(int irqno, void *dev_id) static u32 mtk_i2c_functionality(struct i2c_adapter *adap) { - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; + if (adap->quirks->flags & I2C_AQ_NO_ZERO_LEN) + return I2C_FUNC_I2C | + (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK); + else + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; } static const struct i2c_algorithm mtk_i2c_algorithm = { @@ -933,8 +942,8 @@ static int mtk_i2c_probe(struct platform_device *pdev) i2c->dev = &pdev->dev; i2c->adap.dev.parent = &pdev->dev; i2c->adap.owner = THIS_MODULE; - i2c->adap.algo = &mtk_i2c_algorithm; i2c->adap.quirks = i2c->dev_comp->quirks; + i2c->adap.algo = &mtk_i2c_algorithm; i2c->adap.timeout = 2 * HZ; i2c->adap.retries = 1; -- 2.20.1